1 """WiZ integration binary sensor platform."""
3 from __future__
import annotations
5 from collections.abc
import Callable
7 from pywizlight.bulb
import PIR_SOURCE
10 BinarySensorDeviceClass,
19 from .
import WizConfigEntry
20 from .const
import DOMAIN, SIGNAL_WIZ_PIR
21 from .entity
import WizEntity
22 from .models
import WizData
24 OCCUPANCY_UNIQUE_ID =
"{}_occupancy"
29 entry: WizConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up the WiZ binary sensor platform."""
33 mac = entry.runtime_data.bulb.mac
35 if er.async_get(hass).async_get_entity_id(
36 Platform.BINARY_SENSOR, DOMAIN, OCCUPANCY_UNIQUE_ID.format(mac)
41 cancel_dispatcher: Callable[[],
None] |
None =
None
44 def _async_add_occupancy_sensor() -> None:
45 nonlocal cancel_dispatcher
46 assert cancel_dispatcher
is not None
48 cancel_dispatcher =
None
52 hass, SIGNAL_WIZ_PIR.format(mac), _async_add_occupancy_sensor
56 def _async_cancel_dispatcher() -> None:
57 nonlocal cancel_dispatcher
58 if cancel_dispatcher
is not None:
60 cancel_dispatcher =
None
62 entry.async_on_unload(_async_cancel_dispatcher)
66 """Representation of WiZ Occupancy sensor."""
68 _attr_device_class = BinarySensorDeviceClass.OCCUPANCY
70 def __init__(self, wiz_data: WizData, name: str) ->
None:
71 """Initialize an WiZ device."""
78 """Handle updating _attr values."""
79 if self.
_device_device.state.get_source() == PIR_SOURCE:
None __init__(self, WizData wiz_data, str name)
None _async_update_attrs(self)
None _async_update_attrs(self)
None async_setup_entry(HomeAssistant hass, WizConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)