Fixed bug with unknown switches, that was sent to gateway and makes an error

This commit is contained in:
2017-04-01 23:12:16 +03:00
parent 74adba1a68
commit 96777ae1cc
2 changed files with 7 additions and 1 deletions
+5
View File
@@ -105,6 +105,7 @@ class Mqtt:
name = "" # we will find it next name = "" # we will find it next
sid = query_sid sid = query_sid
isFound = False
for current_sid in self._sids: for current_sid in self._sids:
if (current_sid == None): if (current_sid == None):
continue continue
@@ -116,11 +117,15 @@ class Mqtt:
if (sidname == query_sid and sidmodel == model): if (sidname == query_sid and sidmodel == model):
sid = current_sid sid = current_sid
name = sidname name = sidname
isFound = True
break break
else: else:
_LOGGER.debug(sidmodel + "-" + sidname + " is not " + model + "-" + query_sid + ".") _LOGGER.debug(sidmodel + "-" + sidname + " is not " + model + "-" + query_sid + ".")
continue continue
if isFound == False:
return
# fix for rgb format # fix for rgb format
if (param == "rgb" and "," in str(value)): if (param == "rgb" and "," in str(value)):
value = self._color_rgb_to_xiaomi(value) value = self._color_rgb_to_xiaomi(value)
+2 -1
View File
@@ -128,7 +128,7 @@ class XiaomiHub:
def _send_socket(self, cmd, rtnCmd, ip, port): def _send_socket(self, cmd, rtnCmd, ip, port):
socket = self._socket socket = self._socket
try: try:
_LOGGER.info('Sending to GW {0}'.format(cmd)) _LOGGER.debug('Sending to GW {0}'.format(cmd))
self._read_unwanted_data() self._read_unwanted_data()
socket.settimeout(30.0) socket.settimeout(30.0)
@@ -137,6 +137,7 @@ class XiaomiHub:
data, addr = socket.recvfrom(1024) data, addr = socket.recvfrom(1024)
if len(data) is not None: if len(data) is not None:
resp = json.loads(data.decode()) resp = json.loads(data.decode())
_LOGGER.debug('Recieved from GW {0}'.format(resp))
if resp["cmd"] == rtnCmd: if resp["cmd"] == rtnCmd:
return resp return resp
else: else: