Add POD support, sleep fitness sensor to EightSleep (#31874)
* Add POD support, sleep fitness sensor * Black format changes * Change dict formatting
This commit is contained in:
parent
b77f2670a7
commit
164e970ba0
5 changed files with 43 additions and 11 deletions
|
@ -43,12 +43,14 @@ SIGNAL_UPDATE_USER = "eight_user_update"
|
||||||
|
|
||||||
NAME_MAP = {
|
NAME_MAP = {
|
||||||
"left_current_sleep": "Left Sleep Session",
|
"left_current_sleep": "Left Sleep Session",
|
||||||
|
"left_current_sleep_fitness": "Left Sleep Fitness",
|
||||||
"left_last_sleep": "Left Previous Sleep Session",
|
"left_last_sleep": "Left Previous Sleep Session",
|
||||||
"left_bed_state": "Left Bed State",
|
"left_bed_state": "Left Bed State",
|
||||||
"left_presence": "Left Bed Presence",
|
"left_presence": "Left Bed Presence",
|
||||||
"left_bed_temp": "Left Bed Temperature",
|
"left_bed_temp": "Left Bed Temperature",
|
||||||
"left_sleep_stage": "Left Sleep Stage",
|
"left_sleep_stage": "Left Sleep Stage",
|
||||||
"right_current_sleep": "Right Sleep Session",
|
"right_current_sleep": "Right Sleep Session",
|
||||||
|
"right_current_sleep_fitness": "Right Sleep Fitness",
|
||||||
"right_last_sleep": "Right Previous Sleep Session",
|
"right_last_sleep": "Right Previous Sleep Session",
|
||||||
"right_bed_state": "Right Bed State",
|
"right_bed_state": "Right Bed State",
|
||||||
"right_presence": "Right Bed Presence",
|
"right_presence": "Right Bed Presence",
|
||||||
|
@ -57,14 +59,21 @@ NAME_MAP = {
|
||||||
"room_temp": "Room Temperature",
|
"room_temp": "Room Temperature",
|
||||||
}
|
}
|
||||||
|
|
||||||
SENSORS = ["current_sleep", "last_sleep", "bed_state", "bed_temp", "sleep_stage"]
|
SENSORS = [
|
||||||
|
"current_sleep",
|
||||||
|
"current_sleep_fitness",
|
||||||
|
"last_sleep",
|
||||||
|
"bed_state",
|
||||||
|
"bed_temp",
|
||||||
|
"sleep_stage",
|
||||||
|
]
|
||||||
|
|
||||||
SERVICE_HEAT_SET = "heat_set"
|
SERVICE_HEAT_SET = "heat_set"
|
||||||
|
|
||||||
ATTR_TARGET_HEAT = "target"
|
ATTR_TARGET_HEAT = "target"
|
||||||
ATTR_HEAT_DURATION = "duration"
|
ATTR_HEAT_DURATION = "duration"
|
||||||
|
|
||||||
VALID_TARGET_HEAT = vol.All(vol.Coerce(int), vol.Clamp(min=0, max=100))
|
VALID_TARGET_HEAT = vol.All(vol.Coerce(int), vol.Clamp(min=-100, max=100))
|
||||||
VALID_DURATION = vol.All(vol.Coerce(int), vol.Clamp(min=0, max=28800))
|
VALID_DURATION = vol.All(vol.Coerce(int), vol.Clamp(min=0, max=28800))
|
||||||
|
|
||||||
SERVICE_EIGHT_SCHEMA = vol.Schema(
|
SERVICE_EIGHT_SCHEMA = vol.Schema(
|
||||||
|
@ -101,7 +110,7 @@ async def async_setup(hass, config):
|
||||||
_LOGGER.error("Timezone is not set in Home Assistant.")
|
_LOGGER.error("Timezone is not set in Home Assistant.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
timezone = hass.config.time_zone
|
timezone = str(hass.config.time_zone)
|
||||||
|
|
||||||
eight = EightSleep(user, password, timezone, partner, None, hass.loop)
|
eight = EightSleep(user, password, timezone, partner, None, hass.loop)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"domain": "eight_sleep",
|
"domain": "eight_sleep",
|
||||||
"name": "Eight Sleep",
|
"name": "Eight Sleep",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/eight_sleep",
|
"documentation": "https://www.home-assistant.io/integrations/eight_sleep",
|
||||||
"requirements": ["pyeight==0.1.2"],
|
"requirements": ["pyeight==0.1.3"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@mezz64"]
|
"codeowners": ["@mezz64"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,11 @@ ATTR_ACTIVE_HEAT = "Heating Active"
|
||||||
ATTR_DURATION_HEAT = "Heating Time Remaining"
|
ATTR_DURATION_HEAT = "Heating Time Remaining"
|
||||||
ATTR_PROCESSING = "Processing"
|
ATTR_PROCESSING = "Processing"
|
||||||
ATTR_SESSION_START = "Session Start"
|
ATTR_SESSION_START = "Session Start"
|
||||||
|
ATTR_FIT_DATE = "Fitness Date"
|
||||||
|
ATTR_FIT_DURATION_SCORE = "Fitness Duration Score"
|
||||||
|
ATTR_FIT_ASLEEP_SCORE = "Fitness Asleep Score"
|
||||||
|
ATTR_FIT_OUT_SCORE = "Fitness Out-of-Bed Score"
|
||||||
|
ATTR_FIT_WAKEUP_SCORE = "Fitness Wakeup Score"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -151,7 +156,11 @@ class EightUserSensor(EightSleepUserEntity):
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit the value is expressed in."""
|
"""Return the unit the value is expressed in."""
|
||||||
if "current_sleep" in self._sensor or "last_sleep" in self._sensor:
|
if (
|
||||||
|
"current_sleep" in self._sensor
|
||||||
|
or "last_sleep" in self._sensor
|
||||||
|
or "current_sleep_fitness" in self._sensor
|
||||||
|
):
|
||||||
return "Score"
|
return "Score"
|
||||||
if "bed_temp" in self._sensor:
|
if "bed_temp" in self._sensor:
|
||||||
if self._units == "si":
|
if self._units == "si":
|
||||||
|
@ -169,8 +178,12 @@ class EightUserSensor(EightSleepUserEntity):
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
_LOGGER.debug("Updating User sensor: %s", self._sensor)
|
_LOGGER.debug("Updating User sensor: %s", self._sensor)
|
||||||
if "current" in self._sensor:
|
if "current" in self._sensor:
|
||||||
self._state = self._usrobj.current_sleep_score
|
if "fitness" in self._sensor:
|
||||||
self._attr = self._usrobj.current_values
|
self._state = self._usrobj.current_sleep_fitness_score
|
||||||
|
self._attr = self._usrobj.current_fitness_values
|
||||||
|
else:
|
||||||
|
self._state = self._usrobj.current_sleep_score
|
||||||
|
self._attr = self._usrobj.current_values
|
||||||
elif "last" in self._sensor:
|
elif "last" in self._sensor:
|
||||||
self._state = self._usrobj.last_sleep_score
|
self._state = self._usrobj.last_sleep_score
|
||||||
self._attr = self._usrobj.last_values
|
self._attr = self._usrobj.last_values
|
||||||
|
@ -193,6 +206,16 @@ class EightUserSensor(EightSleepUserEntity):
|
||||||
# Skip attributes if sensor type doesn't support
|
# Skip attributes if sensor type doesn't support
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if "fitness" in self._sensor_root:
|
||||||
|
state_attr = {
|
||||||
|
ATTR_FIT_DATE: self._attr["date"],
|
||||||
|
ATTR_FIT_DURATION_SCORE: self._attr["duration"],
|
||||||
|
ATTR_FIT_ASLEEP_SCORE: self._attr["asleep"],
|
||||||
|
ATTR_FIT_OUT_SCORE: self._attr["out"],
|
||||||
|
ATTR_FIT_WAKEUP_SCORE: self._attr["wakeup"],
|
||||||
|
}
|
||||||
|
return state_attr
|
||||||
|
|
||||||
state_attr = {ATTR_SESSION_START: self._attr["date"]}
|
state_attr = {ATTR_SESSION_START: self._attr["date"]}
|
||||||
state_attr[ATTR_TNT] = self._attr["tnt"]
|
state_attr[ATTR_TNT] = self._attr["tnt"]
|
||||||
state_attr[ATTR_PROCESSING] = self._attr["processing"]
|
state_attr[ATTR_PROCESSING] = self._attr["processing"]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
heat_set:
|
heat_set:
|
||||||
description: Set heating level for eight sleep.
|
description: Set heating/cooling level for eight sleep.
|
||||||
fields:
|
fields:
|
||||||
duration: {description: Duration to heat at the target level in seconds., example: 3600}
|
duration: {description: Duration to heat/cool at the target level in seconds., example: 3600}
|
||||||
entity_id: {description: Entity id of the bed state to adjust., example: sensor.eight_left_bed_state}
|
entity_id: {description: Entity id of the bed state to adjust., example: sensor.eight_left_bed_state}
|
||||||
target: {description: Target heating level from 0-100., example: 35}
|
target: {description: Target cooling/heating level from -100 to 100., example: 35}
|
||||||
|
|
|
@ -1226,7 +1226,7 @@ pyeconet==0.0.11
|
||||||
pyedimax==0.2.1
|
pyedimax==0.2.1
|
||||||
|
|
||||||
# homeassistant.components.eight_sleep
|
# homeassistant.components.eight_sleep
|
||||||
pyeight==0.1.2
|
pyeight==0.1.3
|
||||||
|
|
||||||
# homeassistant.components.emby
|
# homeassistant.components.emby
|
||||||
pyemby==1.6
|
pyemby==1.6
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue