From a10b17fb0923bfeaa0950a24c7cae054b50cd864 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Sun, 8 Jan 2023 19:47:21 +0300 Subject: [PATCH] Add support Aqara Thermostat E1 --- custom_components/xiaomi_gateway3/climate.py | 48 +++++++++++++++++++ .../core/converters/devices.py | 19 ++++++++ 2 files changed, 67 insertions(+) diff --git a/custom_components/xiaomi_gateway3/climate.py b/custom_components/xiaomi_gateway3/climate.py index e653a0d6..e04e3217 100644 --- a/custom_components/xiaomi_gateway3/climate.py +++ b/custom_components/xiaomi_gateway3/climate.py @@ -21,6 +21,8 @@ def setup(gateway: XGateway, device: XDevice, conv: Converter): if conv.attr in device.entities: entity: XEntity = device.entities[conv.attr] entity.gw = gateway + elif conv.mi == "4.21.85": + entity = AqaraE1(gateway, device, conv) else: entity = XiaomiClimate(gateway, device, conv) async_add_entities([entity]) @@ -71,3 +73,49 @@ async def async_set_fan_mode(self, fan_mode: str) -> None: async def async_set_hvac_mode(self, hvac_mode: str) -> None: payload = {"hvac_mode": hvac_mode} await self.device_send({self.attr: payload}) + + +# noinspection PyAbstractClass +class AqaraE1(XEntity, ClimateEntity): + _attr_hvac_mode = None + _attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_AUTO] + _attr_supported_features = SUPPORT_TARGET_TEMPERATURE + _attr_temperature_unit = TEMP_CELSIUS + _attr_max_temp = 30 + _attr_min_temp = 5 + _attr_target_temperature_step = 0.5 + + _enabled = False + _mode = None + + @callback + def async_set_state(self, data: dict): + if "climate" in data: + self._enabled = data["climate"] + if "mode" in data: + self._mode = data["mode"] + if "current_temp" in data: + self._attr_current_temperature = data["current_temp"] + if "target_temp" in data: + self._attr_target_temperature = data["target_temp"] + + if self._enabled: + self._attr_hvac_mode = self._mode or HVAC_MODE_OFF + else: + self._attr_hvac_mode = HVAC_MODE_OFF + + async def async_update(self): + await self.device_read(self.subscribed_attrs) + + async def async_set_temperature(self, **kwargs) -> None: + payload = {"target_temp": kwargs[ATTR_TEMPERATURE]} + await self.device_send({self.attr: payload}) + + async def async_set_hvac_mode(self, hvac_mode: str) -> None: + if hvac_mode in (HVAC_MODE_HEAT, HVAC_MODE_AUTO): + payload = {"mode": hvac_mode} + elif hvac_mode == HVAC_MODE_OFF: + payload = {"climate": False} + else: + return + await self.device_send(payload) diff --git a/custom_components/xiaomi_gateway3/core/converters/devices.py b/custom_components/xiaomi_gateway3/core/converters/devices.py index 470646bf..dfb4fe47 100644 --- a/custom_components/xiaomi_gateway3/core/converters/devices.py +++ b/custom_components/xiaomi_gateway3/core/converters/devices.py @@ -468,6 +468,25 @@ }), ClimateTempConv("target_temp", mi="14.9.85"), ], +}, { + "lumi.airrtc.agl001": ["Aqara", "Thermostat E1", "SRTS-A01"], + "spec": [ + BoolConv("climate", "climate", mi="4.21.85"), + # 0: Manual module 1: Smart schedule mode 2: Antifreeze mode 3: Installation mode + MapConv("mode", mi="14.51.85", parent="climate", map={0: "heat", 2: "auto"}), + MathConv("current_temp", mi="0.1.85", multiply=0.01, parent="climate"), + MathConv("target_temp", mi="1.8.85", multiply=0.01, parent="climate"), + MathConv("antifreeze_temp", "number", mi="1.10.85", multiply=0.01, min=500, + max=15000), + BoolConv("window_detection", "switch", mi="4.24.85", enabled=False), + BoolConv("valve_calibration", "switch", mi="4.22.85", enabled=False), + BoolConv("valve_notification", "switch", mi="4.25.85", enabled=False), + BoolConv("child_lock", "switch", mi="4.26.85", enabled=False), + MapConv("find_device", "switch", mi="8.0.2096", map={2: True, 1: False}, + enabled=False), + Converter("battery", "sensor", mi="8.0.2001"), + ChipTemp, + ], }, { "lumi.airrtc.vrfegl01": ["Xiaomi", "VRF Air Conditioning EU"], "support": 1,