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

Don't assume all devices will return DPS 1 or 3.

Judge that devices are communicating if they have returned any DPS rather than checking specific ones.
Jason Rumney 4 лет назад
Родитель
Сommit
a40468d6aa

+ 1 - 1
custom_components/tuya_local/config_flow.py

@@ -107,4 +107,4 @@ async def async_test_connection(config: dict, hass: HomeAssistant):
         "Test", config[CONF_DEVICE_ID], config[CONF_HOST], config[CONF_LOCAL_KEY], hass
     )
     await device.async_refresh()
-    return device.get_property("1") is not None or device.get_property("3") is not None
+    return device.has_returned_state()

+ 5 - 0
custom_components/tuya_local/device.py

@@ -76,6 +76,11 @@ class TuyaLocalDevice(object):
             "manufacturer": "Tuya",
         }
 
+    @property
+    def has_sent_state(self):
+        """Return True if the device has returned some state."""
+        return len(self._get_cached_state()) > 1
+
     @property
     def temperature_unit(self):
         return self._TEMPERATURE_UNIT