From ed116b431b7ac66940db7ac3d646b1f4ecaa85b5 Mon Sep 17 00:00:00 2001 From: raspberry Date: Wed, 21 Feb 2018 19:55:47 +0300 Subject: [PATCH] SORRY! Fix for broken motion/door state! --- .semver | 2 +- Makefile | 11 +++++++++++ docker-compose.yaml | 4 +++- src/mqtt.py | 12 +++++++----- 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/.semver b/.semver index 6d7de6e..21e8796 100644 --- a/.semver +++ b/.semver @@ -1 +1 @@ -1.0.2 +1.0.3 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..74d4e82 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +#SHELL := /bin/bash + +ARGS = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}` + +commit: + git add . + git commit -m "$(call ARGS,\"updating to lastest local code\")" + git push + +%: + @: diff --git a/docker-compose.yaml b/docker-compose.yaml index be7edd1..f03cbde 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,5 +1,7 @@ aqara: - image: monster1025/aqara-mqtt:1-armhf + #image: monster1025/aqara-mqtt:1-armhf + build: . + dockerfile: Dockerfile-armhf container_name: aqara volumes: - "./config:/app/config" diff --git a/src/mqtt.py b/src/mqtt.py index 5684de5..7f4d864 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -74,6 +74,7 @@ class Mqtt: model = sidprops.get("model",model) sid = sidprops.get("name",sid) + items = {} for key, value in data.items(): # fix for latest motion value if (model == "motion" and key == "no_motion"): @@ -88,23 +89,24 @@ class Mqtt: # fix for rgb format if (key == "rgb" and self._is_int(value)): value = self._color_xiaomi_to_rgb(value) + items[key] = value if self.json == True: PATH_FMT = self.prefix + "/{model}/{sid}/json" topic = PATH_FMT.format(model=model, sid=sid) values = {} values['sid'] = sid - for key, value in data.items(): - values[key] = value + for key in items: + values[key] = items[key] jsondata = json.dumps(values) _LOGGER.info("Publishing message to topic " + topic + ": " + str(jsondata) + ".") self._client.publish(topic, payload=jsondata, qos=0, retain=retain) else: - for key, value in data.items(): + for key in items: PATH_FMT = self.prefix + "/{model}/{sid}/{prop}" topic = PATH_FMT.format(model=model, sid=sid, prop=key) - _LOGGER.info("Publishing message to topic " + topic + ": " + str(value) + ".") - self._client.publish(topic, payload=value, qos=0, retain=retain) + _LOGGER.info("Publishing message to topic " + topic + ": " + str(items[key]) + ".") + self._client.publish(topic, payload=items[key], qos=0, retain=retain) def _mqtt_on_connect(self, client, userdata, rc, unk): _LOGGER.info("Connected to mqtt server.")