Преглед изворни кода

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 година
родитељ
комит
a40468d6aa
2 измењених фајлова са 6 додато и 1 уклоњено
  1. 1 1
      custom_components/tuya_local/config_flow.py
  2. 5 0
      custom_components/tuya_local/device.py

+ 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
         "Test", config[CONF_DEVICE_ID], config[CONF_HOST], config[CONF_LOCAL_KEY], hass
     )
     )
     await device.async_refresh()
     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",
             "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
     @property
     def temperature_unit(self):
     def temperature_unit(self):
         return self._TEMPERATURE_UNIT
         return self._TEMPERATURE_UNIT