mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-16 06:30:44 +08:00
feat: support binary mode
This commit is contained in:
parent
37a446f2d1
commit
14766466ca
@ -217,8 +217,21 @@ async def async_setup_entry(
|
||||
siid=action.service.iid, aiid=action.iid)
|
||||
if er.async_get(entity_id_or_uuid=entity_id):
|
||||
er.async_remove(entity_id=entity_id)
|
||||
|
||||
# Binary sensor display
|
||||
if not miot_client.display_binary_bool:
|
||||
for prop in device.prop_list.get('binary_sensor', []):
|
||||
entity_id = device.gen_prop_entity_id(
|
||||
ha_domain='binary_sensor', spec_name=prop.name,
|
||||
siid=prop.service.iid, piid=prop.iid)
|
||||
if er.async_get(entity_id_or_uuid=entity_id):
|
||||
er.async_remove(entity_id=entity_id)
|
||||
if not miot_client.display_binary_text:
|
||||
for prop in device.prop_list.get('binary_sensor', []):
|
||||
entity_id = device.gen_prop_entity_id(
|
||||
ha_domain='sensor', spec_name=prop.name,
|
||||
siid=prop.service.iid, piid=prop.iid)
|
||||
if er.async_get(entity_id_or_uuid=entity_id):
|
||||
er.async_remove(entity_id=entity_id)
|
||||
|
||||
hass.data[DOMAIN]['devices'][config_entry.entry_id] = miot_devices
|
||||
await hass.config_entries.async_forward_entry_setups(
|
||||
|
||||
@ -68,9 +68,10 @@ async def async_setup_entry(
|
||||
|
||||
new_entities = []
|
||||
for miot_device in device_list:
|
||||
for prop in miot_device.prop_list.get('binary_sensor', []):
|
||||
new_entities.append(BinarySensor(
|
||||
miot_device=miot_device, spec=prop))
|
||||
if miot_device.miot_client.display_binary_bool:
|
||||
for prop in miot_device.prop_list.get('binary_sensor', []):
|
||||
new_entities.append(BinarySensor(
|
||||
miot_device=miot_device, spec=prop))
|
||||
|
||||
if new_entities:
|
||||
async_add_entities(new_entities)
|
||||
|
||||
@ -169,6 +169,8 @@ class MIoTClient:
|
||||
_show_devices_changed_notify_timer: Optional[asyncio.TimerHandle]
|
||||
# Display devices changed notify
|
||||
_display_devs_notify: list[str]
|
||||
_display_binary_text: bool
|
||||
_display_binary_bool: bool
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@ -235,6 +237,10 @@ class MIoTClient:
|
||||
|
||||
self._display_devs_notify = entry_data.get(
|
||||
'display_devices_changed_notify', ['add', 'del', 'offline'])
|
||||
self._display_binary_text = 'text' in entry_data.get(
|
||||
'display_binary_mode', ['text'])
|
||||
self._display_binary_bool = 'bool' in entry_data.get(
|
||||
'display_binary_mode', ['text'])
|
||||
|
||||
async def init_async(self) -> None:
|
||||
# Load user config and check
|
||||
@ -469,6 +475,14 @@ class MIoTClient:
|
||||
def display_devices_changed_notify(self) -> list[str]:
|
||||
return self._display_devs_notify
|
||||
|
||||
@property
|
||||
def display_binary_text(self) -> bool:
|
||||
return self._display_binary_text
|
||||
|
||||
@property
|
||||
def display_binary_bool(self) -> bool:
|
||||
return self._display_binary_bool
|
||||
|
||||
@display_devices_changed_notify.setter
|
||||
def display_devices_changed_notify(self, value: list[str]) -> None:
|
||||
if set(value) == set(self._display_devs_notify):
|
||||
|
||||
@ -76,6 +76,12 @@ async def async_setup_entry(
|
||||
for prop in miot_device.prop_list.get('sensor', []):
|
||||
new_entities.append(Sensor(miot_device=miot_device, spec=prop))
|
||||
|
||||
if miot_device.miot_client.display_binary_text:
|
||||
for prop in miot_device.prop_list.get('binary_sensor', []):
|
||||
if not prop.value_list:
|
||||
continue
|
||||
new_entities.append(Sensor(miot_device=miot_device, spec=prop))
|
||||
|
||||
if new_entities:
|
||||
async_add_entities(new_entities)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user