Просмотр исходного кода

Modify payload command for tinytuya

pytuya supported two commands ("status" and "set"). For status, the higher level status()
method is used, which still works. But for set, in order to set multiple dps at once,
the lower level generate_payload method is used, passing in the commands. But tinytuya
has changed to use int commands defined as constants: AP_CONFIG, CONTROL, STATUS,
HEART_BEAT, DP_QUERY, CONTROL_NEW, DP_QUERY_NEW, UPDAtEDPS are the new commands, with
some differences for devices with 22 character IDs.  Equivalant of "status" is DP_QUERY
and equivalent of "set" is CONTROL, though some devices may need DP_QUERY_NEW and
CONTROL_NEW by the looks of the protocol (it does not appear that tinytuya handles this
automatically, unfortunately).
Jason Rumney 4 лет назад
Родитель
Сommit
81e46d668d
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      custom_components/tuya_local/device.py

+ 4 - 4
custom_components/tuya_local/device.py

@@ -6,6 +6,8 @@ import json
 import logging
 import logging
 from threading import Lock, Timer
 from threading import Lock, Timer
 from time import time
 from time import time
+from tinytuya import CONTROL, Device as TuyaDevice
+
 
 
 from homeassistant.const import TEMP_CELSIUS
 from homeassistant.const import TEMP_CELSIUS
 from homeassistant.core import HomeAssistant
 from homeassistant.core import HomeAssistant
@@ -39,12 +41,10 @@ class TuyaLocalDevice(object):
             address (str): The network address.
             address (str): The network address.
             local_key (str): The encryption key.
             local_key (str): The encryption key.
         """
         """
-        import tinytuya
-
         self._name = name
         self._name = name
         self._api_protocol_version_index = None
         self._api_protocol_version_index = None
         self._api_protocol_working = False
         self._api_protocol_working = False
-        self._api = tinytuya.Device(dev_id, address, local_key)
+        self._api = TuyaDevice(dev_id, address, local_key)
         self._refresh_task = None
         self._refresh_task = None
         self._rotate_api_protocol_version()
         self._rotate_api_protocol_version()
 
 
@@ -207,7 +207,7 @@ class TuyaLocalDevice(object):
 
 
     def _send_pending_updates(self):
     def _send_pending_updates(self):
         pending_properties = self._get_pending_properties()
         pending_properties = self._get_pending_properties()
-        payload = self._api.generate_payload("set", pending_properties)
+        payload = self._api.generate_payload(CONTROL, pending_properties)
 
 
         _LOGGER.debug(f"sending dps update: {json.dumps(pending_properties)}")
         _LOGGER.debug(f"sending dps update: {json.dumps(pending_properties)}")