mrwiwi / tydom2mqtt

Link between a Delta Dore's Tydom Hub and and a MQTT broker, unofficial of course.
MIT License
28 stars 17 forks source link

Adding PositionCmd #6

Closed GiPe66 closed 4 years ago

GiPe66 commented 4 years ago

Hello,

This patch implements the positionCmd command of the tydom 1.0.

It allows the following commands: "DOWN", "UP", "STOP", "UP_SLOW", "DOWN_SLOW", "FAVORIT1", "FAVORIT2"

mqtt topic paylod is: cover/tydom/1581346948/set_positionCmd "UP"

Be aware that the set_positionCmd test must be done before the set_position test as set_position is a sub-string of set_positionCmd.

--- git/mqtt_client.py  2020-03-24 06:22:32.000000000 +0100
+++ mqtt_client.py      2020-03-24 15:16:41.000000000 +0100
@@ -101,6 +101,18 @@
             else:
                 await self.tydom.put_devices_data(str(get_id), 'position', str(json.loads(payload)))

+        elif ('set_positionCmd' in str(topic)) and not ('homeassistant'in str(topic)):
+            get_id = (topic.split("/"))[2] #extract id from mqtt
+            print(str(get_id), 'positionCmd', json.loads(payload))
+            if not self.tydom.connection.open:
+                print('MQTT req : Websocket not opened, reconnect...')
+                await self.tydom.connect()
+                await self.tydom.put_devices_data(str(get_id), 'positionCmd', str(json.loads(payload)))
+
+            else:
+                if not (str(json.loads(payload)) == ''):
+                    await self.tydom.put_devices_data(str(get_id), 'positionCmd', str(json.loads(payload)))
+
         elif ('set_position' in str(topic)) and not ('homeassistant'in str(topic)):

             print('Incoming MQTT set_position request : ', topic, payload)

Keep on the good job. Thanks !

Jean-Paul.

mrwiwi commented 4 years ago

Added in next release, thanks !

GiPe66 commented 4 years ago

Hi William,

as I wrote in my proposal, set_positionCmd test must be before set_Positio.

Otherwise set_position is a false match in set_positionCmd and the set_positionCmd match is never done.

Regards, Jean-Paul.