1 """Sensors flow for Withings."""
3 from __future__
import annotations
5 from collections.abc
import Callable
8 BinarySensorDeviceClass,
16 from .
import WithingsConfigEntry
17 from .const
import DOMAIN
18 from .coordinator
import WithingsBedPresenceDataUpdateCoordinator
19 from .entity
import WithingsEntity
24 entry: WithingsConfigEntry,
25 async_add_entities: AddEntitiesCallback,
27 """Set up the sensor config entry."""
28 coordinator = entry.runtime_data.bed_presence_coordinator
30 ent_reg = er.async_get(hass)
32 callback: Callable[[],
None] |
None =
None
34 def _async_add_bed_presence_entity() -> None:
35 """Add bed presence entity."""
40 if ent_reg.async_get_entity_id(
41 Platform.BINARY_SENSOR, DOMAIN, f
"withings_{entry.unique_id}_in_bed"
43 _async_add_bed_presence_entity()
45 callback = coordinator.async_add_listener(_async_add_bed_presence_entity)
49 """Implementation of a Withings sensor."""
51 _attr_translation_key =
"in_bed"
52 _attr_device_class = BinarySensorDeviceClass.OCCUPANCY
53 coordinator: WithingsBedPresenceDataUpdateCoordinator
55 def __init__(self, coordinator: WithingsBedPresenceDataUpdateCoordinator) ->
None:
56 """Initialize binary sensor."""
57 super().
__init__(coordinator,
"in_bed")
61 """Return true if the binary sensor is on."""
62 return self.coordinator.in_bed
None __init__(self, WithingsBedPresenceDataUpdateCoordinator coordinator)
None async_setup_entry(HomeAssistant hass, WithingsConfigEntry entry, AddEntitiesCallback async_add_entities)