Compare commits

...

17 Commits

Author SHA1 Message Date
ted
4f4ff94ce9
Merge 4e1185f4e5 into 8be0fa5d61 2025-03-13 13:14:41 +08:00
Li Shuzhen
8be0fa5d61
fix: MIoT-Spec-V2 conflicts of xiaomi.fan.p5 and mike.bhf_light.2 (#866) 2025-03-12 15:22:03 +08:00
Necroneco
07cb4ed193
feat: avoid setting icon when device_class is defined (#855) 2025-03-12 15:17:02 +08:00
ted
4e1185f4e5
Merge branch 'XiaoMi:main' into main 2025-02-28 20:20:55 +08:00
ted
6ad8da42be
Merge branch 'XiaoMi:main' into main 2025-02-25 10:45:50 +08:00
ted
4aa6bb579f
Merge branch 'XiaoMi:main' into main 2025-02-19 14:05:50 +08:00
ted
e83aa9367e
Merge branch 'XiaoMi:main' into main 2025-01-31 15:25:58 +08:00
tedwang
04c44f36b1 Merge branch 'main' of https://github.com/zghnwsq/fork_ha_xiaomi_home into fix_vacuum_warn 2025-01-23 11:01:23 +08:00
ted
a40363d3e6
Merge branch 'XiaoMi:main' into main 2025-01-23 10:17:55 +08:00
tedwang
13e6863678 fix: Fix the HA warning in the logs related to vacuum state setting
Adapt to new vacuum state property, set the activity property instead of directly setting the state property.
2025-01-23 10:09:15 +08:00
ted
b0d0d6b107
Merge branch 'XiaoMi:main' into main 2025-01-21 16:27:32 +08:00
ted
085caff660
Merge branch 'XiaoMi:main' into main 2025-01-18 16:34:16 +08:00
ted
fe3756db9b
Merge branch 'XiaoMi:main' into main 2025-01-16 09:18:40 +08:00
ted
bf33f0c60d
Merge branch 'XiaoMi:main' into main 2025-01-13 13:58:58 +08:00
ted
72f3a5df3e
Merge branch 'XiaoMi:main' into main 2025-01-11 20:35:24 +08:00
ted
f452611b87
Merge branch 'XiaoMi:main' into main 2025-01-08 11:43:20 +08:00
tedwang
36d5a3e4de docs: fix table header misplacement
fix table header misplacement
2025-01-03 10:54:41 +08:00
8 changed files with 74 additions and 13 deletions

View File

@ -46,6 +46,7 @@ off Xiaomi or its affiliates' products.
Event entities for Xiaomi Home.
"""
from __future__ import annotations
import logging
from typing import Any
from homeassistant.config_entries import ConfigEntry
@ -57,6 +58,8 @@ from .miot.miot_spec import MIoTSpecEvent
from .miot.miot_device import MIoTDevice, MIoTEventEntity
from .miot.const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
@ -89,4 +92,5 @@ class Event(MIoTEventEntity, EventEntity):
self, name: str, arguments: dict[str, Any] | None = None
) -> None:
"""An event is occurred."""
_LOGGER.debug('%s, attributes: %s', name, str(arguments))
self._trigger_event(event_type=name, event_attributes=arguments)

View File

@ -591,13 +591,8 @@ class MIoTDevice:
# Priority: spec_modify.unit > unit_convert > specv2entity.unit
miot_prop.external_unit = SPEC_PROP_TRANS_MAP['properties'][
prop_name]['unit_of_measurement']
if (
not miot_prop.icon
and 'icon' in SPEC_PROP_TRANS_MAP['properties'][prop_name]
):
# Priority: spec_modify.icon > icon_convert > specv2entity.icon
miot_prop.icon = SPEC_PROP_TRANS_MAP['properties'][prop_name][
'icon']
# Priority: default.icon when device_class is set > spec_modify.icon
# > icon_convert
miot_prop.platform = platform
return True

View File

@ -1215,9 +1215,10 @@ class MipsLocalClient(_MipsClient):
or 'eiid' not in msg
# or 'arguments' not in msg
):
# self.log_error(f'on_event_msg, recv unknown msg, {payload}')
self.log_error('unknown event msg, %s', payload)
return
if 'arguments' not in msg:
self.log_info('wrong event msg, %s', payload)
msg['arguments'] = []
if handler:
self.log_debug('local, on event_occurred, %s', payload)

View File

@ -213,6 +213,12 @@ class MIoTSpecValueList:
return item.description
return None
def get_name_by_value(self, value: Any) -> Optional[str]:
for item in self.items:
if item.value == value:
return item.name
return None
def dump(self) -> list:
return [item.dump() for item in self.items]
@ -1205,6 +1211,9 @@ class _SpecModify:
if isinstance(self._selected, str):
return await self.set_spec_async(urn=self._selected)
def get_prop_name(self, siid: int, piid: int) -> Optional[str]:
return self.__get_prop_item(siid=siid, piid=piid, key='name')
def get_prop_unit(self, siid: int, piid: int) -> Optional[str]:
return self.__get_prop_item(siid=siid, piid=piid, key='unit')
@ -1518,6 +1527,10 @@ class MIoTSpecParser:
siid=service['iid'], piid=property_['iid'])
if custom_range:
spec_prop.value_range = custom_range
custom_name = self._spec_modify.get_prop_name(
siid=service['iid'], piid=property_['iid'])
if custom_name:
spec_prop.name = custom_name
# Parse service event
for event in service.get('events', []):
if (

View File

@ -58,3 +58,13 @@ urn:miot-spec-v2:device:bath-heater:0000A028:opple-acmoto:1:
description: medium
- value: 255
description: high
urn:miot-spec-v2:device:bath-heater:0000A028:mike-2:1:
prop.3.1:
name: mode-a
prop.3.11:
name: mode-b
prop.3.12:
name: mode-c
urn:miot-spec-v2:device:fan:0000A005:xiaomi-p51:1:
prop.2.2:
name: fan-level-a

View File

@ -88,7 +88,7 @@ class Number(MIoTPropertyEntity, NumberEntity):
if self.spec.external_unit:
self._attr_native_unit_of_measurement = self.spec.external_unit
# Set icon
if self.spec.icon:
if self.spec.icon and not self.device_class:
self._attr_icon = self.spec.icon
# Set value range
if self._value_range:

View File

@ -116,7 +116,7 @@ class Sensor(MIoTPropertyEntity, SensorEntity):
if spec.state_class:
self._attr_state_class = spec.state_class
# Set icon
if spec.icon:
if spec.icon and not self.device_class:
self._attr_icon = spec.icon
@property

View File

@ -54,7 +54,8 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.components.vacuum import (
StateVacuumEntity,
VacuumEntityFeature
VacuumEntityFeature,
VacuumActivity
)
from .miot.const import DOMAIN
@ -191,10 +192,47 @@ class Vacuum(MIoTServiceEntity, StateVacuumEntity):
@property
def state(self) -> Optional[str]:
"""Return the current state of the vacuum cleaner."""
"""Return the current state of the vacuum cleaner.
To fix the HA warning below:
Detected that custom integration 'xiaomi_home' is setting state
directly.Entity XXX(<class 'custom_components.xiaomi_home.vacuum
.Vacuum'>)should implement the 'activity' property and return
its state using the VacuumActivity enum.This will stop working in
Home Assistant 2026.1.
Refer to
https://developers.home-assistant.io/blog/2024/12/08/new-vacuum-state-property
There are only 6 states in VacuumActivity enum. To be compatible with
more constants, try get matching VacuumActivity enum first, return state
string as before if there is no match. In Home Assistant 2026.1, every
state should map to a VacuumActivity enum.
"""
if (activity := self.activity) is not None:
return activity
return self.get_map_value(
map_=self._status_map,
key=self.get_prop_value(prop=self._prop_status))
key=self.get_prop_value(prop=self._prop_status)
)
@property
def activity(self) -> VacuumActivity | None:
"""Return the current vacuum activity."""
state_trans_map = {
'Sleep': VacuumActivity.IDLE,
'Idle': VacuumActivity.IDLE,
'Paused': VacuumActivity.PAUSED,
'Go Charging': VacuumActivity.RETURNING,
'Charging': VacuumActivity.DOCKED,
'Sweeping': VacuumActivity.CLEANING,
'Sweeping and Mopping': VacuumActivity.CLEANING,
'Mopping': VacuumActivity.CLEANING,
'Error': VacuumActivity.ERROR,
}
prop_value = self.get_prop_value(prop=self._prop_status)
state_name = self._prop_status.value_list.get_name_by_value(prop_value)
return state_trans_map.get(state_name)
@property
def battery_level(self) -> Optional[int]: