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:
RyanClark123
2023-05-16 15:06:01 +01:00
parent dc710a1783
commit 9b3392bdbc
6 changed files with 50 additions and 6 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ This integration provides the following entities:
## Options ## 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.
--- ---
+17 -1
View File
@@ -86,6 +86,12 @@ SENSORS: tuple[OwletBinarySensorEntityDescription, ...] = (
device_class=BinarySensorDeviceClass.POWER, device_class=BinarySensorDeviceClass.POWER,
element="sock_off", element="sock_off",
), ),
OwletBinarySensorEntityDescription(
key="awake",
name="Awake",
element="sleep_state",
icon="mdi:sleep",
),
) )
@@ -119,4 +125,14 @@ class OwletBinarySensor(OwletBaseEntity, 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."""
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
+1
View File
@@ -8,3 +8,4 @@ CONF_OWLET_REFRESH = "refresh"
SUPPORTED_VERSIONS = [3] SUPPORTED_VERSIONS = [3]
POLLING_INTERVAL = 5 POLLING_INTERVAL = 5
MANUFACTURER = "Owlet Baby Care" MANUFACTURER = "Owlet Baby Care"
SLEEP_STATES = {1, "Awake", 8, "Light Sleep", 15, "Deep Sleep"}
+1 -1
View File
@@ -12,5 +12,5 @@
"requirements": [ "requirements": [
"pyowletapi==2023.5.23" "pyowletapi==2023.5.23"
], ],
"version":"2023.5.1" "version":"2023.5.2"
} }
+30 -1
View File
@@ -18,7 +18,7 @@ from homeassistant.const import (
UnitOfTemperature, UnitOfTemperature,
) )
from .const import DOMAIN from .const import DOMAIN, SLEEP_STATES
from .coordinator import OwletCoordinator from .coordinator import OwletCoordinator
from .entity import OwletBaseEntity from .entity import OwletBaseEntity
@@ -107,6 +107,7 @@ async def async_setup_entry(
coordinator: OwletCoordinator = hass.data[DOMAIN][config_entry.entry_id] coordinator: OwletCoordinator = hass.data[DOMAIN][config_entry.entry_id]
entities = [OwletSensor(coordinator, sensor) for sensor in SENSORS] entities = [OwletSensor(coordinator, sensor) for sensor in SENSORS]
entities.append(OwletSleepStateSensor(coordinator))
async_add_entities(entities) async_add_entities(entities)
@@ -142,3 +143,31 @@ class OwletSensor(OwletBaseEntity, SensorEntity):
return None return None
return self.sock.properties[self.entity_description.element] 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"]
-2
View File
@@ -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. 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". 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 %}
<!----> <!---->
--- ---