Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0141f7d01a | ||
|
|
dc58b19a46 | ||
|
|
bd6a315b00 | ||
|
|
0cf3afef85 | ||
|
|
fa06157fe2 | ||
|
|
2b21188e73 | ||
|
|
9b3392bdbc | ||
|
|
dc710a1783 | ||
|
|
8d9299a8f4 | ||
|
|
228d54b641 | ||
|
|
3e147aa914 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -151,4 +151,5 @@ cython_debug/
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
|
||||
/custom_components/owlet.zip
|
||||
/custom_components/owlet.zip
|
||||
custom_components/owlet/owlet.zip
|
||||
|
||||
24
CHANGELOG.md
24
CHANGELOG.md
@@ -1,6 +1,30 @@
|
||||
# Changelog
|
||||
|
||||
<!--next-version-placeholder-->
|
||||
## 2023.05.5 (2023-05-19)
|
||||
#### Fix
|
||||
* Owlet refresh token becomes invalid after 24 hours. Meant that after 1 day the integration would stop working. Moved to pyowletapi v2023.5.28 which uses different refresh token, should no longer need reconfiguring after 24 hours
|
||||
|
||||
## 2023.05.4 (2023-05-17)
|
||||
#### Fix
|
||||
* Bumping to pyowletapi 2023.5.25
|
||||
|
||||
## 2023.05.3 (2023-05-17)
|
||||
#### Fix
|
||||
* Bumping to pyowletapi 2023.5.24
|
||||
* Reauthing now no longer re adds users' password to config entry
|
||||
|
||||
## 2023.05.2 (2023-05-16)
|
||||
#### Feature
|
||||
* Integration now makes use of refresh token from pyowletapi to reauthenticate, user password in no longer stored by integration ([`dc710a1`](https://github.com/ryanbdclark/owlet/commit/dc710a1783a4cad9d6cf355240fe12ac779a87ef))
|
||||
* New sensors create for baby sleep state ([`9b3392b`](https://github.com/ryanbdclark/owlet/commit/9b3392bdbcd82015ed31d3a50a517e4e22905684))
|
||||
|
||||
## 2023.05.1 (2023-05-15)
|
||||
#### Feature
|
||||
* Changed versioning to date based
|
||||
### Fix
|
||||
* Bumping to pyowletapi 2023.5.21 to fix issue with unawaited authentication call, should resolve issue with refreshing authentication ([`228d54b`](https://github.com/ryanbdclark/owlet/commit/228d54b6414e0b9171064254246d1f36c3af8f5b))
|
||||
|
||||
|
||||
## v1.5.0 (2023-05-12)
|
||||
### Feature
|
||||
|
||||
22
README.md
22
README.md
@@ -1,8 +1,6 @@
|
||||
# Owlet Custom Integration
|
||||
|
||||
[![GitHub Release][releases-shield]][releases]
|
||||
![GitHub all releases][download-all]
|
||||
![GitHub release (latest by RyanClark123)][download-latest]
|
||||
[![GitHub Activity][commits-shield]][commits]
|
||||
|
||||
[![License][license-shield]][license]
|
||||
@@ -16,7 +14,7 @@ If you have a smart sock 2 and would like to contribute then please do so.
|
||||
|
||||
## Installation
|
||||
|
||||
1. Use [HACS](https://hacs.xyz/docs/setup/download), in `HACS > Integrations > Explore & Add Repositories` search for "Owlet". After adding this `https://github.com/RyanClark123/owlet` as a custom repository.
|
||||
1. Use [HACS](https://hacs.xyz/docs/setup/download), in `HACS > Integrations > Explore & Add Repositories` search for "Owlet". After adding this `https://github.com/ryanbdclark/owlet` as a custom repository.
|
||||
2. Restart Home Assistant.
|
||||
3. [![Add Integration][add-integration-badge]][add-integration] or in the HA UI go to "Settings" -> "Devices & Services" then click "+" and search for "Owlet Smart Sock".
|
||||
|
||||
@@ -34,21 +32,19 @@ 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.
|
||||
|
||||
---
|
||||
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/w/RyanClark123/owlet?style=for-the-badge
|
||||
[commits]: https://github.com/RyanClark123/owlet/commits/main
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/w/ryanbdclark/owlet?style=for-the-badge
|
||||
[commits]: https://github.com/ryanbdclark/owlet/commits/main
|
||||
[hacs]: https://github.com/hacs/integration
|
||||
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badge
|
||||
[license]: LICENSE
|
||||
[license-shield]: https://img.shields.io/github/license/RyanClark123/owlet.svg?style=for-the-badge
|
||||
[maintenance-shield]: https://img.shields.io/badge/maintainer-Ryan%20Clark%20%40RyanClark123-blue.svg?style=for-the-badge
|
||||
[releases-shield]: https://img.shields.io/github/release/RyanClark123/owlet.svg?style=for-the-badge
|
||||
[releases]: https://github.com/RyanClark123/owlet/releases
|
||||
[user_profile]: https://github.com/RyanClark123
|
||||
[download-all]: https://img.shields.io/github/downloads/RyanClark123/Owlet/total?style=for-the-badge
|
||||
[download-latest]: https://img.shields.io/github/downloads/RyanClark123/Owlet/latest/total?style=for-the-badge
|
||||
[license-shield]: https://img.shields.io/github/license/ryanbdclark/owlet.svg?style=for-the-badge
|
||||
[maintenance-shield]: https://img.shields.io/badge/maintainer-Ryan%20Clark%20%40ryanbdclark-blue.svg?style=for-the-badge
|
||||
[releases-shield]: https://img.shields.io/github/release/ryanbdclark/owlet.svg?style=for-the-badge
|
||||
[releases]: https://github.com/ryanbdclark/owlet/releases
|
||||
[user_profile]: https://github.com/ryanbdclark
|
||||
[add-integration]: https://my.home-assistant.io/redirect/config_flow_start?domain=owlet
|
||||
[add-integration-badge]: https://my.home-assistant.io/badges/config_flow_start.svg
|
||||
@@ -5,7 +5,7 @@ import logging
|
||||
|
||||
from pyowletapi.api import OwletAPI
|
||||
from pyowletapi.sock import Sock
|
||||
from pyowletapi.exceptions import OwletConnectionError
|
||||
from pyowletapi.exceptions import OwletAuthenticationError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryAuthFailed
|
||||
from homeassistant.const import (
|
||||
@@ -21,6 +21,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
CONF_OWLET_EXPIRY,
|
||||
CONF_OWLET_REFRESH,
|
||||
SUPPORTED_VERSIONS,
|
||||
)
|
||||
from .coordinator import OwletCoordinator
|
||||
@@ -35,12 +36,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
owlet_api = OwletAPI(
|
||||
entry.data[CONF_REGION],
|
||||
entry.data[CONF_USERNAME],
|
||||
entry.data[CONF_PASSWORD],
|
||||
entry.data[CONF_API_TOKEN],
|
||||
entry.data[CONF_OWLET_EXPIRY],
|
||||
async_get_clientsession(hass),
|
||||
region=entry.data[CONF_REGION],
|
||||
token=entry.data[CONF_API_TOKEN],
|
||||
expiry=entry.data[CONF_OWLET_EXPIRY],
|
||||
refresh=entry.data[CONF_OWLET_REFRESH],
|
||||
session=async_get_clientsession(hass),
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -49,12 +49,19 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
if token:
|
||||
hass.config_entries.async_update_entry(entry, data={**entry.data, **token})
|
||||
|
||||
devices = await owlet_api.get_devices(SUPPORTED_VERSIONS)
|
||||
|
||||
if devices["tokens"]:
|
||||
hass.config_entries.async_update_entry(
|
||||
entry, data={**entry.data, **devices["tokens"]}
|
||||
)
|
||||
|
||||
socks = {
|
||||
device["device"]["dsn"]: Sock(owlet_api, device["device"])
|
||||
for device in await owlet_api.get_devices(SUPPORTED_VERSIONS)
|
||||
for device in devices["response"]
|
||||
}
|
||||
|
||||
except OwletConnectionError as err:
|
||||
except OwletAuthenticationError as err:
|
||||
_LOGGER.error("Credentials no longer valid, please setup owlet again")
|
||||
raise ConfigEntryAuthFailed(
|
||||
f"Credentials expired for {entry.data[CONF_USERNAME]}"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -31,7 +31,7 @@ from .const import (
|
||||
DOMAIN,
|
||||
CONF_OWLET_EXPIRY,
|
||||
POLLING_INTERVAL,
|
||||
SUPPORTED_VERSIONS,
|
||||
CONF_OWLET_REFRESH,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -69,9 +69,9 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._password = user_input[CONF_PASSWORD]
|
||||
|
||||
owlet_api = OwletAPI(
|
||||
self._region,
|
||||
self._username,
|
||||
self._password,
|
||||
region=self._region,
|
||||
user=self._username,
|
||||
password=self._password,
|
||||
session=async_get_clientsession(self.hass),
|
||||
)
|
||||
|
||||
@@ -81,15 +81,15 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
token = await owlet_api.authenticate()
|
||||
try:
|
||||
await owlet_api.get_devices(SUPPORTED_VERSIONS)
|
||||
await owlet_api.validate_authentication()
|
||||
return self.async_create_entry(
|
||||
title=self._username,
|
||||
data={
|
||||
CONF_REGION: self._region,
|
||||
CONF_USERNAME: self._username,
|
||||
CONF_PASSWORD: self._password,
|
||||
CONF_API_TOKEN: token[CONF_API_TOKEN],
|
||||
CONF_OWLET_EXPIRY: token[CONF_OWLET_EXPIRY],
|
||||
CONF_OWLET_REFRESH: token[CONF_OWLET_REFRESH],
|
||||
},
|
||||
options={CONF_SCAN_INTERVAL: POLLING_INTERVAL},
|
||||
)
|
||||
@@ -137,11 +137,9 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
token = await owlet_api.authenticate()
|
||||
if token:
|
||||
user_input[CONF_API_TOKEN] = token[CONF_API_TOKEN]
|
||||
user_input[CONF_OWLET_EXPIRY] = token[CONF_OWLET_EXPIRY]
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.reauth_entry, data={**entry_data, **user_input}
|
||||
)
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.reauth_entry, data={**entry_data, **token}
|
||||
)
|
||||
|
||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
DOMAIN = "owlet"
|
||||
|
||||
CONF_OWLET_EXPIRY = "expiry"
|
||||
CONF_OWLET_REFRESH = "refresh"
|
||||
|
||||
SUPPORTED_VERSIONS = [3]
|
||||
POLLING_INTERVAL = 10
|
||||
POLLING_INTERVAL = 5
|
||||
MANUFACTURER = "Owlet Baby Care"
|
||||
SLEEP_STATES = {0: "Unknown", 1: "Awake", 8: "Light Sleep", 15: "Deep Sleep"}
|
||||
|
||||
@@ -5,16 +5,17 @@ from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from pyowletapi.sock import Sock
|
||||
from pyowletapi.exceptions import OwletError
|
||||
from pyowletapi.exceptions import (
|
||||
OwletError,
|
||||
OwletConnectionError,
|
||||
OwletAuthenticationError,
|
||||
)
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
)
|
||||
from .const import DOMAIN, MANUFACTURER
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -48,6 +49,11 @@ class OwletCoordinator(DataUpdateCoordinator):
|
||||
async def _async_update_data(self) -> None:
|
||||
"""Fetch the data from the device."""
|
||||
try:
|
||||
await self.sock.update_properties()
|
||||
except OwletError as err:
|
||||
properties = await self.sock.update_properties()
|
||||
if properties["tokens"]:
|
||||
self.hass.config_entries.async_update_entry(
|
||||
self.config_entry,
|
||||
data={**self.config_entry.data, **properties["tokens"]},
|
||||
)
|
||||
except (OwletError, OwletConnectionError, OwletAuthenticationError) as err:
|
||||
raise UpdateFailed(err) from err
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"domain": "owlet",
|
||||
"name": "Owlet Smart Sock",
|
||||
"codeowners": [
|
||||
"@RyanClark123"
|
||||
"@ryanbdclark"
|
||||
],
|
||||
"config_flow": true,
|
||||
"dependencies": [],
|
||||
@@ -10,7 +10,7 @@
|
||||
"homekit": {},
|
||||
"iot_class": "cloud_polling",
|
||||
"requirements": [
|
||||
"pyowletapi==2023.5.20"
|
||||
"pyowletapi==2023.5.28"
|
||||
],
|
||||
"version":"1.5.0"
|
||||
"version":"2023.5.5"
|
||||
}
|
||||
|
||||
@@ -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 list(SLEEP_STATES.values())
|
||||
|
||||
20
info.md
20
info.md
@@ -1,8 +1,6 @@
|
||||
# Owlet Custom Integration
|
||||
|
||||
[![GitHub Release][releases-shield]][releases]
|
||||
![GitHub all releases][download-all]
|
||||
![GitHub release (latest by RyanClark123)][download-latest]
|
||||
[![GitHub Activity][commits-shield]][commits]
|
||||
|
||||
[![License][license-shield]][license]
|
||||
@@ -21,23 +19,19 @@ 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 %}
|
||||
|
||||
<!---->
|
||||
|
||||
---
|
||||
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/w/RyanClark123/owlet?style=for-the-badge
|
||||
[commits]: https://github.com/RyanClark123/owlet/commits/main
|
||||
[commits-shield]: https://img.shields.io/github/commit-activity/w/ryanbdclark/owlet?style=for-the-badge
|
||||
[commits]: https://github.com/ryanbdclark/owlet/commits/main
|
||||
[hacs]: https://github.com/hacs/integration
|
||||
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badge
|
||||
[license]: LICENSE
|
||||
[license-shield]: https://img.shields.io/github/license/RyanClark123/owlet.svg?style=for-the-badge
|
||||
[maintenance-shield]: https://img.shields.io/badge/maintainer-Ryan%20Clark%20%40RyanClark123-blue.svg?style=for-the-badge
|
||||
[releases-shield]: https://img.shields.io/github/release/RyanClark123/owlet.svg?style=for-the-badge
|
||||
[releases]: https://github.com/RyanClark123/owlet/releases
|
||||
[user_profile]: https://github.com/RyanClark123
|
||||
[download-all]: https://img.shields.io/github/downloads/RyanClark123/Owlet/total?style=for-the-badge
|
||||
[download-latest]: https://img.shields.io/github/downloads/RyanClark123/Owlet/latest/total?style=for-the-badge
|
||||
[license-shield]: https://img.shields.io/github/license/ryanbdclark/owlet.svg?style=for-the-badge
|
||||
[maintenance-shield]: https://img.shields.io/badge/maintainer-Ryan%20Clark%20%40ryanbdclark-blue.svg?style=for-the-badge
|
||||
[releases-shield]: https://img.shields.io/github/release/ryanbdclark/owlet.svg?style=for-the-badge
|
||||
[releases]: https://github.com/ryanbdclark/owlet/releases
|
||||
[user_profile]: https://github.com/ryanbdclark
|
||||
[add-integration]: https://my.home-assistant.io/redirect/config_flow_start?domain=owlet
|
||||
[add-integration-badge]: https://my.home-assistant.io/badges/config_flow_start.svg
|
||||
Reference in New Issue
Block a user