Compare commits

...

16 Commits

Author SHA1 Message Date
ted
e22d95a293
Merge 4e1185f4e5 into e69448f2eb 2025-03-05 16:52:53 +08:00
Necroneco
e69448f2eb
feat: add entity_category for indicator-light (#697)
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-03-05 16:13:17 +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
4 changed files with 72 additions and 6 deletions

View File

@ -549,6 +549,10 @@ class MIoTDevice:
# Optional actions
# Optional events
miot_service.platform = platform
# entity_category
if entity_category := SPEC_SERVICE_TRANS_MAP[service_name].get(
'entity_category', None):
miot_service.entity_category = entity_category
return entity_data
def parse_miot_property_entity(self, miot_prop: MIoTSpecProperty) -> bool:
@ -899,6 +903,7 @@ class MIoTServiceEntity(Entity):
self._attr_name = (
f'{"* "if self.entity_data.spec.proprietary else " "}'
f'{self.entity_data.spec.description_trans}')
self._attr_entity_category = entity_data.spec.entity_category
# Set entity attr
self._attr_unique_id = self.entity_id
self._attr_should_poll = False

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]
@ -465,7 +471,7 @@ class _MIoTSpecBase:
iid: int
type_: str
description: str
description_trans: str
description_trans: Optional[str]
proprietary: bool
need_filter: bool
name: str
@ -476,6 +482,7 @@ class _MIoTSpecBase:
device_class: Any
state_class: Any
external_unit: Any
entity_category: Optional[str]
spec_id: int
@ -494,6 +501,7 @@ class _MIoTSpecBase:
self.device_class = None
self.state_class = None
self.external_unit = None
self.entity_category = None
self.spec_id = hash(f'{self.type_}.{self.iid}')

View File

@ -51,6 +51,7 @@ from homeassistant.components.event import EventDeviceClass
from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
EntityCategory,
LIGHT_LUX,
UnitOfEnergy,
UnitOfPower,
@ -330,7 +331,8 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'events': set<event instance name: str>,
'actions': set<action instance name: str>
},
'entity': str
'entity': str,
'entity_category'?: str
}
}
"""
@ -348,10 +350,23 @@ SPEC_SERVICE_TRANS_MAP: dict = {
},
'entity': 'light'
},
'indicator-light': 'light',
'ambient-light': 'light',
'night-light': 'light',
'white-light': 'light',
'indicator-light': {
'required': {
'properties': {
'on': {'read', 'write'}
}
},
'optional': {
'properties': {
'mode', 'brightness',
}
},
'entity': 'light',
'entity_category': EntityCategory.CONFIG
},
'fan': {
'required': {
'properties': {

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]: