mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-17 15:41:15 +08:00
fix: fix some type error
This commit is contained in:
parent
af3c4572f9
commit
bfb6a96477
@ -85,6 +85,8 @@ class Event(MIoTEventEntity, EventEntity):
|
|||||||
# Set device_class
|
# Set device_class
|
||||||
self._attr_device_class = spec.device_class
|
self._attr_device_class = spec.device_class
|
||||||
|
|
||||||
def on_event_occurred(self, name: str, arguments: list[dict[int, Any]]):
|
def on_event_occurred(
|
||||||
|
self, name: str, arguments: dict[str, Any] | None = None
|
||||||
|
) -> None:
|
||||||
"""An event is occurred."""
|
"""An event is occurred."""
|
||||||
self._trigger_event(event_type=name, event_attributes=arguments)
|
self._trigger_event(event_type=name, event_attributes=arguments)
|
||||||
|
|||||||
@ -389,14 +389,20 @@ class MIoTDevice:
|
|||||||
self._entity_list[entity_data.platform].append(entity_data)
|
self._entity_list[entity_data.platform].append(entity_data)
|
||||||
|
|
||||||
def append_prop(self, prop: MIoTSpecProperty) -> None:
|
def append_prop(self, prop: MIoTSpecProperty) -> None:
|
||||||
|
if not prop.platform:
|
||||||
|
return
|
||||||
self._prop_list.setdefault(prop.platform, [])
|
self._prop_list.setdefault(prop.platform, [])
|
||||||
self._prop_list[prop.platform].append(prop)
|
self._prop_list[prop.platform].append(prop)
|
||||||
|
|
||||||
def append_event(self, event: MIoTSpecEvent) -> None:
|
def append_event(self, event: MIoTSpecEvent) -> None:
|
||||||
|
if not event.platform:
|
||||||
|
return
|
||||||
self._event_list.setdefault(event.platform, [])
|
self._event_list.setdefault(event.platform, [])
|
||||||
self._event_list[event.platform].append(event)
|
self._event_list[event.platform].append(event)
|
||||||
|
|
||||||
def append_action(self, action: MIoTSpecAction) -> None:
|
def append_action(self, action: MIoTSpecAction) -> None:
|
||||||
|
if not action.platform:
|
||||||
|
return
|
||||||
self._action_list.setdefault(action.platform, [])
|
self._action_list.setdefault(action.platform, [])
|
||||||
self._action_list[action.platform].append(action)
|
self._action_list[action.platform].append(action)
|
||||||
|
|
||||||
@ -625,7 +631,6 @@ class MIoTDevice:
|
|||||||
prop.platform = 'binary_sensor'
|
prop.platform = 'binary_sensor'
|
||||||
else:
|
else:
|
||||||
prop.platform = 'sensor'
|
prop.platform = 'sensor'
|
||||||
if prop.platform:
|
|
||||||
self.append_prop(prop=prop)
|
self.append_prop(prop=prop)
|
||||||
# STEP 3.2: event conversion
|
# STEP 3.2: event conversion
|
||||||
for event in service.events:
|
for event in service.events:
|
||||||
@ -796,12 +801,12 @@ class MIoTServiceEntity(Entity):
|
|||||||
self._state_sub_id = 0
|
self._state_sub_id = 0
|
||||||
self._value_sub_ids = {}
|
self._value_sub_ids = {}
|
||||||
# Gen entity id
|
# Gen entity id
|
||||||
if isinstance(entity_data.spec, MIoTSpecInstance):
|
if isinstance(self.entity_data.spec, MIoTSpecInstance):
|
||||||
self.entity_id = miot_device.gen_device_entity_id(DOMAIN)
|
self.entity_id = miot_device.gen_device_entity_id(DOMAIN)
|
||||||
self._attr_name = f' {self.entity_data.spec.description_trans}'
|
self._attr_name = f' {self.entity_data.spec.description_trans}'
|
||||||
elif isinstance(entity_data.spec, MIoTSpecService):
|
elif isinstance(self.entity_data.spec, MIoTSpecService):
|
||||||
self.entity_id = miot_device.gen_service_entity_id(
|
self.entity_id = miot_device.gen_service_entity_id(
|
||||||
DOMAIN, siid=entity_data.spec.iid)
|
DOMAIN, siid=self.entity_data.spec.iid)
|
||||||
self._attr_name = (
|
self._attr_name = (
|
||||||
f'{"* "if self.entity_data.spec.proprietary else " "}'
|
f'{"* "if self.entity_data.spec.proprietary else " "}'
|
||||||
f'{self.entity_data.spec.description_trans}')
|
f'{self.entity_data.spec.description_trans}')
|
||||||
@ -1277,8 +1282,8 @@ class MIoTEventEntity(Entity):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def on_event_occurred(
|
def on_event_occurred(
|
||||||
self, name: str, arguments: list[dict[int, Any]]
|
self, name: str, arguments: dict[str, Any] | None = None
|
||||||
): ...
|
) -> None: ...
|
||||||
|
|
||||||
def __on_event_occurred(self, params: dict, ctx: Any) -> None:
|
def __on_event_occurred(self, params: dict, ctx: Any) -> None:
|
||||||
_LOGGER.debug('event occurred, %s', params)
|
_LOGGER.debug('event occurred, %s', params)
|
||||||
|
|||||||
@ -465,7 +465,7 @@ class _MIoTSpecBase:
|
|||||||
iid: int
|
iid: int
|
||||||
type_: str
|
type_: str
|
||||||
description: str
|
description: str
|
||||||
description_trans: Optional[str]
|
description_trans: str
|
||||||
proprietary: bool
|
proprietary: bool
|
||||||
need_filter: bool
|
need_filter: bool
|
||||||
name: str
|
name: str
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user