From 50fe1a87656b7d6413d06f06f3650fd0bfb48e02 Mon Sep 17 00:00:00 2001 From: RyanClark123 Date: Thu, 23 Nov 2023 15:38:35 +0000 Subject: [PATCH] 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 --- custom_components/owlet/binary_sensor.py | 14 +- custom_components/owlet/config_flow.py | 7 +- custom_components/owlet/const.py | 2 +- custom_components/owlet/coordinator.py | 2 +- custom_components/owlet/entity.py | 4 +- custom_components/owlet/manifest.json | 4 +- custom_components/owlet/sensor.py | 2 +- custom_components/owlet/strings.json | 8 +- custom_components/owlet/translations/en.json | 214 +-- custom_components/owlet/translations/uk.json | 8 +- .../fixtures/update_properties_charging.json | 2 +- tests/fixtures/update_properties_v2.json | 1211 +++++++++++++++++ tests/test_binary_sensor.py | 188 +++ tests/test_config_flow.py | 6 +- tests/test_init.py | 2 +- tests/test_sensor.py | 17 + 16 files changed, 1567 insertions(+), 124 deletions(-) create mode 100644 tests/fixtures/update_properties_v2.json create mode 100644 tests/test_binary_sensor.py diff --git a/custom_components/owlet/binary_sensor.py b/custom_components/owlet/binary_sensor.py index 36cf032..6287fda 100644 --- a/custom_components/owlet/binary_sensor.py +++ b/custom_components/owlet/binary_sensor.py @@ -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.""" diff --git a/custom_components/owlet/config_flow.py b/custom_components/owlet/config_flow.py index ab9d288..8f6bb9b 100644 --- a/custom_components/owlet/config_flow.py +++ b/custom_components/owlet/config_flow.py @@ -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}, ) diff --git a/custom_components/owlet/const.py b/custom_components/owlet/const.py index 3365809..041727d 100644 --- a/custom_components/owlet/const.py +++ b/custom_components/owlet/const.py @@ -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"} diff --git a/custom_components/owlet/coordinator.py b/custom_components/owlet/coordinator.py index 4016be8..889c063 100644 --- a/custom_components/owlet/coordinator.py +++ b/custom_components/owlet/coordinator.py @@ -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.""" diff --git a/custom_components/owlet/entity.py b/custom_components/owlet/entity.py index 714e633..d4d9810 100644 --- a/custom_components/owlet/entity.py +++ b/custom_components/owlet/entity.py @@ -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", diff --git a/custom_components/owlet/manifest.json b/custom_components/owlet/manifest.json index d286c16..f928287 100644 --- a/custom_components/owlet/manifest.json +++ b/custom_components/owlet/manifest.json @@ -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" } \ No newline at end of file diff --git a/custom_components/owlet/sensor.py b/custom_components/owlet/sensor.py index 52821c1..3a979ec 100644 --- a/custom_components/owlet/sensor.py +++ b/custom_components/owlet/sensor.py @@ -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 diff --git a/custom_components/owlet/strings.json b/custom_components/owlet/strings.json index d75702f..08f123d 100644 --- a/custom_components/owlet/strings.json +++ b/custom_components/owlet/strings.json @@ -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" diff --git a/custom_components/owlet/translations/en.json b/custom_components/owlet/translations/en.json index d75702f..5491965 100644 --- a/custom_components/owlet/translations/en.json +++ b/custom_components/owlet/translations/en.json @@ -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" - } } - } } \ No newline at end of file diff --git a/custom_components/owlet/translations/uk.json b/custom_components/owlet/translations/uk.json index d75702f..08f123d 100644 --- a/custom_components/owlet/translations/uk.json +++ b/custom_components/owlet/translations/uk.json @@ -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" diff --git a/tests/fixtures/update_properties_charging.json b/tests/fixtures/update_properties_charging.json index e818eac..e62aee9 100644 --- a/tests/fixtures/update_properties_charging.json +++ b/tests/fixtures/update_properties_charging.json @@ -1052,4 +1052,4 @@ "expiry": 200, "refresh": "new_refresh_token" } -} +} \ No newline at end of file diff --git a/tests/fixtures/update_properties_v2.json b/tests/fixtures/update_properties_v2.json new file mode 100644 index 0000000..2f66733 --- /dev/null +++ b/tests/fixtures/update_properties_v2.json @@ -0,0 +1,1211 @@ +{ + "response": { + "AGE_MONTHS_OLD": { + "type": "Property", + "name": "AGE_MONTHS_OLD", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412147, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Age (Months)", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "ALRTS_DISABLED": { + "type": "Property", + "name": "ALRTS_DISABLED", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412203, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Disable Alerts", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "ALRT_SNS_BLE": { + "type": "Property", + "name": "ALRT_SNS_BLE", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2021-10-22T02:21:11Z", + "key": 82412205, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Alert Sense Ble", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 2, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "ALRT_SNS_YLW": { + "type": "Property", + "name": "ALRT_SNS_YLW", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2021-10-22T02:21:02Z", + "key": 82412208, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Alert Sense Yellow", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 2, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "APP_ACTIVE": { + "type": "Property", + "name": "APP_ACTIVE", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:00Z", + "key": 82412150, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "App Active", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 1, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30, + "ack_status": null, + "ack_message": null, + "acked_at": null + }, + "AVERAGE_DATA": { + "type": "Property", + "name": "AVERAGE_DATA", + "base_type": "string", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "null", + "key": 82412151, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Average Data", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "BABY_NAME": { + "type": "Property", + "name": "BABY_NAME", + "base_type": "string", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412153, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Baby's Name", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "BASE_STATION_ON": { + "type": "Property", + "name": "BASE_STATION_ON", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:00Z", + "key": 82412185, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Base Station On", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 1, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30, + "ack_status": null, + "ack_message": null, + "acked_at": null + }, + "BATT_LEVEL": { + "type": "Property", + "name": "BATT_LEVEL", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T12:21:43Z", + "key": 82412154, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Battery Level (%)", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 29, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "BIRTHDATE": { + "type": "Property", + "name": "BIRTHDATE", + "base_type": "string", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412155, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Birthdate", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "BLE_MAC_ID": { + "type": "Property", + "name": "BLE_MAC_ID", + "base_type": "string", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:40Z", + "key": 82412156, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Sock BLE Id", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": "EEFE7E17F87A", + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "BLE_RSSI": { + "type": "Property", + "name": "BLE_RSSI", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:35Z", + "key": 82412186, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "BLE RSSI", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 98, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "CHARGE_STATUS": { + "type": "Property", + "name": "CHARGE_STATUS", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T13:07:53Z", + "key": 82412157, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Charge Status", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "CRIT_BATT_ALRT": { + "type": "Property", + "name": "CRIT_BATT_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:37Z", + "key": 82412158, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Crit. Battery Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "CRIT_OX_ALRT": { + "type": "Property", + "name": "CRIT_OX_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:37Z", + "key": 82412159, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Crit. Oxygen Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "DEVICE_PING": { + "type": "Property", + "name": "DEVICE_PING", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:40Z", + "key": 82412196, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Device Ping", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "DISABLE_LOGGED_DATA": { + "type": "Property", + "name": "DISABLE_LOGGED_DATA", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2021-10-30T18:58:39Z", + "key": 82412218, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Disable Logged Data", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "ELEVATION": { + "type": "Property", + "name": "ELEVATION", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412160, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Elevation", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "GENDER": { + "type": "Property", + "name": "GENDER", + "base_type": "string", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412161, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Gender", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "HEART_RATE": { + "type": "Property", + "name": "HEART_RATE", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:01Z", + "key": 82412162, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Heart Rate", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 145, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "HIGH_HR_ALRT": { + "type": "Property", + "name": "HIGH_HR_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:38Z", + "key": 82412163, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "High HR Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LATITUDE": { + "type": "Property", + "name": "LATITUDE", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412165, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Latitude", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LIVE_DATA_STREAM": { + "type": "Property", + "name": "LIVE_DATA_STREAM", + "base_type": "string", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "null", + "key": 82412210, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Live Data Stream", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOCAL_BLE_MAC_ID": { + "type": "Property", + "name": "LOCAL_BLE_MAC_ID", + "base_type": "string", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-13T00:47:12Z", + "key": 82412216, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Base BLE Mac Id", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": "C1AC7A823D26", + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOGGED_DATA_CACHE": { + "type": "Property", + "name": "LOGGED_DATA_CACHE", + "base_type": "file", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-10-21T14:13:34Z", + "key": 82412166, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Logged Data Cache", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": "https://ads-owlue1.aylanetworks.com/apiv1/devices/25343495/properties/LOGGED_DATA_CACHE/datapoints/0563f5c0-701c-11ee-1c9e-d612bca1fb00.json", + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LONGITUDE": { + "type": "Property", + "name": "LONGITUDE", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412167, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Longitude", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_BATT_ALRT": { + "type": "Property", + "name": "LOW_BATT_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:38Z", + "key": 82412169, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low Battery Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_BATT_PRCNT": { + "type": "Property", + "name": "LOW_BATT_PRCNT", + "base_type": "integer", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412168, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low Batt. Percent", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_HR_ALRT": { + "type": "Property", + "name": "LOW_HR_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:32Z", + "key": 82412170, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low HR Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_INTEG_READ": { + "type": "Property", + "name": "LOW_INTEG_READ", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:33Z", + "key": 82412171, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low Integrity Read", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_OX_ALRT": { + "type": "Property", + "name": "LOW_OX_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:33Z", + "key": 82412172, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low Oxygen Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "LOW_PA_ALRT": { + "type": "Property", + "name": "LOW_PA_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:40Z", + "key": 82412201, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Low Pa Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "MOVEMENT": { + "type": "Property", + "name": "MOVEMENT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:01Z", + "key": 82412152, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Baby Movement", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 1, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "NURSERY_MODE": { + "type": "Property", + "name": "NURSERY_MODE", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:42Z", + "key": 82412187, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Nursery Mode", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "oem_base_version": { + "type": "Property", + "name": "oem_base_version", + "base_type": "string", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:40Z", + "key": 82412199, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "oem_base_version", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": "M2_3_1_0_7a09", + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "oem_sock_version": { + "type": "Property", + "name": "oem_sock_version", + "base_type": "string", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:41Z", + "key": 82412184, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "oem_sock_version", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": "B2_1_0_0_6c36", + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "ON_BOARDING": { + "type": "Property", + "name": "ON_BOARDING", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:31Z", + "key": 82412181, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "On Boarding", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "OTA_ERROR": { + "type": "Property", + "name": "OTA_ERROR", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:41Z", + "key": 82412183, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "OTA Error", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "OTA_STATUS": { + "type": "Property", + "name": "OTA_STATUS", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:41Z", + "key": 82412182, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "OTA Status", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "OXYGEN_LEVEL": { + "type": "Property", + "name": "OXYGEN_LEVEL", + "base_type": "integer", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T12:22:26Z", + "key": 82412174, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Oxygen Level", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 99, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "PREMATURE": { + "type": "Property", + "name": "PREMATURE", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412175, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Premature", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SHARE_DATA": { + "type": "Property", + "name": "SHARE_DATA", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412176, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Share Data", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_CONNECTION": { + "type": "Property", + "name": "SOCK_CONNECTION", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:01Z", + "key": 82412177, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Sock Connection", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 1, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_DISCON_ALRT": { + "type": "Property", + "name": "SOCK_DISCON_ALRT", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-19T20:19:31Z", + "key": 82412178, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Sock Disconnect Alert", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_DIS_APP_PREF": { + "type": "Property", + "name": "SOCK_DIS_APP_PREF", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412212, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Sock Dis. App Pref.", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_DIS_NEST_PREF": { + "type": "Property", + "name": "SOCK_DIS_NEST_PREF", + "base_type": "boolean", + "read_only": false, + "direction": "input", + "scope": "user", + "data_updated_at": "null", + "key": 82412214, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Sock Dis. Nest Pref.", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": null, + "generated_from": null, + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_OFF": { + "type": "Property", + "name": "SOCK_OFF", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T13:07:53Z", + "key": 82412179, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": false, + "display_name": "Sock Off", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 0, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + }, + "SOCK_REC_PLACED": { + "type": "Property", + "name": "SOCK_REC_PLACED", + "base_type": "boolean", + "read_only": true, + "direction": "output", + "scope": "user", + "data_updated_at": "2023-11-20T14:05:00Z", + "key": 82412180, + "device_key": 25343495, + "product_name": "Owlet Baby Monitors", + "track_only_changes": true, + "display_name": "Sock Recently Placed", + "host_sw_version": false, + "time_series": false, + "derived": false, + "app_type": null, + "recipe": null, + "value": 1, + "generated_from": "AYLA::device", + "generated_at": null, + "denied_roles": [], + "ack_enabled": false, + "retention_days": 30 + } + }, + "tokens": "" +} \ No newline at end of file diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py new file mode 100644 index 0000000..553c35c --- /dev/null +++ b/tests/test_binary_sensor.py @@ -0,0 +1,188 @@ +"""Test Owlet Sensor.""" +from __future__ import annotations + +from homeassistant.core import HomeAssistant + +from . import async_init_integration + + +async def test_sensors_asleep(hass: HomeAssistant) -> None: + """Test sensor values.""" + await async_init_integration( + hass, properties_fixture="update_properties_asleep.json" + ) + + assert len(hass.states.async_all("binary_sensor")) == 10 + + assert hass.states.get("binary_sensor.owlet_baby_care_sock_charging").state == "off" + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_high_heart_rate_alert" + ).state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_heart_rate_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_high_oxygen_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_oxygen_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_battery_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_lost_power_alert").state + == "off" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_sock_disconnected_alert" + ).state + == "off" + ) + assert hass.states.get("binary_sensor.owlet_baby_care_sock_sock_off").state == "off" + assert hass.states.get("binary_sensor.owlet_baby_care_sock_awake").state == "off" + + +async def test_sensors_awake(hass: HomeAssistant) -> None: + """Test sensor values.""" + await async_init_integration( + hass, properties_fixture="update_properties_awake.json" + ) + + assert len(hass.states.async_all("binary_sensor")) == 10 + + assert hass.states.get("binary_sensor.owlet_baby_care_sock_charging").state == "off" + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_high_heart_rate_alert" + ).state + == "on" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_heart_rate_alert").state + == "on" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_high_oxygen_alert").state + == "on" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_oxygen_alert").state + == "on" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_battery_alert").state + == "on" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_lost_power_alert").state + == "on" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_sock_disconnected_alert" + ).state + == "off" + ) + assert hass.states.get("binary_sensor.owlet_baby_care_sock_sock_off").state == "off" + assert hass.states.get("binary_sensor.owlet_baby_care_sock_awake").state == "on" + + +async def test_sensors_charging(hass: HomeAssistant) -> None: + """Test sensor values.""" + await async_init_integration( + hass, properties_fixture="update_properties_charging.json" + ) + + assert len(hass.states.async_all("binary_sensor")) == 10 + + assert hass.states.get("binary_sensor.owlet_baby_care_sock_charging").state == "on" + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_high_heart_rate_alert" + ).state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_heart_rate_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_high_oxygen_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_oxygen_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_battery_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_lost_power_alert").state + == "off" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_sock_disconnected_alert" + ).state + == "off" + ) + assert hass.states.get("binary_sensor.owlet_baby_care_sock_sock_off").state == "off" + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_awake").state == "unknown" + ) + + +async def test_sensors_v2(hass: HomeAssistant) -> None: + """Test sensor values.""" + await async_init_integration(hass, properties_fixture="update_properties_v2.json") + assert len(hass.states.async_all("binary_sensor")) == 9 + + assert hass.states.get("binary_sensor.owlet_baby_care_sock_charging").state == "off" + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_high_heart_rate_alert" + ).state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_heart_rate_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_oxygen_alert").state + == "off" + ) + assert ( + hass.states.get("binary_sensor.owlet_baby_care_sock_low_battery_alert").state + == "off" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_critical_battery_alert" + ).state + == "off" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_critical_oxygen_alert" + ).state + == "off" + ) + assert ( + hass.states.get( + "binary_sensor.owlet_baby_care_sock_sock_disconnected_alert" + ).state + == "off" + ) + assert hass.states.get("binary_sensor.owlet_baby_care_sock_sock_off").state == "off" diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 07ffa7d..a3cebae 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -70,7 +70,7 @@ async def test_flow_wrong_password(hass: HomeAssistant) -> None: user_input=CONF_INPUT, ) assert result["type"] == FlowResultType.FORM - assert result["errors"] == {"base": "invalid_password"} + assert result["errors"] == {"password": "invalid_password"} async def test_flow_wrong_email(hass: HomeAssistant) -> None: @@ -88,7 +88,7 @@ async def test_flow_wrong_email(hass: HomeAssistant) -> None: user_input=CONF_INPUT, ) assert result["type"] == FlowResultType.FORM - assert result["errors"] == {"base": "invalid_email"} + assert result["errors"] == {"username": "invalid_email"} async def test_flow_credentials_error(hass: HomeAssistant) -> None: @@ -193,7 +193,7 @@ async def test_reauth_invalid_password(hass: HomeAssistant) -> None: assert result["type"] == FlowResultType.FORM assert result["step_id"] == "reauth_confirm" - assert result["errors"] == {"base": "invalid_password"} + assert result["errors"] == {"password": "invalid_password"} async def test_reauth_unknown_error(hass: HomeAssistant) -> None: diff --git a/tests/test_init.py b/tests/test_init.py index 9ee5462..8718023 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -43,7 +43,7 @@ async def test_async_setup_entry(hass: HomeAssistant) -> None: entities = er.async_entries_for_device(entity_registry, device_entry.id) - assert len(entities) == 8 + assert len(entities) == 18 await entry.async_unload(hass) diff --git a/tests/test_sensor.py b/tests/test_sensor.py index fb9475e..c564fbd 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -107,3 +107,20 @@ async def test_sensors_charging(hass: HomeAssistant) -> None: == "unknown" ) assert hass.states.get("sensor.owlet_baby_care_sock_sleep_state").state == "unknown" + + +async def test_sensors_v2(hass: HomeAssistant) -> None: + """Test sensor values.""" + await async_init_integration(hass, properties_fixture="update_properties_v2.json") + assert len(hass.states.async_all("sensor")) == 4 + + assert ( + hass.states.get("sensor.owlet_baby_care_sock_battery_percentage").state == "29" + ) + assert hass.states.get("sensor.owlet_baby_care_sock_heart_rate").state == "145" + assert hass.states.get("sensor.owlet_baby_care_sock_o2_saturation").state == "99" + + assert ( + hass.states.get("sensor.owlet_baby_care_sock_signal_strength").state == "98.0" + ) +