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

Add child lock support for Kogan heaters.

Also added reading of timer countdown, in case it is useful as a condition to block certain automations (for example).
Jason Rumney 5 лет назад
Родитель
Сommit
4ae05d2632

+ 1 - 1
README.md

@@ -111,7 +111,7 @@ tuya_local:
     *Default value: false* 
 
 #### child_lock
-    *(boolean) (Optional)* Whether to surface this appliances's child lock as a lock device (not supported for fans or Kogan Heaters).
+    *(boolean) (Optional)* Whether to surface this appliances's child lock as a lock device (not supported for fans).
 
     *Default value: false* 
 

+ 11 - 6
custom_components/tuya_local/kogan_heater/climate.py

@@ -5,9 +5,9 @@ dps:
   2 = target temperature (integer)
   3 = current temperature (integer)
   4 = preset_mode (string Low/High)
-  6 = timer state (boolean) [not supported - use HA based timers]
+  6 = child_lock (boolean)
   7 = hvac_mode (boolean)
-  8 = timer (integer) [not supported - use HA based timers]
+  8 = timer (integer) [supported for read only - use HA based timers]
 """
 
 from homeassistant.components.climate import ClimateDevice
@@ -24,11 +24,10 @@ from ..device import TuyaLocalDevice
 from .const import (
     ATTR_TARGET_TEMPERATURE,
     HVAC_MODE_TO_DPS_MODE,
-    PRESET_HIGH,
-    PRESET_LOW,
     PRESET_MODE_TO_DPS_MODE,
     PROPERTY_TO_DPS_ID,
 )
+
 SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
 
 
@@ -120,9 +119,9 @@ class KoganHeater(ClimateDevice):
         target_temperature = int(round(target_temperature))
 
         limits = self._TEMPERATURE_LIMITS
-        if not limits['min'] <= target_temperature <= limits['max']:
+        if not limits["min"] <= target_temperature <= limits["max"]:
             raise ValueError(
-                f'Target temperature ({target_temperature}) must be between '
+                f"Target temperature ({target_temperature}) must be between "
                 f'{limits["min"]} and {limits["max"]}'
             )
 
@@ -180,5 +179,11 @@ class KoganHeater(ClimateDevice):
             PROPERTY_TO_DPS_ID[ATTR_PRESET_MODE], dps_mode
         )
 
+    @property
+    def device_state_attributes(self):
+        """Get additional attributes that HA doesn't naturally support."""
+        timer = self._device.get_property(PROPERTY_TO_DPS_ID[ATTR_TIMER])
+        return {ATTR_TIMER: timer}
+
     async def async_update(self):
         await self._device.async_refresh()

+ 6 - 1
custom_components/tuya_local/kogan_heater/const.py

@@ -7,14 +7,19 @@ from homeassistant.components.climate.const import (
 from homeassistant.const import ATTR_TEMPERATURE
 
 ATTR_TARGET_TEMPERATURE = "target_temperature"
+ATTR_CHILD_LOCK = "child_lock"
+ATTR_TIMER = "timer"
+
 PRESET_LOW = 'LOW'
 PRESET_HIGH = 'HIGH'
 
 PROPERTY_TO_DPS_ID = {
-    ATTR_HVAC_MODE: "7",
     ATTR_TARGET_TEMPERATURE: "2",
     ATTR_TEMPERATURE: "3",
     ATTR_PRESET_MODE: "4",
+    ATTR_CHILD_LOCK: "6"
+    ATTR_HVAC_MODE: "7",
+    ATTR_TIMER: "8",
 }
 
 HVAC_MODE_TO_DPS_MODE = {HVAC_MODE_OFF: False, HVAC_MODE_HEAT: True}

+ 2 - 2
custom_components/tuya_local/lock.py

@@ -6,7 +6,7 @@ from .const import (CONF_DEVICE_ID, CONF_TYPE, CONF_TYPE_DEHUMIDIFIER,
                     CONF_TYPE_FAN, CONF_TYPE_HEATER, CONF_TYPE_KOGAN_HEATER, CONF_CHILD_LOCK, CONF_TYPE_AUTO)
 from .dehumidifier.lock import GoldairDehumidifierChildLock
 from .heater.lock import GoldairHeaterChildLock
-
+from .kogan_heater.lock import KoganHeaterChildLock
 
 async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
     """Set up the Goldair climate device according to its type."""
@@ -26,7 +26,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
     if discovery_info[CONF_TYPE] == CONF_TYPE_FAN:
         raise ValueError('Goldair fans do not support Child Lock.')
     if discovery_info[CONF_TYPE] == CONF_TYPE_KOGAN_HEATER:
-        raise ValueError('Kogan Heaters do not support Child Lock.')
+        data[CONF_CHILD_LOCK] = KoganHeaterChildLock(device)
 
     if CONF_CHILD_LOCK in data:
         async_add_entities([data[CONF_CHILD_LOCK]])