mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-19 00:20:44 +08:00
feat: update action debug logic
This commit is contained in:
parent
6b49d07140
commit
93905a10ee
@ -209,12 +209,7 @@ async def async_setup_entry(
|
|||||||
if er.async_get(entity_id_or_uuid=entity_id):
|
if er.async_get(entity_id_or_uuid=entity_id):
|
||||||
er.async_remove(entity_id=entity_id)
|
er.async_remove(entity_id=entity_id)
|
||||||
# Action debug
|
# Action debug
|
||||||
if miot_client.action_debug:
|
if not miot_client.action_debug:
|
||||||
if 'notify' in device.action_list:
|
|
||||||
# Add text entity for debug action
|
|
||||||
device.action_list['action_text'] = (
|
|
||||||
device.action_list['notify'])
|
|
||||||
else:
|
|
||||||
# Remove text entity for debug action
|
# Remove text entity for debug action
|
||||||
for action in device.action_list.get('notify', []):
|
for action in device.action_list.get('notify', []):
|
||||||
entity_id = device.gen_action_entity_id(
|
entity_id = device.gen_action_entity_id(
|
||||||
@ -223,6 +218,8 @@ async def async_setup_entry(
|
|||||||
if er.async_get(entity_id_or_uuid=entity_id):
|
if er.async_get(entity_id_or_uuid=entity_id):
|
||||||
er.async_remove(entity_id=entity_id)
|
er.async_remove(entity_id=entity_id)
|
||||||
|
|
||||||
|
# Binary sensor display
|
||||||
|
|
||||||
hass.data[DOMAIN]['devices'][config_entry.entry_id] = miot_devices
|
hass.data[DOMAIN]['devices'][config_entry.entry_id] = miot_devices
|
||||||
await hass.config_entries.async_forward_entry_setups(
|
await hass.config_entries.async_forward_entry_setups(
|
||||||
config_entry, SUPPORTED_PLATFORMS)
|
config_entry, SUPPORTED_PLATFORMS)
|
||||||
|
|||||||
@ -1325,7 +1325,6 @@ class MIoTActionEntity(Entity):
|
|||||||
miot_device: MIoTDevice
|
miot_device: MIoTDevice
|
||||||
spec: MIoTSpecAction
|
spec: MIoTSpecAction
|
||||||
service: MIoTSpecService
|
service: MIoTSpecService
|
||||||
action_platform: str
|
|
||||||
|
|
||||||
_main_loop: asyncio.AbstractEventLoop
|
_main_loop: asyncio.AbstractEventLoop
|
||||||
_in_map: dict[int, MIoTSpecProperty]
|
_in_map: dict[int, MIoTSpecProperty]
|
||||||
@ -1338,7 +1337,6 @@ class MIoTActionEntity(Entity):
|
|||||||
self.miot_device = miot_device
|
self.miot_device = miot_device
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
self.service = spec.service
|
self.service = spec.service
|
||||||
self.action_platform = 'action'
|
|
||||||
self._main_loop = miot_device.miot_client.main_loop
|
self._main_loop = miot_device.miot_client.main_loop
|
||||||
self._state_sub_id = 0
|
self._state_sub_id = 0
|
||||||
# Gen entity_id
|
# Gen entity_id
|
||||||
@ -1365,12 +1363,12 @@ class MIoTActionEntity(Entity):
|
|||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
self._state_sub_id = self.miot_device.sub_device_state(
|
self._state_sub_id = self.miot_device.sub_device_state(
|
||||||
key=f'{self.action_platform}.{ self.service.iid}.{self.spec.iid}',
|
key=f'a.{ self.service.iid}.{self.spec.iid}',
|
||||||
handler=self.__on_device_state_changed)
|
handler=self.__on_device_state_changed)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
self.miot_device.unsub_device_state(
|
self.miot_device.unsub_device_state(
|
||||||
key=f'{self.action_platform}.{ self.service.iid}.{self.spec.iid}',
|
key=f'a.{ self.service.iid}.{self.spec.iid}',
|
||||||
sub_id=self._state_sub_id)
|
sub_id=self._state_sub_id)
|
||||||
|
|
||||||
async def action_async(
|
async def action_async(
|
||||||
|
|||||||
@ -76,9 +76,10 @@ async def async_setup_entry(
|
|||||||
for prop in miot_device.prop_list.get('text', []):
|
for prop in miot_device.prop_list.get('text', []):
|
||||||
new_entities.append(Text(miot_device=miot_device, spec=prop))
|
new_entities.append(Text(miot_device=miot_device, spec=prop))
|
||||||
|
|
||||||
for action in miot_device.action_list.get('action_text', []):
|
if miot_device.miot_client.action_debug:
|
||||||
new_entities.append(ActionText(
|
for action in miot_device.action_list.get('notify', []):
|
||||||
miot_device=miot_device, spec=action))
|
new_entities.append(ActionText(
|
||||||
|
miot_device=miot_device, spec=action))
|
||||||
|
|
||||||
if new_entities:
|
if new_entities:
|
||||||
async_add_entities(new_entities)
|
async_add_entities(new_entities)
|
||||||
@ -114,8 +115,6 @@ class ActionText(MIoTActionEntity, TextEntity):
|
|||||||
f'{prop.description_trans}({prop.format_.__name__})'
|
f'{prop.description_trans}({prop.format_.__name__})'
|
||||||
for prop in self.spec.in_])
|
for prop in self.spec.in_])
|
||||||
self._attr_extra_state_attributes['action params'] = f'[{action_in}]'
|
self._attr_extra_state_attributes['action params'] = f'[{action_in}]'
|
||||||
# For action debug
|
|
||||||
self.action_platform = 'action_text'
|
|
||||||
|
|
||||||
async def async_set_value(self, value: str) -> None:
|
async def async_set_value(self, value: str) -> None:
|
||||||
if not value:
|
if not value:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user