Added new sensors
###Feature * Added new sensors, binary sensor awake, is on if baby awake, off otherwise. Sensor sleep state, shows baby sleep state, options are awake, light sleep, deep sleep
This commit is contained in:
@@ -32,7 +32,7 @@ This integration provides the following entities:
|
||||
|
||||
## Options
|
||||
|
||||
- Seconds between polling - Number of seconds between each call for data from the owlet cloud service, default is 10 seconds.
|
||||
- Seconds between polling - Number of seconds between each call for data from the owlet cloud service, default is 5 seconds.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -86,6 +86,12 @@ SENSORS: tuple[OwletBinarySensorEntityDescription, ...] = (
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
element="sock_off",
|
||||
),
|
||||
OwletBinarySensorEntityDescription(
|
||||
key="awake",
|
||||
name="Awake",
|
||||
element="sleep_state",
|
||||
icon="mdi:sleep",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -119,4 +125,14 @@ class OwletBinarySensor(OwletBaseEntity, BinarySensorEntity):
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the binary sensor is on."""
|
||||
return self.sock.properties[self.entity_description.element]
|
||||
state = self.sock.properties[self.entity_description.element]
|
||||
|
||||
if self.entity_description.element == "sleep_state":
|
||||
if self.sock.properties["charging"]:
|
||||
return None
|
||||
if state in [8, 15]:
|
||||
state = False
|
||||
else:
|
||||
state = True
|
||||
|
||||
return state
|
||||
|
||||
@@ -8,3 +8,4 @@ CONF_OWLET_REFRESH = "refresh"
|
||||
SUPPORTED_VERSIONS = [3]
|
||||
POLLING_INTERVAL = 5
|
||||
MANUFACTURER = "Owlet Baby Care"
|
||||
SLEEP_STATES = {1, "Awake", 8, "Light Sleep", 15, "Deep Sleep"}
|
||||
|
||||
@@ -12,5 +12,5 @@
|
||||
"requirements": [
|
||||
"pyowletapi==2023.5.23"
|
||||
],
|
||||
"version":"2023.5.1"
|
||||
"version":"2023.5.2"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ from homeassistant.const import (
|
||||
UnitOfTemperature,
|
||||
)
|
||||
|
||||
from .const import DOMAIN
|
||||
from .const import DOMAIN, SLEEP_STATES
|
||||
from .coordinator import OwletCoordinator
|
||||
from .entity import OwletBaseEntity
|
||||
|
||||
@@ -107,6 +107,7 @@ async def async_setup_entry(
|
||||
coordinator: OwletCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities = [OwletSensor(coordinator, sensor) for sensor in SENSORS]
|
||||
entities.append(OwletSleepStateSensor(coordinator))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
@@ -142,3 +143,31 @@ class OwletSensor(OwletBaseEntity, SensorEntity):
|
||||
return None
|
||||
|
||||
return self.sock.properties[self.entity_description.element]
|
||||
|
||||
|
||||
class OwletSleepStateSensor(OwletBaseEntity, SensorEntity):
|
||||
"""Representation of an Owlet sleep state sensor."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: OwletCoordinator,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self._attr_unique_id = f"{self.sock.serial}-Sleep State"
|
||||
self._attr_icon = "mdi:sleep"
|
||||
self._attr_device_class = SensorDeviceClass.ENUM
|
||||
self._attr_translation_key = "sleepstate"
|
||||
self._attr_name = "Sleep State"
|
||||
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Return sensor value"""
|
||||
if self.sock.properties["charging"]:
|
||||
return None
|
||||
|
||||
return SLEEP_STATES[self.sock.properties["sleep_state"]]
|
||||
|
||||
@property
|
||||
def options(self) -> list[str]:
|
||||
return ["Awake", "Light Sleep", "Deep Sleep"]
|
||||
|
||||
@@ -19,8 +19,6 @@ If you have a smart sock 2 and would like to contribute then please do so.
|
||||
3. Hard refresh browser cache.
|
||||
4. [![Add Integration][add-integration-badge]][add-integration] or in the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Owlet Smart Sock".
|
||||
|
||||
{% endif %}
|
||||
|
||||
<!---->
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user