Pārlūkot izejas kodu

WIP: Update icons including those that represent the current status

Dehumidifier states represented by icons:
 - Normal
 - Tank full or missing
 - Defrosting

Heater states represented by icons:
 - Heating (HVAC mode is Heat and power level is not "stop"; this means
   that when you have the power mode set to Auto and the heater stops
   heating because the temperature is high enough, the icon will switch
   to idle to represent this state)
 - Idle

Fan is now a fan but has no dynamic states.

Also fixed a bug with manual power modes breaking the swing mode
dropdown in the UI.
Nik Rolls 5 gadi atpakaļ
vecāks
revīzija
30b65e040e

+ 21 - 3
custom_components/goldair_climate/dehumidifier/climate.py

@@ -22,6 +22,7 @@ from .const import (
     ATTR_ERROR,
     ATTR_TARGET_HUMIDITY,
     ERROR_CODE_TO_DPS_CODE,
+    ERROR_TANK,
     FAN_MODE_TO_DPS_MODE,
     HVAC_MODE_TO_DPS_MODE,
     PRESET_AIR_CLEAN,
@@ -76,6 +77,16 @@ class GoldairDehumidifier(ClimateDevice):
         """Return device information about this dehumidifier."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend based on the device state."""
+        if self.tank_full_or_missing:
+            return "mdi:cup-water"
+        elif self.defrosting:
+            return "mdi:snowflake-melt"
+        else:
+            return "mdi:air-humidifier"
+
     @property
     def current_humidity(self):
         """Return the current reading of the humidity sensor."""
@@ -244,6 +255,15 @@ class GoldairDehumidifier(ClimateDevice):
             PROPERTY_TO_DPS_ID[ATTR_FAN_MODE], dps_mode
         )
 
+    @property
+    def tank_full_or_missing(self):
+        error = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_ERROR])
+        return error == ERROR_TANK
+
+    @property
+    def defrosting(self):
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DEFROSTING])
+
     @property
     def device_state_attributes(self):
         """Get additional attributes that HA doesn't naturally support."""
@@ -253,9 +273,7 @@ class GoldairDehumidifier(ClimateDevice):
                 ERROR_CODE_TO_DPS_CODE, error, error
             )
 
-        defrosting = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DEFROSTING])
-
-        return {ATTR_ERROR: error or None, ATTR_DEFROSTING: defrosting}
+        return {ATTR_ERROR: error or None, ATTR_DEFROSTING: self.defrosting}
 
     async def async_update(self):
         await self._device.async_refresh()

+ 9 - 10
custom_components/goldair_climate/dehumidifier/light.py

@@ -38,19 +38,18 @@ class GoldairDehumidifierLedDisplayLight(Light):
         """Return device information about this dehumidifier LED display."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend for this device."""
+        if self.is_on:
+            return "mdi:led-on"
+        else:
+            return "mdi:led-off"
+
     @property
     def is_on(self):
         """Return the current state."""
-        dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
-        dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
-
-        if (
-            dps_hvac_mode is None
-            or dps_hvac_mode == HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]
-        ):
-            return STATE_UNAVAILABLE
-        else:
-            return dps_display_on
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
 
     async def async_turn_on(self):
         await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)

+ 5 - 0
custom_components/goldair_climate/fan/climate.py

@@ -62,6 +62,11 @@ class GoldairFan(ClimateDevice):
         """Return device information about this fan."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend for this device."""
+        return "mdi:fan"
+
     @property
     def temperature_unit(self):
         """This is not used but required by Home Assistant."""

+ 9 - 10
custom_components/goldair_climate/fan/light.py

@@ -38,19 +38,18 @@ class GoldairFanLedDisplayLight(Light):
         """Return device information about this LED display."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend for this device."""
+        if self.is_on:
+            return "mdi:led-on"
+        else:
+            return "mdi:led-off"
+
     @property
     def is_on(self):
         """Return the current state."""
-        dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
-        dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
-
-        if (
-            dps_hvac_mode is None
-            or dps_hvac_mode == HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]
-        ):
-            return STATE_UNAVAILABLE
-        else:
-            return dps_display_on
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
 
     async def async_turn_on(self):
         await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)

+ 13 - 7
custom_components/goldair_climate/heater/climate.py

@@ -5,6 +5,7 @@ from homeassistant.components.climate import ClimateDevice
 from homeassistant.components.climate.const import (
     ATTR_HVAC_MODE,
     ATTR_PRESET_MODE,
+    HVAC_MODE_HEAT,
     SUPPORT_PRESET_MODE,
     SUPPORT_SWING_MODE,
     SUPPORT_TARGET_TEMPERATURE,
@@ -75,6 +76,16 @@ class GoldairHeater(ClimateDevice):
         """Return device information about this heater."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend for this device."""
+        hvac_mode = self.hvac_mode
+        power_level = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_POWER_LEVEL])
+        if hvac_mode == HVAC_MODE_HEAT and power_level != "stop":
+            return "mdi:radiator"
+        else:
+            return "mdi:radiator-disabled"
+
     @property
     def temperature_unit(self):
         """Return the unit of measurement."""
@@ -200,13 +211,8 @@ class GoldairHeater(ClimateDevice):
         """Return the power level."""
         dps_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_POWER_MODE])
         if dps_mode == ATTR_POWER_MODE_USER:
-            return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_POWER_LEVEL])
-        elif dps_mode == ATTR_POWER_MODE_AUTO:
-            return GoldairTuyaDevice.get_key_for_value(
-                POWER_LEVEL_TO_DPS_LEVEL, dps_mode
-            )
-        else:
-            return None
+            dps_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_POWER_LEVEL])
+        return GoldairTuyaDevice.get_key_for_value(POWER_LEVEL_TO_DPS_LEVEL, dps_mode)
 
     @property
     def swing_modes(self):

+ 5 - 2
custom_components/goldair_climate/heater/const.py

@@ -39,12 +39,15 @@ PRESET_MODE_TO_DPS_MODE = {
     STATE_ECO: "ECO",
     STATE_ANTI_FREEZE: "AF",
 }
+
+POWER_LEVEL_STOP = "stop"
+POWER_LEVEL_AUTO = "auto"
 POWER_LEVEL_TO_DPS_LEVEL = {
-    "Stop": "stop",
+    "Stop": POWER_LEVEL_STOP,
     "1": "1",
     "2": "2",
     "3": "3",
     "4": "4",
     "5": "5",
-    "Auto": "auto",
+    "Auto": POWER_LEVEL_AUTO,
 }

+ 9 - 10
custom_components/goldair_climate/heater/light.py

@@ -38,19 +38,18 @@ class GoldairHeaterLedDisplayLight(Light):
         """Return device information about this heater LED display."""
         return self._device.device_info
 
+    @property
+    def icon(self):
+        """Return the icon to use in the frontend for this device."""
+        if self.is_on:
+            return "mdi:led-on"
+        else:
+            return "mdi:led-off"
+
     @property
     def is_on(self):
         """Return the current state."""
-        dps_hvac_mode = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_HVAC_MODE])
-        dps_display_on = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
-
-        if (
-            dps_hvac_mode is None
-            or dps_hvac_mode == HVAC_MODE_TO_DPS_MODE[HVAC_MODE_OFF]
-        ):
-            return STATE_UNAVAILABLE
-        else:
-            return dps_display_on
+        return self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON])
 
     async def async_turn_on(self):
         await self._device.async_set_property(PROPERTY_TO_DPS_ID[ATTR_DISPLAY_ON], True)