Fix: working properly without sids in config
This commit is contained in:
+29
-27
@@ -25,7 +25,7 @@ class Mqtt:
|
|||||||
#load sids dictionary
|
#load sids dictionary
|
||||||
self._sids = config.get("sids", None)
|
self._sids = config.get("sids", None)
|
||||||
if (self._sids == None):
|
if (self._sids == None):
|
||||||
raise "Config sids section is null"
|
self._sids = dict({})
|
||||||
|
|
||||||
#load mqtt settings
|
#load mqtt settings
|
||||||
mqttConfig = config.get("mqtt", None)
|
mqttConfig = config.get("mqtt", None)
|
||||||
@@ -94,39 +94,41 @@ class Mqtt:
|
|||||||
if (len(parts) != 5):
|
if (len(parts) != 5):
|
||||||
return
|
return
|
||||||
model = parts[1]
|
model = parts[1]
|
||||||
name = parts[2] #name part
|
query_sid = parts[2] #sid or name part
|
||||||
found = False
|
param = parts[3] #param part
|
||||||
for sid in self._sids:
|
value = (msg.payload).decode('utf-8')
|
||||||
if (sid == None):
|
if self._is_int(value):
|
||||||
|
value = int(value)
|
||||||
|
name = "" # we will find it next
|
||||||
|
sid = query_sid
|
||||||
|
|
||||||
|
for current_sid in self._sids:
|
||||||
|
if (current_sid == None):
|
||||||
continue
|
continue
|
||||||
sidprops = self._sids.get(sid, None)
|
sidprops = self._sids.get(current_sid, None)
|
||||||
if sidprops == None:
|
if sidprops == None:
|
||||||
continue
|
continue
|
||||||
sidname = sidprops.get("name", sid)
|
sidname = sidprops.get("name", current_sid)
|
||||||
sidmodel = sidprops.get("model", "")
|
sidmodel = sidprops.get("model", "")
|
||||||
if sidname != name or sidmodel != model:
|
if (sidname == query_sid and sidmodel == model):
|
||||||
_LOGGER.debug(sidmodel + "-" + sidname + " is not " + model + "-" + name + ".")
|
sid = current_sid
|
||||||
|
name = sidname
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
_LOGGER.debug(sidmodel + "-" + sidname + " is not " + model + "-" + query_sid + ".")
|
||||||
continue
|
continue
|
||||||
param = parts[3] #param part
|
|
||||||
value = (msg.payload).decode('utf-8')
|
|
||||||
if self._is_int(value):
|
|
||||||
value = int(value)
|
|
||||||
|
|
||||||
# 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(",")
|
arr = value.split(",")
|
||||||
r = int(arr[0])
|
r = int(arr[0])
|
||||||
g = int(arr[1])
|
g = int(arr[1])
|
||||||
b = int(arr[2])
|
b = int(arr[2])
|
||||||
value = int('%02x%02x%02x%02x' % (255, r, g, b), 16)
|
value = int('%02x%02x%02x%02x' % (255, 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
|
||||||
self._queue.put(data)
|
self._queue.put(data)
|
||||||
found = True
|
|
||||||
break
|
|
||||||
if (found == False):
|
|
||||||
_LOGGER.error("Device " + model + "/" + name + " not found =(.")
|
|
||||||
|
|
||||||
def _mqtt_loop(self):
|
def _mqtt_loop(self):
|
||||||
_LOGGER.info("Starting mqtt loop.")
|
_LOGGER.info("Starting mqtt loop.")
|
||||||
|
|||||||
Reference in New Issue
Block a user