Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd6a315b00 | ||
|
|
0cf3afef85 | ||
|
|
fa06157fe2 | ||
|
|
2b21188e73 | ||
|
|
9b3392bdbc | ||
|
|
dc710a1783 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,6 +1,20 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
<!--next-version-placeholder-->
|
<!--next-version-placeholder-->
|
||||||
|
## 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)
|
## 2023-05-1 (2023-05-15)
|
||||||
#### Feature
|
#### Feature
|
||||||
* Changed versioning to date based
|
* Changed versioning to date based
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import logging
|
|||||||
|
|
||||||
from pyowletapi.api import OwletAPI
|
from pyowletapi.api import OwletAPI
|
||||||
from pyowletapi.sock import Sock
|
from pyowletapi.sock import Sock
|
||||||
from pyowletapi.exceptions import OwletConnectionError
|
from pyowletapi.exceptions import OwletAuthenticationError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryAuthFailed
|
from homeassistant.config_entries import ConfigEntry, ConfigEntryAuthFailed
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@@ -21,6 +21,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
CONF_OWLET_EXPIRY,
|
CONF_OWLET_EXPIRY,
|
||||||
|
CONF_OWLET_REFRESH,
|
||||||
SUPPORTED_VERSIONS,
|
SUPPORTED_VERSIONS,
|
||||||
)
|
)
|
||||||
from .coordinator import OwletCoordinator
|
from .coordinator import OwletCoordinator
|
||||||
@@ -35,12 +36,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
owlet_api = OwletAPI(
|
owlet_api = OwletAPI(
|
||||||
entry.data[CONF_REGION],
|
region=entry.data[CONF_REGION],
|
||||||
entry.data[CONF_USERNAME],
|
token=entry.data[CONF_API_TOKEN],
|
||||||
entry.data[CONF_PASSWORD],
|
expiry=entry.data[CONF_OWLET_EXPIRY],
|
||||||
entry.data[CONF_API_TOKEN],
|
refresh=entry.data[CONF_OWLET_REFRESH],
|
||||||
entry.data[CONF_OWLET_EXPIRY],
|
session=async_get_clientsession(hass),
|
||||||
async_get_clientsession(hass),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -54,7 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
for device in await owlet_api.get_devices(SUPPORTED_VERSIONS)
|
for device in await owlet_api.get_devices(SUPPORTED_VERSIONS)
|
||||||
}
|
}
|
||||||
|
|
||||||
except OwletConnectionError as err:
|
except OwletAuthenticationError as err:
|
||||||
_LOGGER.error("Credentials no longer valid, please setup owlet again")
|
_LOGGER.error("Credentials no longer valid, please setup owlet again")
|
||||||
raise ConfigEntryAuthFailed(
|
raise ConfigEntryAuthFailed(
|
||||||
f"Credentials expired for {entry.data[CONF_USERNAME]}"
|
f"Credentials expired for {entry.data[CONF_USERNAME]}"
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from .const import (
|
|||||||
CONF_OWLET_EXPIRY,
|
CONF_OWLET_EXPIRY,
|
||||||
POLLING_INTERVAL,
|
POLLING_INTERVAL,
|
||||||
SUPPORTED_VERSIONS,
|
SUPPORTED_VERSIONS,
|
||||||
|
CONF_OWLET_REFRESH,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -87,9 +88,9 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
data={
|
data={
|
||||||
CONF_REGION: self._region,
|
CONF_REGION: self._region,
|
||||||
CONF_USERNAME: self._username,
|
CONF_USERNAME: self._username,
|
||||||
CONF_PASSWORD: self._password,
|
|
||||||
CONF_API_TOKEN: token[CONF_API_TOKEN],
|
CONF_API_TOKEN: token[CONF_API_TOKEN],
|
||||||
CONF_OWLET_EXPIRY: token[CONF_OWLET_EXPIRY],
|
CONF_OWLET_EXPIRY: token[CONF_OWLET_EXPIRY],
|
||||||
|
CONF_OWLET_REFRESH: token[CONF_OWLET_REFRESH],
|
||||||
},
|
},
|
||||||
options={CONF_SCAN_INTERVAL: POLLING_INTERVAL},
|
options={CONF_SCAN_INTERVAL: POLLING_INTERVAL},
|
||||||
)
|
)
|
||||||
@@ -137,10 +138,8 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
try:
|
try:
|
||||||
token = await owlet_api.authenticate()
|
token = await owlet_api.authenticate()
|
||||||
if token:
|
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.hass.config_entries.async_update_entry(
|
||||||
self.reauth_entry, data={**entry_data, **user_input}
|
self.reauth_entry, data={**entry_data, **token}
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
DOMAIN = "owlet"
|
DOMAIN = "owlet"
|
||||||
|
|
||||||
CONF_OWLET_EXPIRY = "expiry"
|
CONF_OWLET_EXPIRY = "expiry"
|
||||||
|
CONF_OWLET_REFRESH = "refresh"
|
||||||
|
|
||||||
SUPPORTED_VERSIONS = [3]
|
SUPPORTED_VERSIONS = [3]
|
||||||
POLLING_INTERVAL = 10
|
POLLING_INTERVAL = 5
|
||||||
MANUFACTURER = "Owlet Baby Care"
|
MANUFACTURER = "Owlet Baby Care"
|
||||||
|
SLEEP_STATES = {0: "Unknown", 1: "Awake", 8: "Light Sleep", 15: "Deep Sleep"}
|
||||||
|
|||||||
@@ -5,16 +5,18 @@ from datetime import timedelta
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyowletapi.sock import Sock
|
from pyowletapi.sock import Sock
|
||||||
from pyowletapi.exceptions import OwletError, OwletConnectionError
|
from pyowletapi.exceptions import (
|
||||||
|
OwletError,
|
||||||
|
OwletConnectionError,
|
||||||
|
OwletAuthenticationError,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
from homeassistant.const import CONF_API_TOKEN
|
||||||
|
|
||||||
from .const import (
|
from .const import DOMAIN, MANUFACTURER, CONF_OWLET_EXPIRY, CONF_OWLET_REFRESH
|
||||||
DOMAIN,
|
|
||||||
MANUFACTURER,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -49,5 +51,16 @@ class OwletCoordinator(DataUpdateCoordinator):
|
|||||||
"""Fetch the data from the device."""
|
"""Fetch the data from the device."""
|
||||||
try:
|
try:
|
||||||
await self.sock.update_properties()
|
await self.sock.update_properties()
|
||||||
except (OwletError, OwletConnectionError) as err:
|
tokens = await self.sock.api.tokens_changed(
|
||||||
|
{
|
||||||
|
CONF_API_TOKEN: self.config_entry.data[CONF_API_TOKEN],
|
||||||
|
CONF_OWLET_EXPIRY: self.config_entry.data[CONF_OWLET_EXPIRY],
|
||||||
|
CONF_OWLET_REFRESH: self.config_entry.data[CONF_OWLET_REFRESH],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if tokens:
|
||||||
|
self.hass.config_entries.async_update_entry(
|
||||||
|
self.config_entry, data={**self.config_entry.data, **tokens}
|
||||||
|
)
|
||||||
|
except (OwletError, OwletConnectionError, OwletAuthenticationError) as err:
|
||||||
raise UpdateFailed(err) from err
|
raise UpdateFailed(err) from err
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"homekit": {},
|
"homekit": {},
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyowletapi==2023.5.21"
|
"pyowletapi==2023.5.25"
|
||||||
],
|
],
|
||||||
"version":"2023.5.1"
|
"version":"2023.5.4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 SLEEP_STATES.values()
|
||||||
|
|||||||
2
info.md
2
info.md
@@ -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 %}
|
|
||||||
|
|
||||||
<!---->
|
<!---->
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user