1 """Support for ONVIF binary sensors."""
3 from __future__
import annotations
5 from datetime
import date, datetime
6 from decimal
import Decimal
16 from .const
import DOMAIN
17 from .device
import ONVIFDevice
18 from .entity
import ONVIFBaseEntity
23 config_entry: ConfigEntry,
24 async_add_entities: AddEntitiesCallback,
26 """Set up a ONVIF binary sensor."""
27 device: ONVIFDevice = hass.data[DOMAIN][config_entry.unique_id]
31 for event
in device.events.get_platform(
"sensor")
34 ent_reg = er.async_get(hass)
35 for entry
in er.async_entries_for_config_entry(ent_reg, config_entry.entry_id):
36 if entry.domain ==
"sensor" and entry.unique_id
not in entities:
37 entities[entry.unique_id] =
ONVIFSensor(entry.unique_id, device, entry)
40 uids_by_platform = device.events.get_uids_by_platform(
"sensor")
43 def async_check_entities() -> None:
44 """Check if we have added an entity for the event."""
45 nonlocal uids_by_platform
46 if not (missing := uids_by_platform.difference(entities)):
48 new_entities: dict[str, ONVIFSensor] = {
52 entities.update(new_entities)
55 device.events.async_add_listener(async_check_entities)
59 """Representation of a ONVIF sensor event."""
61 _attr_should_poll =
False
64 self, uid, device: ONVIFDevice, entry: er.RegistryEntry |
None =
None
66 """Initialize the ONVIF binary sensor."""
70 SensorDeviceClass, entry.original_device_class
76 event = device.events.get_uid(uid)
79 SensorDeviceClass, event.device_class
83 self.
_attr_name_attr_name = f
"{device.name} {event.name}"
91 """Return the value reported by the sensor."""
93 if (event := self.device.events.get_uid(self.
_attr_unique_id_attr_unique_id))
is not None:
98 """Connect to dispatcher listening for entity data notifications."""
_attr_entity_registry_enabled_default
StateType|date|datetime|Decimal native_value(self)
None async_added_to_hass(self)
_attr_native_unit_of_measurement
None __init__(self, uid, ONVIFDevice device, er.RegistryEntry|None entry=None)
SensorExtraStoredData|None async_get_last_sensor_data(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)