Support for V2 sock added

### Feature
* Support added for V2 sock
* Added tests for binary sensors
### Fix
* Bumping pyowletapi to 2023.11.4 to allow V2 support
* Refactoring
* Corrected spelling of sock disconnected sensor
This commit is contained in:
RyanClark123
2023-11-23 15:38:35 +00:00
parent 1cfff537d7
commit 50fe1a8765
16 changed files with 1567 additions and 124 deletions
+13 -1
View File
@@ -48,11 +48,21 @@ SENSORS: tuple[OwletBinarySensorEntityDescription, ...] = (
translation_key="low_ox_alrt",
device_class=BinarySensorDeviceClass.SOUND,
),
OwletBinarySensorEntityDescription(
key="critical_oxygen_alert",
translation_key="crit_ox_alrt",
device_class=BinarySensorDeviceClass.SOUND,
),
OwletBinarySensorEntityDescription(
key="low_battery_alert",
translation_key="low_batt_alrt",
device_class=BinarySensorDeviceClass.SOUND,
),
OwletBinarySensorEntityDescription(
key="critical_battery_alert",
translation_key="crit_batt_alrt",
device_class=BinarySensorDeviceClass.SOUND,
),
OwletBinarySensorEntityDescription(
key="lost_power_alert",
translation_key="lost_pwr_alrt",
@@ -87,12 +97,14 @@ async def async_setup_entry(
sensors = []
for coordinator in coordinators:
print(coordinator.sock.properties)
for sensor in SENSORS:
if sensor.key in coordinator.sock.properties:
sensors.append(OwletBinarySensor(coordinator, sensor))
async_add_entities(sensors)
class OwletBinarySensor(OwletBaseEntity, BinarySensorEntity):
"""Representation of an Owlet binary sensor."""
+2 -5
View File
@@ -12,7 +12,6 @@ from pyowletapi.exceptions import (
OwletEmailError,
OwletPasswordError,
)
from pyowletapi.sock import Sock
import voluptuous as vol
from homeassistant import config_entries, exceptions
@@ -86,10 +85,8 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
title=user_input[CONF_USERNAME],
data={
CONF_REGION: user_input[CONF_REGION],
CONF_USERNAME: user_input[CONF_PASSWORD],
CONF_API_TOKEN: token[CONF_API_TOKEN],
CONF_OWLET_EXPIRY: token[CONF_OWLET_EXPIRY],
CONF_OWLET_REFRESH: token[CONF_OWLET_REFRESH],
CONF_USERNAME: user_input[CONF_USERNAME],
**token,
},
options={CONF_SCAN_INTERVAL: POLLING_INTERVAL},
)
+1 -1
View File
@@ -5,7 +5,7 @@ DOMAIN = "owlet"
CONF_OWLET_EXPIRY = "expiry"
CONF_OWLET_REFRESH = "refresh"
SUPPORTED_VERSIONS = [3]
SUPPORTED_VERSIONS = [2, 3]
POLLING_INTERVAL = 5
MANUFACTURER = "Owlet Baby Care"
SLEEP_STATES = {0: "unknown", 1: "awake", 8: "light_sleep", 15: "deep_sleep"}
+1 -1
View File
@@ -36,7 +36,7 @@ class OwletCoordinator(DataUpdateCoordinator):
update_interval=timedelta(seconds=interval),
)
self.sock = sock
self.config_entry = entry
self.config_entry: ConfigEntry = entry
async def _async_update_data(self) -> None:
"""Fetch the data from the device."""
+2 -2
View File
@@ -2,7 +2,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.device_registry import DeviceInfo
from .coordinator import OwletCoordinator
from .const import DOMAIN, MANUFACTURER
@@ -23,7 +23,7 @@ class OwletBaseEntity(CoordinatorEntity[OwletCoordinator], Entity):
@property
def device_info(self) -> DeviceInfo:
"""Return the device info of the device"""
"""Return the device info of the device."""
return DeviceInfo(
identifiers={(DOMAIN, self.sock.serial)},
name="Owlet Baby Care Sock",
+2 -2
View File
@@ -9,7 +9,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/ryanbdclark/owlet/issues",
"requirements": [
"pyowletapi==2023.11.1"
"pyowletapi==2023.11.4"
],
"version": "2023.11.1"
"version": "2023.11.2"
}
+1 -1
View File
@@ -160,7 +160,7 @@ class OwletSensor(OwletBaseEntity, SensorEntity):
return self.sock.properties[self.entity_description.key]
@property
def options(self) -> list[str]:
def options(self) -> list[str] | None:
"""Set options for sleep state."""
if self.entity_description.key != "sleep_state":
return None
+7 -1
View File
@@ -54,14 +54,20 @@
"low_ox_alrt": {
"name": "Low oxygen alert"
},
"crit_ox_alrt": {
"name": "Critical oxygen alert"
},
"low_batt_alrt": {
"name": "Low battery alert"
},
"crit_batt_alrt": {
"name": "Critical battery alert"
},
"lost_pwr_alrt": {
"name": "Lost power alert"
},
"sock_discon_alrt": {
"name": "Sock diconnected alert"
"name": "Sock disconnected alert"
},
"sock_off": {
"name": "Sock off"
+110 -104
View File
@@ -1,112 +1,118 @@
{
"config": {
"step": {
"user": {
"data": {
"region": "Region",
"username": "Email",
"password": "Password"
"config": {
"step": {
"user": {
"data": {
"region": "Region",
"username": "Email",
"password": "Password"
}
},
"reauth_confirm": {
"title": "Reauthentiaction required for Owlet",
"data": {
"password": "Password"
}
}
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_email": "Entered email address is incorrect",
"invalid_password": "Entered password is incorrect",
"invalid_credentials": "Entered credentials are incorrect",
"unknown": "Unknown error occured"
},
"abort": {
"already_configured": "Device already configured",
"reauth_successful": "Reauthentication successful"
}
},
"reauth_confirm": {
"title": "Reauthentiaction required for Owlet",
"data": {
"password": "Password"
}
}
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_email": "Entered email address is incorrect",
"invalid_password": "Entered password is incorrect",
"invalid_credentials": "Entered credentials are incorrect",
"unknown": "Unknown error occured"
},
"abort": {
"already_configured": "Device already configured",
"reauth_successful": "Reauthentication successful"
}
},
"options": {
"step": {
"init": {
"title": "Configure options for Owlet",
"data": {
"pollinterval": "Polling interval in seconds, min 10"
"options": {
"step": {
"init": {
"title": "Configure options for Owlet",
"data": {
"pollinterval": "Polling interval in seconds, min 10"
}
}
}
}
}
},
"entity": {
"binary_sensor": {
"charging": {
"name": "Charging"
},
"high_hr_alrt": {
"name": "High heart rate alert"
},
"low_hr_alrt": {
"name": "Low heart rate alert"
},
"high_ox_alrt": {
"name": "High oxygen alert"
},
"low_ox_alrt": {
"name": "Low oxygen alert"
},
"low_batt_alrt": {
"name": "Low battery alert"
},
"lost_pwr_alrt": {
"name": "Lost power alert"
},
"sock_discon_alrt": {
"name": "Sock diconnected alert"
},
"sock_off": {
"name": "Sock off"
},
"awake": {
"name": "Awake"
}
},
"sensor": {
"batterypercent": {
"name": "Battery percentage"
},
"signalstrength": {
"name": "Signal strength"
},
"o2saturation": {
"name": "O2 saturation"
},
"o2saturation10a": {
"name": "O2 saturation 10 minute average"
},
"heartrate": {
"name": "Heart rate"
},
"batterymin": {
"name": "Battery remaining"
},
"skintemp": {
"name": "Skin temperature"
},
"sleepstate": {
"name": "Sleep state",
"state": {
"unknown": "Unknown",
"awake": "Awake",
"light_sleep": "Light sleep",
"deep_sleep": "Deep sleep"
"entity": {
"binary_sensor": {
"charging": {
"name": "Charging"
},
"high_hr_alrt": {
"name": "High heart rate alert"
},
"low_hr_alrt": {
"name": "Low heart rate alert"
},
"high_ox_alrt": {
"name": "High oxygen alert"
},
"low_ox_alrt": {
"name": "Low oxygen alert"
},
"crit_ox_alrt": {
"name": "Critical oxygen alert"
},
"low_batt_alrt": {
"name": "Low battery alert"
},
"crit_batt_alrt": {
"name": "Critical battery alert"
},
"lost_pwr_alrt": {
"name": "Lost power alert"
},
"sock_discon_alrt": {
"name": "Sock disconnected alert"
},
"sock_off": {
"name": "Sock off"
},
"awake": {
"name": "Awake"
}
},
"sensor": {
"batterypercent": {
"name": "Battery percentage"
},
"signalstrength": {
"name": "Signal strength"
},
"o2saturation": {
"name": "O2 saturation"
},
"o2saturation10a": {
"name": "O2 saturation 10 minute average"
},
"heartrate": {
"name": "Heart rate"
},
"batterymin": {
"name": "Battery remaining"
},
"skintemp": {
"name": "Skin temperature"
},
"sleepstate": {
"name": "Sleep state",
"state": {
"unknown": "Unknown",
"awake": "Awake",
"light_sleep": "Light sleep",
"deep_sleep": "Deep sleep"
}
},
"movement": {
"name": "Movement"
},
"movementbucket": {
"name": "Movement bucket"
}
}
},
"movement": {
"name": "Movement"
},
"movementbucket": {
"name": "Movement bucket"
}
}
}
}
+7 -1
View File
@@ -54,14 +54,20 @@
"low_ox_alrt": {
"name": "Low oxygen alert"
},
"crit_ox_alrt": {
"name": "Critical oxygen alert"
},
"low_batt_alrt": {
"name": "Low battery alert"
},
"crit_batt_alrt": {
"name": "Critical battery alert"
},
"lost_pwr_alrt": {
"name": "Lost power alert"
},
"sock_discon_alrt": {
"name": "Sock diconnected alert"
"name": "Sock disconnected alert"
},
"sock_off": {
"name": "Sock off"