Corrected spelling fixed typing reordered imports
###Fix # In preparation for pull request to homeassistant core, just corrected some spelling, sorted imports using isort and corrected some type hinting
This commit is contained in:
@@ -4,26 +4,32 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyowletapi.api import OwletAPI
|
from pyowletapi.api import OwletAPI
|
||||||
|
from pyowletapi.exceptions import (
|
||||||
|
OwletAuthenticationError,
|
||||||
|
OwletConnectionError,
|
||||||
|
OwletDevicesError,
|
||||||
|
OwletEmailError,
|
||||||
|
OwletPasswordError,
|
||||||
|
)
|
||||||
from pyowletapi.sock import Sock
|
from pyowletapi.sock import Sock
|
||||||
from pyowletapi.exceptions import OwletAuthenticationError
|
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryAuthFailed
|
from homeassistant.config_entries import (
|
||||||
|
ConfigEntry,
|
||||||
|
ConfigEntryAuthFailed,
|
||||||
|
ConfigEntryNotReady,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
Platform,
|
|
||||||
CONF_REGION,
|
|
||||||
CONF_USERNAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_SCAN_INTERVAL,
|
|
||||||
CONF_API_TOKEN,
|
CONF_API_TOKEN,
|
||||||
|
CONF_REGION,
|
||||||
|
CONF_SCAN_INTERVAL,
|
||||||
|
CONF_USERNAME,
|
||||||
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from .const import (
|
from homeassistant.helpers.device_registry import DeviceEntry
|
||||||
DOMAIN,
|
|
||||||
CONF_OWLET_EXPIRY,
|
from .const import CONF_OWLET_EXPIRY, CONF_OWLET_REFRESH, DOMAIN, SUPPORTED_VERSIONS
|
||||||
CONF_OWLET_REFRESH,
|
|
||||||
SUPPORTED_VERSIONS,
|
|
||||||
)
|
|
||||||
from .coordinator import OwletCoordinator
|
from .coordinator import OwletCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||||
@@ -61,12 +67,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
for device in devices["response"]
|
for device in devices["response"]
|
||||||
}
|
}
|
||||||
|
|
||||||
except OwletAuthenticationError as err:
|
except (OwletAuthenticationError, OwletEmailError, OwletPasswordError) 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]}"
|
||||||
) from err
|
) from err
|
||||||
|
|
||||||
|
except OwletConnectionError as err:
|
||||||
|
raise ConfigEntryNotReady(
|
||||||
|
f"Error connecting to {entry.data[CONF_USERNAME]}"
|
||||||
|
) from err
|
||||||
|
|
||||||
coordinators = [
|
coordinators = [
|
||||||
OwletCoordinator(hass, sock, entry.options.get(CONF_SCAN_INTERVAL))
|
OwletCoordinator(hass, sock, entry.options.get(CONF_SCAN_INTERVAL))
|
||||||
for sock in socks.values()
|
for sock in socks.values()
|
||||||
|
|||||||
@@ -5,34 +5,24 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from pyowletapi.api import OwletAPI
|
from pyowletapi.api import OwletAPI
|
||||||
|
from pyowletapi.exceptions import OwletDevicesError, OwletEmailError, OwletPasswordError
|
||||||
from pyowletapi.sock import Sock
|
from pyowletapi.sock import Sock
|
||||||
from pyowletapi.exceptions import (
|
|
||||||
OwletDevicesError,
|
|
||||||
OwletEmailError,
|
|
||||||
OwletPasswordError,
|
|
||||||
)
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, exceptions
|
from homeassistant import config_entries, exceptions
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
||||||
from homeassistant.core import callback
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_REGION,
|
|
||||||
CONF_USERNAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_SCAN_INTERVAL,
|
|
||||||
CONF_API_TOKEN,
|
CONF_API_TOKEN,
|
||||||
|
CONF_PASSWORD,
|
||||||
|
CONF_REGION,
|
||||||
|
CONF_SCAN_INTERVAL,
|
||||||
|
CONF_USERNAME,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import callback
|
||||||
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import (
|
from .const import CONF_OWLET_EXPIRY, CONF_OWLET_REFRESH, DOMAIN, POLLING_INTERVAL
|
||||||
DOMAIN,
|
|
||||||
CONF_OWLET_EXPIRY,
|
|
||||||
POLLING_INTERVAL,
|
|
||||||
CONF_OWLET_REFRESH,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -110,18 +100,22 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
def async_get_options_flow(config_entry):
|
def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlowHandler:
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return OptionsFlowHandler(config_entry)
|
return OptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
async def async_step_reauth(self, user_input=None):
|
async def async_step_reauth(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle reauth"""
|
"""Handle reauth"""
|
||||||
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
self.reauth_entry = self.hass.config_entries.async_get_entry(
|
||||||
self.context["entry_id"]
|
self.context["entry_id"]
|
||||||
)
|
)
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(self, user_input=None):
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Dialog that informs the user that reauth is required"""
|
"""Dialog that informs the user that reauth is required"""
|
||||||
assert self.reauth_entry is not None
|
assert self.reauth_entry is not None
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
@@ -145,12 +139,10 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return self.async_abort(reason="reauth_successful")
|
return self.async_abort(reason="reauth_successful")
|
||||||
|
|
||||||
except OwletEmailError:
|
|
||||||
errors["base"] = "invalid_email"
|
|
||||||
except OwletPasswordError:
|
except OwletPasswordError:
|
||||||
errors["base"] = "invalid_password"
|
errors["base"] = "invalid_password"
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("error reauthing")
|
_LOGGER.exception("Error reauthenticating")
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="reauth_confirm",
|
step_id="reauth_confirm",
|
||||||
@@ -162,11 +154,13 @@ class OwletConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
class OptionsFlowHandler(config_entries.OptionsFlow):
|
class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||||
"""Handle a options flow for owlet"""
|
"""Handle a options flow for owlet"""
|
||||||
|
|
||||||
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
|
def __init__(self, config_entry: ConfigEntry) -> None:
|
||||||
"""Initialise options flow"""
|
"""Initialise options flow"""
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
|
|
||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle options flow"""
|
"""Handle options flow"""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
"""Owlet integration."""
|
"""Owlet integration coordinator class."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pyowletapi.sock import Sock
|
|
||||||
from pyowletapi.exceptions import (
|
from pyowletapi.exceptions import (
|
||||||
OwletError,
|
|
||||||
OwletConnectionError,
|
|
||||||
OwletAuthenticationError,
|
OwletAuthenticationError,
|
||||||
|
OwletConnectionError,
|
||||||
|
OwletError,
|
||||||
)
|
)
|
||||||
|
from pyowletapi.sock import Sock
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_EMAIL
|
||||||
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 (
|
||||||
|
ConfigEntryAuthFailed,
|
||||||
|
DataUpdateCoordinator,
|
||||||
|
UpdateFailed,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN, MANUFACTURER
|
from .const import DOMAIN, MANUFACTURER
|
||||||
|
|
||||||
@@ -55,5 +60,9 @@ class OwletCoordinator(DataUpdateCoordinator):
|
|||||||
self.config_entry,
|
self.config_entry,
|
||||||
data={**self.config_entry.data, **properties["tokens"]},
|
data={**self.config_entry.data, **properties["tokens"]},
|
||||||
)
|
)
|
||||||
except (OwletError, OwletConnectionError, OwletAuthenticationError) as err:
|
except OwletAuthenticationError as err:
|
||||||
|
raise ConfigEntryAuthFailed(
|
||||||
|
f"Authentication failed for {self.config_entry.data[CONF_EMAIL]}"
|
||||||
|
) from err
|
||||||
|
except (OwletError, OwletConnectionError) as err:
|
||||||
raise UpdateFailed(err) from err
|
raise UpdateFailed(err) from err
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
{
|
{
|
||||||
"domain": "owlet",
|
"domain": "owlet",
|
||||||
"name": "Owlet Smart Sock",
|
"name": "Owlet Smart Sock",
|
||||||
"codeowners": [
|
"codeowners": ["@ryanbdclark"],
|
||||||
"@ryanbdclark"
|
|
||||||
],
|
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/owlet",
|
"documentation": "https://www.home-assistant.io/integrations/owlet",
|
||||||
"homekit": {},
|
"homekit": {},
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"requirements": [
|
"requirements": ["pyowletapi==2023.5.28"]
|
||||||
"pyowletapi==2023.5.28"
|
|
||||||
],
|
|
||||||
"version":"2023.5.5"
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"""Support for Android IP Webcam binary sensors."""
|
"""Support for Owlet sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
@@ -9,14 +10,15 @@ from homeassistant.components.sensor import (
|
|||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
UnitOfTime,
|
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
|
UnitOfTime,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.helpers.typing import StateType
|
||||||
|
|
||||||
from .const import DOMAIN, SLEEP_STATES
|
from .const import DOMAIN, SLEEP_STATES
|
||||||
from .coordinator import OwletCoordinator
|
from .coordinator import OwletCoordinator
|
||||||
@@ -80,7 +82,7 @@ SENSORS: tuple[OwletSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
OwletSensorEntityDescription(
|
OwletSensorEntityDescription(
|
||||||
key="signalstrength",
|
key="signalstrength",
|
||||||
name="Singal Strength",
|
name="Signal Strength",
|
||||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
@@ -126,7 +128,7 @@ class OwletSensor(OwletBaseEntity, SensorEntity):
|
|||||||
self._attr_unique_id = f"{self.sock.serial}-{self.entity_description.name}"
|
self._attr_unique_id = f"{self.sock.serial}-{self.entity_description.name}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self) -> StateType:
|
||||||
"""Return sensor value"""
|
"""Return sensor value"""
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -142,7 +144,9 @@ class OwletSensor(OwletBaseEntity, SensorEntity):
|
|||||||
):
|
):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.sock.properties[self.entity_description.element]
|
properties = self.sock.properties
|
||||||
|
|
||||||
|
return properties[self.entity_description.element]
|
||||||
|
|
||||||
|
|
||||||
class OwletSleepStateSensor(OwletBaseEntity, SensorEntity):
|
class OwletSleepStateSensor(OwletBaseEntity, SensorEntity):
|
||||||
@@ -161,7 +165,7 @@ class OwletSleepStateSensor(OwletBaseEntity, SensorEntity):
|
|||||||
self._attr_name = "Sleep State"
|
self._attr_name = "Sleep State"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self) -> str:
|
||||||
"""Return sensor value"""
|
"""Return sensor value"""
|
||||||
if self.sock.properties["charging"]:
|
if self.sock.properties["charging"]:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user