mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Address late review of eight_sleep (#60951)
This commit is contained in:
parent
6d6e0dd8bf
commit
267896cfc0
@ -96,7 +96,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
)
|
||||
|
||||
|
||||
def _get_device_unique_id(eight: EightSleep, user_obj: EightUser = None) -> str:
|
||||
def _get_device_unique_id(eight: EightSleep, user_obj: EightUser | None = None) -> str:
|
||||
"""Get the device's unique ID."""
|
||||
unique_id = eight.deviceid
|
||||
if user_obj:
|
||||
@ -199,7 +199,6 @@ class EightSleepHeatDataCoordinator(DataUpdateCoordinator):
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN}_heat",
|
||||
update_interval=HEAT_SCAN_INTERVAL,
|
||||
update_method=self._async_update_data,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> None:
|
||||
@ -217,7 +216,6 @@ class EightSleepUserDataCoordinator(DataUpdateCoordinator):
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN}_user",
|
||||
update_interval=USER_SCAN_INTERVAL,
|
||||
update_method=self._async_update_data,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> None:
|
||||
@ -240,7 +238,7 @@ class EightSleepBaseEntity(CoordinatorEntity):
|
||||
self._eight = eight
|
||||
self._side = side
|
||||
self._sensor = sensor
|
||||
self._usrobj: EightUser = None
|
||||
self._usrobj: EightUser | None = None
|
||||
if self._side:
|
||||
self._usrobj = self._eight.users[self._eight.fetch_userid(self._side)]
|
||||
full_sensor_name = self._sensor
|
||||
|
@ -62,7 +62,7 @@ class EightHeatSensor(EightSleepBaseEntity, BinarySensorEntity):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(name, coordinator, eight, side, sensor)
|
||||
self._attr_device_class = DEVICE_CLASS_OCCUPANCY
|
||||
|
||||
assert self._usrobj
|
||||
_LOGGER.debug(
|
||||
"Presence Sensor: %s, Side: %s, User: %s",
|
||||
self._sensor,
|
||||
@ -73,4 +73,5 @@ class EightHeatSensor(EightSleepBaseEntity, BinarySensorEntity):
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the binary sensor is on."""
|
||||
assert self._usrobj
|
||||
return bool(self._usrobj.bed_presence)
|
||||
|
@ -106,6 +106,7 @@ class EightHeatSensor(EightSleepBaseEntity, SensorEntity):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(name, coordinator, eight, side, sensor)
|
||||
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||
assert self._usrobj
|
||||
|
||||
_LOGGER.debug(
|
||||
"Heat Sensor: %s, Side: %s, User: %s",
|
||||
@ -117,11 +118,13 @@ class EightHeatSensor(EightSleepBaseEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
assert self._usrobj
|
||||
return self._usrobj.heating_level
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
"""Return device state attributes."""
|
||||
assert self._usrobj
|
||||
return {
|
||||
ATTR_TARGET_HEAT: self._usrobj.target_heating_level,
|
||||
ATTR_ACTIVE_HEAT: self._usrobj.now_heating,
|
||||
@ -167,6 +170,9 @@ class EightUserSensor(EightSleepUserEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self) -> str | int | float | None:
|
||||
"""Return the state of the sensor."""
|
||||
if not self._usrobj:
|
||||
return None
|
||||
|
||||
if "current" in self._sensor:
|
||||
if "fitness" in self._sensor:
|
||||
return self._usrobj.current_sleep_fitness_score
|
||||
@ -215,12 +221,12 @@ class EightUserSensor(EightSleepUserEntity, SensorEntity):
|
||||
def extra_state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return device state attributes."""
|
||||
attr = None
|
||||
if "current" in self._sensor:
|
||||
if "current" in self._sensor and self._usrobj:
|
||||
if "fitness" in self._sensor:
|
||||
attr = self._usrobj.current_fitness_values
|
||||
else:
|
||||
attr = self._usrobj.current_values
|
||||
elif "last" in self._sensor:
|
||||
elif "last" in self._sensor and self._usrobj:
|
||||
attr = self._usrobj.last_values
|
||||
|
||||
if attr is None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user