Compare commits

...

5 Commits

Author SHA1 Message Date
ohyeah521
90e9eb46a4
Merge 1258d3f3d3 into b40d357230 2026-01-03 09:16:26 +01:00
Li Shuzhen
b40d357230
fix: update mesh offline state (#1579)
Some checks failed
Tests / check-rule-format (push) Has been cancelled
Validate / validate-hassfest (push) Has been cancelled
Validate / validate-hacs (push) Has been cancelled
Validate / validate-lint (push) Has been cancelled
Validate / validate-setup (push) Has been cancelled
2025-12-31 09:58:29 +08:00
ohyeah521
1258d3f3d3
Merge branch 'XiaoMi:main' into main 2025-09-10 14:05:45 +08:00
ohyeah521
64d9d54170
Merge branch 'XiaoMi:main' into main 2025-08-24 10:12:48 -04:00
ohyeah521
059eee33e0
Fix #1309 #1124
# HomeKit Bridge: fan_modes must be "auto"、"low"、"medium"、"high"
2025-07-28 23:23:21 +08:00
2 changed files with 31 additions and 4 deletions

View File

@ -224,6 +224,15 @@ class FeatureFanMode(MIoTServiceEntity, ClimateEntity):
_prop_fan_level: Optional[MIoTSpecProperty]
_fan_mode_map: Optional[dict[int, str]]
# HomeKit Bridge: fan_modes must be "auto"、"low"、"medium"、"high"
_fan_mode_translation_map = {
"自动": "auto",
"低风": "low",
"中风": "medium",
"高风": "high",
}
_fan_mode_translation_map_rev = {v: k for k, v in _fan_mode_translation_map.items()}
def __init__(self, miot_device: MIoTDevice,
entity_data: MIoTEntityData) -> None:
"""Initialize the feature class."""
@ -243,7 +252,13 @@ class FeatureFanMode(MIoTServiceEntity, ClimateEntity):
self.entity_id)
continue
self._fan_mode_map = prop.value_list.to_map()
self._attr_fan_modes = prop.value_list.descriptions
# save org fan speed
self._raw_fan_modes = prop.value_list.descriptions
self._attr_fan_modes = [
self._fan_mode_translation_map.get(mode, mode)
for mode in self._raw_fan_modes
]
self._attr_supported_features |= ClimateEntityFeature.FAN_MODE
self._prop_fan_level = prop
elif prop.name == 'on' and prop.service.name == 'fan-control':
@ -264,7 +279,11 @@ class FeatureFanMode(MIoTServiceEntity, ClimateEntity):
if fan_mode == FAN_ON:
await self.set_property_async(prop=self._prop_fan_on, value=True)
return
mode_value = self.get_map_key(map_=self._fan_mode_map, value=fan_mode)
chinese_fan_mode = self._fan_mode_translation_map_rev.get(fan_mode, fan_mode)
mode_value = self.get_map_key(map_=self._fan_mode_map, value=chinese_fan_mode)
if mode_value is None or not await self.set_property_async(
prop=self._prop_fan_level, value=mode_value):
raise RuntimeError(f'set climate prop.fan_mode failed, {fan_mode}, '
@ -278,9 +297,15 @@ class FeatureFanMode(MIoTServiceEntity, ClimateEntity):
if self._prop_fan_level is None and self._prop_fan_on:
return (FAN_ON if self.get_prop_value(
prop=self._prop_fan_on) else FAN_OFF)
return self.get_map_value(
current_chinese_mode = self.get_map_value(
map_=self._fan_mode_map,
key=self.get_prop_value(prop=self._prop_fan_level))
if current_chinese_mode is None:
return None
return self._fan_mode_translation_map.get(current_chinese_mode, current_chinese_mode)
class FeatureSwingMode(MIoTServiceEntity, ClimateEntity):

View File

@ -1527,6 +1527,8 @@ class MIoTClient:
if did not in filter_dids:
continue
device_old = self._device_list_gateway.get(did, None)
gw_state_old = device_old.get(
'online', False) if device_old else False
gw_state_new: bool = False
device_new = gw_list.pop(did, None)
if device_new:
@ -1540,7 +1542,7 @@ class MIoTClient:
device_old['online'] = False
# Update cache group_id
info['group_id'] = group_id
if not gw_state_new:
if (gw_state_old == gw_state_new) and (not gw_state_new):
continue
self.__update_device_msg_sub(did=did)
state_old: Optional[bool] = info.get('online', None)