diff --git a/src/main.py b/src/main.py index a63abaa..91fb2a4 100644 --- a/src/main.py +++ b/src/main.py @@ -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']) diff --git a/src/mqtt.py b/src/mqtt.py index 8d8afe2..c88a0b1 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -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 diff --git a/src/xiaomihub.py b/src/xiaomihub.py index f0a4f71..5d43c8c 100644 --- a/src/xiaomihub.py +++ b/src/xiaomihub.py @@ -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))