Exported temporary rgb fix to functions(refactor), uncommented rgb-format report-back and add brightness in reports.
This commit is contained in:
+28
-19
@@ -12,7 +12,7 @@ class Mqtt:
|
|||||||
server = "localhost"
|
server = "localhost"
|
||||||
port = 1883
|
port = 1883
|
||||||
prefix = "home"
|
prefix = "home"
|
||||||
|
|
||||||
_client = None
|
_client = None
|
||||||
_sids = None
|
_sids = None
|
||||||
_queue = None
|
_queue = None
|
||||||
@@ -48,8 +48,8 @@ class Mqtt:
|
|||||||
self._client.on_message = self._mqtt_process_message
|
self._client.on_message = self._mqtt_process_message
|
||||||
self._client.on_connect = self._mqtt_on_connect
|
self._client.on_connect = self._mqtt_on_connect
|
||||||
self._client.connect(self.server, self.port, 60)
|
self._client.connect(self.server, self.port, 60)
|
||||||
|
|
||||||
#run message processing loop
|
#run message processing loop
|
||||||
t1 = Thread(target=self._mqtt_loop)
|
t1 = Thread(target=self._mqtt_loop)
|
||||||
t1.start()
|
t1.start()
|
||||||
self._threads.append(t1)
|
self._threads.append(t1)
|
||||||
@@ -72,14 +72,10 @@ class Mqtt:
|
|||||||
if (model == "motion" and key == "no_motion"):
|
if (model == "motion" and key == "no_motion"):
|
||||||
key="status"
|
key="status"
|
||||||
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