diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-08-14 17:37:09 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-08-14 17:37:09 +0200 |
commit | ab648665b1b6d977038f1d57fd0b8b0a8796b5ab (patch) | |
tree | 58dc06e245e81e13595b44a1e03b60ddb3e40bd4 | |
parent | eb9a5323f8ce22b2a6580ccf8147465af31e9a89 (diff) |
ensure http request delivery
-rw-r--r-- | light.py | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -1,6 +1,7 @@ import homeassistant.helpers.config_validation as cv import voluptuous as vol import requests +import threading from math import floor from homeassistant.const import CONF_MAC from homeassistant.components.light import ( @@ -85,5 +86,15 @@ class ESPLedStripLight(LightEntity): r = int( int(self._on) * self._rgb[0] * ( self._brightness / 255 ) ) g = int( int(self._on) * self._rgb[1] * ( self._brightness / 255 ) ) b = int( int(self._on) * self._rgb[2] * ( self._brightness / 255 ) ) - requests.post("http://" + self._host, f"{r:02x}{g:02x}{b:02x}") + + def req(): + success = False + while not success: + try: + requests.post("http://" + self._host, f"{r:02x}{g:02x}{b:02x}") + success = True + except: + continue + + threading.Thread(target=req).start() |