1 """Entity for the SleepIQ integration."""
3 from abc
import abstractmethod
5 from asyncsleepiq
import SleepIQBed, SleepIQSleeper
13 from .const
import ENTITY_TYPES, ICON_OCCUPIED
14 from .coordinator
import SleepIQDataUpdateCoordinator, SleepIQPauseUpdateCoordinator
16 type _DataCoordinatorType = SleepIQDataUpdateCoordinator | SleepIQPauseUpdateCoordinator
20 """Create a device given a bed."""
22 connections={(dr.CONNECTION_NETWORK_MAC, bed.mac_addr)},
23 manufacturer=
"SleepNumber",
30 """Find the sleeper for a side or the first sleeper."""
31 for sleeper
in bed.sleepers:
32 if sleeper.side == side:
34 return bed.sleepers[0]
38 """Implementation of a SleepIQ entity."""
41 """Initialize the SleepIQ entity."""
47 CoordinatorEntity[_SleepIQCoordinatorT]
49 """Implementation of a SleepIQ sensor."""
51 _attr_icon = ICON_OCCUPIED
55 coordinator: _SleepIQCoordinatorT,
58 """Initialize the SleepIQ sensor entity."""
62 self._async_update_attrs()
66 """Handle updated data from the coordinator."""
67 self._async_update_attrs()
73 """Update sensor attributes."""
76 class SleepIQSleeperEntity[_SleepIQCoordinatorT: _DataCoordinatorType](
77 SleepIQBedEntity[_SleepIQCoordinatorT]
79 """Implementation of a SleepIQ sensor."""
81 _attr_icon = ICON_OCCUPIED
85 coordinator: _SleepIQCoordinatorT,
87 sleeper: SleepIQSleeper,
90 """Initialize the SleepIQ sensor entity."""
91 self.sleeper = sleeper
94 self._attr_name = f
"SleepNumber {bed.name} {sleeper.name} {ENTITY_TYPES[name]}"
95 self._attr_unique_id = f
"{sleeper.sleeper_id}_{name}"
None __init__(self, SleepIQBed bed)
SleepIQSleeper sleeper_for_side(SleepIQBed bed, str side)
None __init__(self, _SleepIQCoordinatorT coordinator, SleepIQBed bed)
None _async_update_attrs(self)
None _handle_coordinator_update(self)
DeviceInfo device_from_bed(SleepIQBed bed)