From ab648665b1b6d977038f1d57fd0b8b0a8796b5ab Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 14 Aug 2021 17:37:09 +0200 Subject: ensure http request delivery --- light.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/light.py b/light.py index 67e2db2..6602ee3 100644 --- a/light.py +++ b/light.py @@ -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() -- cgit v1.2.3