Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add entity_category for indicator-light #697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions custom_components/xiaomi_home/miot/miot_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
CONCENTRATION_PARTS_PER_BILLION,
CONCENTRATION_PARTS_PER_MILLION,
DEGREE,
EntityCategory,
LIGHT_LUX,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS,
Expand Down Expand Up @@ -549,6 +550,9 @@ def parse_miot_service_entity(
# Optional actions
# Optional events
miot_service.platform = platform
# entity_category:
if entity_category := SPEC_SERVICE_TRANS_MAP[service_name].get('entity_category'):
miot_service.entity_category = entity_category
return entity_data

def parse_miot_property_entity(self, miot_prop: MIoTSpecProperty) -> bool:
Expand Down Expand Up @@ -899,6 +903,7 @@ def __init__(
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
Expand Down
2 changes: 2 additions & 0 deletions custom_components/xiaomi_home/miot/miot_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class _MIoTSpecBase:
device_class: Any
state_class: Any
external_unit: Any
entity_category: str | None

spec_id: int

Expand All @@ -494,6 +495,7 @@ def __init__(self, spec: dict) -> None:
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}')

Expand Down
19 changes: 17 additions & 2 deletions custom_components/xiaomi_home/miot/specs/specv2entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
EntityCategory,
LIGHT_LUX,
UnitOfEnergy,
UnitOfPower,
Expand Down Expand Up @@ -264,7 +265,8 @@
'events': set<event instance name: str>,
'actions': set<action instance name: str>
},
'entity': str
'entity': str,
'entity_category'?: str,
}
}
"""
Expand All @@ -282,10 +284,23 @@
},
'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': {
Expand Down