From 8714549f90f751cfac9618d90bcbdcbd8e3f3171 Mon Sep 17 00:00:00 2001 From: sususweet Date: Thu, 27 Nov 2025 21:39:49 +0800 Subject: [PATCH] feat: add support for fan-light. Fix #56. --- .../midea_auto_cloud/device_mapping/T0x13.py | 71 ++++++++++++++++++- custom_components/midea_auto_cloud/fan.py | 10 +++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/custom_components/midea_auto_cloud/device_mapping/T0x13.py b/custom_components/midea_auto_cloud/device_mapping/T0x13.py index 849b4ad..e2c1b3f 100644 --- a/custom_components/midea_auto_cloud/device_mapping/T0x13.py +++ b/custom_components/midea_auto_cloud/device_mapping/T0x13.py @@ -1,4 +1,5 @@ -from homeassistant.const import Platform +from homeassistant.components.fan import DIRECTION_FORWARD, DIRECTION_REVERSE +from homeassistant.const import Platform, UnitOfTemperature, PRECISION_WHOLE DEVICE_MAPPING = { "default": { @@ -57,5 +58,73 @@ DEVICE_MAPPING = { } } } + }, + "79010863": { + "rationale": ["off", "on"], + "queries": [{}], + "centralized": [], + "calculate": { + "get": [ + { + "lvalue": "[device_fan_speed]", + "rvalue": "int((int([fan_speed])) / 20) + 1" + }, + ], + "set": [ + { + "lvalue": "[fan_speed]", + "rvalue": "min(int((int([device_fan_speed]) - 1) * 20 + 1), 100)" + }, + ] + }, + "entities": { + Platform.LIGHT: { + "light": { + "power": "led_power", + "brightness": {"brightness": [1, 100]}, + "color_temp": {"color_temperature": [2700, 6500]}, + "preset_modes": { + "work": {"led_scene_light": "work"}, + "eating": {"led_scene_light": "eating"}, + "film": {"led_scene_light": "film"}, + "night": {"led_scene_light": "night"}, + "ledmanual": {"led_scene_light": "ledmanual"}, + } + } + }, + Platform.FAN: { + "fan": { + "power": "fan_power", + "speeds": list({"device_fan_speed": value + 1} for value in range(0, 6)), + "preset_modes": { + "breathing_wind": {"fan_scene": "breathing_wind"}, + "const_temperature": {"fan_scene": "const_temperature"}, + "fanmanual": {"fan_scene": "fanmanual"}, + "baby_wind": {"fan_scene": "baby_wind"}, + "sleep_wind": {"fan_scene": "sleep_wind"}, + "forest_wind": {"fan_scene": "forest_wind"} + }, + "directions": { + DIRECTION_FORWARD: {"arround_dir": "1"}, + DIRECTION_REVERSE: {"arround_dir": "0"}, + } + } + }, + Platform.CLIMATE: { + "thermostat": { + "power": "fan_power", + "hvac_modes": { + "off": {"fan_scene": "fanmanual"}, + "auto": {"fan_scene": "const_temperature"}, + }, + "target_temperature": "const_temperature_value", + "current_temperature": "indoor_temperature", + "min_temp": 20, + "max_temp": 35, + "temperature_unit": UnitOfTemperature.CELSIUS, + "precision": PRECISION_WHOLE, + } + } + } } } diff --git a/custom_components/midea_auto_cloud/fan.py b/custom_components/midea_auto_cloud/fan.py index 5127617..76b420d 100644 --- a/custom_components/midea_auto_cloud/fan.py +++ b/custom_components/midea_auto_cloud/fan.py @@ -108,6 +108,10 @@ class MideaFanEntity(MideaEntity, FanEntity): def oscillating(self): return self._get_status_on_off(self._key_oscillate) + @property + def current_direction(self): + return self._dict_get_selected(self._key_directions) + async def async_turn_on( self, percentage: int | None = None, @@ -147,3 +151,9 @@ class MideaFanEntity(MideaEntity, FanEntity): if self.oscillating != oscillating: await self._async_set_status_on_off(self._key_oscillate, oscillating) + async def async_set_direction(self, direction: str): + if not self._key_directions: + return + new_status = self._key_directions.get(direction) + if new_status: + await self.async_set_attributes(new_status) \ No newline at end of file