Exported temporary rgb fix to functions(refactor), uncommented rgb-format report-back and add brightness in reports.

This commit is contained in:
2017-01-14 23:41:41 +03:00
parent c521fbf59c
commit 78dd74edd0
+24 -15
View File
@@ -74,12 +74,8 @@ class Mqtt:
value="no_motion"
# fix for rgb format
# if (key == "rgb" and self._is_int(value)):
# intval = int(value)
# blue = (intval) & 255
# green = (intval >> 8) & 255
# red = (intval >> 16) & 255
# value = str(red)+","+str(green)+","+str(blue)
if (key == "rgb" and self._is_int(value)):
value = self._color_xiaomi_to_rgb(value)
topic = PATH_FMT.format(model=model, sid=sid, prop=key)
_LOGGER.info("Publishing message to topic " + topic + ": " + str(value) + ".")
@@ -120,15 +116,7 @@ class Mqtt:
# fix for rgb format
if (param == "rgb" and "," in str(value)):
arr = value.split(",")
r = int(arr[0])
g = int(arr[1])
b = int(arr[2])
if len(arr)>3:
bright = int(arr[3])
else:
bright = 255
value = int('%02x%02x%02x%02x' % (bright, r, g, b), 16)
value = self._color_rgb_to_xiaomi(value)
data = {'sid': sid, 'model': model, 'name': name, 'param':param, 'value':value}
# put in process queuee
@@ -138,6 +126,27 @@ class Mqtt:
_LOGGER.info("Starting mqtt loop.")
self._client.loop_forever()
def _color_xiaomi_to_rgb(self, xiaomi_color):
intval = int(xiaomi_color)
blue = (intval) & 255
green = (intval >> 8) & 255
red = (intval >> 16) & 255
bright = (intval >> 24) & 255
value = str(red)+","+str(green)+","+str(blue)+","+str(bright)
return value
def _color_rgb_to_xiaomi(self, rgb_string):
arr = rgb_string.split(",")
r = int(arr[0])
g = int(arr[1])
b = int(arr[2])
if len(arr)>3:
bright = int(arr[3])
else:
bright = 255
value = int('%02x%02x%02x%02x' % (bright, r, g, b), 16)
return value
def _is_int(self, x):
try:
tmp = int(x)