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