Fix for magnet sensor open state - when opened long time

This commit is contained in:
2017-03-06 20:55:30 +03:00
parent 54eda12502
commit 86d6db496a
3 changed files with 9 additions and 3 deletions
+4 -2
View File
@@ -9,7 +9,7 @@ import mqtt
import yamlparser import yamlparser
from xiaomihub import XiaomiHub from xiaomihub import XiaomiHub
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
def process_gateway_messages(gateway, client): def process_gateway_messages(gateway, client):
@@ -42,8 +42,10 @@ def read_motion_data(gateway, client, polling_interval, polling_models):
sid = device['sid'] sid = device['sid']
sensor_resp = gateway.get_from_hub(sid) sensor_resp = gateway.get_from_hub(sid)
if (sensor_resp == None):
continue;
if (sensor_resp['sid'] != sid): if (sensor_resp['sid'] != sid):
print("Error: Response sid(" + sensor_resp['sid'] + ") differs from requested(" + sid + "). Skipping.") _LOGGER.error("Error: Response sid(" + sensor_resp['sid'] + ") differs from requested(" + sid + "). Skipping.")
continue; continue;
data = json.loads(sensor_resp['data']) data = json.loads(sensor_resp['data'])
+4
View File
@@ -72,6 +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"
if (model == "magnet" and key == "no_close"):
key="status"
value="open"
# do not retain event-based sensors (like switches and cubes). # do not retain event-based sensors (like switches and cubes).
if (model in ["switch", "cube"]): if (model in ["switch", "cube"]):
retain = False retain = False
+1 -1
View File
@@ -121,7 +121,7 @@ class XiaomiHub:
for sock in read_sockets: for sock in read_sockets:
if sock == socket: if sock == socket:
data = sock.recv(4096) data = sock.recv(4096)
print("Not recieved data: " + str(data)) _LOGGER.error("Unwanted data recieved: " + str(data))
except Exception as e: except Exception as e:
_LOGGER.error("Cannot read unwanted data: " + str(e)) _LOGGER.error("Cannot read unwanted data: " + str(e))