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

Add an error_code attribute.

Numeric error codes are easier to deal with in automations and template sensors.
Descriptive errors may be subject to change.

- Make unknown errors more descriptive.
- Make error "OK" for heater when there is no error. null looks like something is wrong.
Jason Rumney 5 лет назад
Родитель
Сommit
174e8e0003

+ 6 - 4
custom_components/tuya_local/dehumidifier/climate.py

@@ -272,13 +272,15 @@ class GoldairDehumidifier(ClimateDevice):
     @property
     def device_state_attributes(self):
         """Get additional attributes that HA doesn't naturally support."""
-        error = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ERROR])
-        if isinstance(error, int):
+        error_code = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ERROR])
+        if isinstance(error_code, int):
             error = TuyaLocalDevice.get_key_for_value(
-                ERROR_CODE_TO_DPS_CODE, error, error
+                ERROR_CODE_TO_DPS_CODE, error, f"Error {error}"
             )
+        else
+            error = None
 
-        return {ATTR_ERROR: error or None, ATTR_DEFROSTING: self.defrosting}
+        return {ATTR_ERROR: error, ATTR_ERROR_CODE: error_code, ATTR_DEFROSTING: self.defrosting}
 
     async def async_update(self):
         await self._device.async_refresh()

+ 1 - 0
custom_components/tuya_local/dehumidifier/const.py

@@ -14,6 +14,7 @@ ATTR_TARGET_HUMIDITY = "target_humidity"
 ATTR_AIR_CLEAN_ON = "air_clean_on"
 ATTR_CHILD_LOCK = "child_lock"
 ATTR_ERROR = "error"
+ATTR_ERROR_CODE = "error_code"
 ATTR_DISPLAY_ON = "display_on"
 ATTR_DEFROSTING = "defrosting"
 

+ 6 - 3
custom_components/tuya_local/heater/climate.py

@@ -235,9 +235,12 @@ class GoldairHeater(ClimateDevice):
     @property
     def device_state_attributes(self):
         """Get additional attributes that HA doesn't naturally support."""
-        error = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ERROR])
-
-        return {ATTR_ERROR: error or None}
+        error_code = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ERROR])
+        if error_code:
+            error = f"Error {error_code}"
+        else:
+            error = "OK"
+        return {ATTR_ERROR: error, ATTR_ERROR_CODE: error}
 
     async def async_update(self):
         await self._device.async_refresh()

+ 1 - 0
custom_components/tuya_local/heater/const.py

@@ -9,6 +9,7 @@ from homeassistant.const import ATTR_TEMPERATURE
 ATTR_TARGET_TEMPERATURE = "target_temperature"
 ATTR_CHILD_LOCK = "child_lock"
 ATTR_ERROR = "error"
+ATTR_ERROR_CODE = "error_code"
 ATTR_POWER_MODE_AUTO = "auto"
 ATTR_POWER_MODE_USER = "user"
 ATTR_POWER_LEVEL = "power_level"