Exported temporary rgb fix to functions(refactor), uncommented rgb-format report-back and add brightness in reports.
This commit is contained in:
+24
-15
@@ -74,12 +74,8 @@ class Mqtt:
|
|||||||
value="no_motion"
|
value="no_motion"
|
||||||
|
|
||||||
# fix for rgb format
|
# fix for rgb format
|
||||||
# if (key == "rgb" and self._is_int(value)):
|
if (key == "rgb" and self._is_int(value)):
|
||||||
# intval = int(value)
|
value = self._color_xiaomi_to_rgb(value)
|
||||||
# blue = (intval) & 255
|
|
||||||
# green = (intval >> 8) & 255
|
|
||||||
# red = (intval >> 16) & 255
|
|
||||||
# value = str(red)+","+str(green)+","+str(blue)
|
|
||||||
|
|
||||||
topic = PATH_FMT.format(model=model, sid=sid, prop=key)
|
topic = PATH_FMT.format(model=model, sid=sid, prop=key)
|
||||||
_LOGGER.info("Publishing message to topic " + topic + ": " + str(value) + ".")
|
_LOGGER.info("Publishing message to topic " + topic + ": " + str(value) + ".")
|
||||||
@@ -120,15 +116,7 @@ class Mqtt:
|
|||||||
|
|
||||||
# fix for rgb format
|
# fix for rgb format
|
||||||
if (param == "rgb" and "," in str(value)):
|
if (param == "rgb" and "," in str(value)):
|
||||||
arr = value.split(",")
|
value = self._color_rgb_to_xiaomi(value)
|
||||||
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)
|
|
||||||
|
|
||||||
data = {'sid': sid, 'model': model, 'name': name, 'param':param, 'value':value}
|
data = {'sid': sid, 'model': model, 'name': name, 'param':param, 'value':value}
|
||||||
# put in process queuee
|
# put in process queuee
|
||||||
@@ -138,6 +126,27 @@ class Mqtt:
|
|||||||
_LOGGER.info("Starting mqtt loop.")
|
_LOGGER.info("Starting mqtt loop.")
|
||||||
self._client.loop_forever()
|
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):
|
def _is_int(self, x):
|
||||||
try:
|
try:
|
||||||
tmp = int(x)
|
tmp = int(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user