Fix for magnet sensor open state - when opened long time
This commit is contained in:
+4
-2
@@ -9,7 +9,7 @@ import mqtt
|
||||
import yamlparser
|
||||
from xiaomihub import XiaomiHub
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def process_gateway_messages(gateway, client):
|
||||
@@ -42,8 +42,10 @@ def read_motion_data(gateway, client, polling_interval, polling_models):
|
||||
sid = device['sid']
|
||||
|
||||
sensor_resp = gateway.get_from_hub(sid)
|
||||
if (sensor_resp == None):
|
||||
continue;
|
||||
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;
|
||||
|
||||
data = json.loads(sensor_resp['data'])
|
||||
|
||||
@@ -72,6 +72,10 @@ class Mqtt:
|
||||
if (model == "motion" and key == "no_motion"):
|
||||
key="status"
|
||||
value="no_motion"
|
||||
if (model == "magnet" and key == "no_close"):
|
||||
key="status"
|
||||
value="open"
|
||||
|
||||
# do not retain event-based sensors (like switches and cubes).
|
||||
if (model in ["switch", "cube"]):
|
||||
retain = False
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ class XiaomiHub:
|
||||
for sock in read_sockets:
|
||||
if sock == socket:
|
||||
data = sock.recv(4096)
|
||||
print("Not recieved data: " + str(data))
|
||||
_LOGGER.error("Unwanted data recieved: " + str(data))
|
||||
except Exception as e:
|
||||
_LOGGER.error("Cannot read unwanted data: " + str(e))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user