Use runtime_data for august (#116610)
parent
ef242f2883
commit
1fc8fdf9ff
|
@ -49,6 +49,8 @@ API_CACHED_ATTRS = {
|
||||||
}
|
}
|
||||||
YALEXS_BLE_DOMAIN = "yalexs_ble"
|
YALEXS_BLE_DOMAIN = "yalexs_ble"
|
||||||
|
|
||||||
|
AugustConfigEntry = ConfigEntry["AugustData"]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up August from a config entry."""
|
"""Set up August from a config entry."""
|
||||||
|
@ -66,22 +68,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
entry.runtime_data.async_stop()
|
||||||
data: AugustData = hass.data[DOMAIN][entry.entry_id]
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
data.async_stop()
|
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
||||||
|
|
||||||
if unload_ok:
|
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_august(
|
async def async_setup_august(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry, august_gateway: AugustGateway
|
hass: HomeAssistant, config_entry: AugustConfigEntry, august_gateway: AugustGateway
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Set up the August component."""
|
"""Set up the August component."""
|
||||||
|
|
||||||
|
@ -95,10 +89,7 @@ async def async_setup_august(
|
||||||
await august_gateway.async_authenticate()
|
await august_gateway.async_authenticate()
|
||||||
await august_gateway.async_refresh_access_token_if_needed()
|
await august_gateway.async_refresh_access_token_if_needed()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
data = config_entry.runtime_data = AugustData(hass, config_entry, august_gateway)
|
||||||
data = hass.data[DOMAIN][config_entry.entry_id] = AugustData(
|
|
||||||
hass, config_entry, august_gateway
|
|
||||||
)
|
|
||||||
await data.async_setup()
|
await data.async_setup()
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
||||||
|
@ -509,12 +500,12 @@ def _restore_live_attrs(
|
||||||
|
|
||||||
|
|
||||||
async def async_remove_config_entry_device(
|
async def async_remove_config_entry_device(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
|
hass: HomeAssistant, config_entry: AugustConfigEntry, device_entry: dr.DeviceEntry
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Remove august config entry from a device if its no longer present."""
|
"""Remove august config entry from a device if its no longer present."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
|
||||||
return not any(
|
return not any(
|
||||||
identifier
|
identifier
|
||||||
for identifier in device_entry.identifiers
|
for identifier in device_entry.identifiers
|
||||||
if identifier[0] == DOMAIN and data.get_device(identifier[1])
|
if identifier[0] == DOMAIN
|
||||||
|
and config_entry.runtime_data.get_device(identifier[1])
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,14 +22,13 @@ from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
from .const import ACTIVITY_UPDATE_INTERVAL, DOMAIN
|
from .const import ACTIVITY_UPDATE_INTERVAL
|
||||||
from .entity import AugustEntityMixin
|
from .entity import AugustEntityMixin
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -154,11 +153,11 @@ SENSOR_TYPES_DOORBELL: tuple[AugustDoorbellBinarySensorEntityDescription, ...] =
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AugustConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the August binary sensors."""
|
"""Set up the August binary sensors."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
entities: list[BinarySensorEntity] = []
|
entities: list[BinarySensorEntity] = []
|
||||||
|
|
||||||
for door in data.locks:
|
for door in data.locks:
|
||||||
|
|
|
@ -3,22 +3,20 @@
|
||||||
from yalexs.lock import Lock
|
from yalexs.lock import Lock
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity
|
from homeassistant.components.button import ButtonEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import AugustEntityMixin
|
from .entity import AugustEntityMixin
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AugustConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up August lock wake buttons."""
|
"""Set up August lock wake buttons."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
async_add_entities(AugustWakeLockButton(data, lock) for lock in data.locks)
|
async_add_entities(AugustWakeLockButton(data, lock) for lock in data.locks)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,12 @@ from yalexs.doorbell import ContentTokenExpired, Doorbell
|
||||||
from yalexs.util import update_doorbell_image_from_activity
|
from yalexs.util import update_doorbell_image_from_activity
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT, DOMAIN
|
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT
|
||||||
from .entity import AugustEntityMixin
|
from .entity import AugustEntityMixin
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -25,11 +24,11 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AugustConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up August cameras."""
|
"""Set up August cameras."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
# Create an aiohttp session instead of using the default one since the
|
# Create an aiohttp session instead of using the default one since the
|
||||||
# default one is likely to trigger august's WAF if another integration
|
# default one is likely to trigger august's WAF if another integration
|
||||||
# is also using Cloudflare
|
# is also using Cloudflare
|
||||||
|
|
|
@ -7,11 +7,10 @@ from typing import Any
|
||||||
from yalexs.const import DEFAULT_BRAND
|
from yalexs.const import DEFAULT_BRAND
|
||||||
|
|
||||||
from homeassistant.components.diagnostics import async_redact_data
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry
|
||||||
from .const import CONF_BRAND, DOMAIN
|
from .const import CONF_BRAND
|
||||||
|
|
||||||
TO_REDACT = {
|
TO_REDACT = {
|
||||||
"HouseID",
|
"HouseID",
|
||||||
|
@ -30,10 +29,10 @@ TO_REDACT = {
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: AugustConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
data: AugustData = hass.data[DOMAIN][entry.entry_id]
|
data = entry.runtime_data
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"locks": {
|
"locks": {
|
||||||
|
|
|
@ -12,15 +12,13 @@ from yalexs.lock import Lock, LockStatus
|
||||||
from yalexs.util import get_latest_activity, update_lock_detail_from_activity
|
from yalexs.util import get_latest_activity, update_lock_detail_from_activity
|
||||||
|
|
||||||
from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity
|
from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
from .const import DOMAIN
|
|
||||||
from .entity import AugustEntityMixin
|
from .entity import AugustEntityMixin
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -30,11 +28,11 @@ LOCK_JAMMED_ERR = 531
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AugustConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up August locks."""
|
"""Set up August locks."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
async_add_entities(AugustLock(data, lock) for lock in data.locks)
|
async_add_entities(AugustLock(data, lock) for lock in data.locks)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_PICTURE,
|
ATTR_ENTITY_PICTURE,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
|
@ -30,7 +29,7 @@ from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import AugustData
|
from . import AugustConfigEntry, AugustData
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_OPERATION_AUTORELOCK,
|
ATTR_OPERATION_AUTORELOCK,
|
||||||
ATTR_OPERATION_KEYPAD,
|
ATTR_OPERATION_KEYPAD,
|
||||||
|
@ -95,11 +94,11 @@ SENSOR_TYPE_KEYPAD_BATTERY = AugustSensorEntityDescription[KeypadDetail](
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: AugustConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the August sensors."""
|
"""Set up the August sensors."""
|
||||||
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
|
data = config_entry.runtime_data
|
||||||
entities: list[SensorEntity] = []
|
entities: list[SensorEntity] = []
|
||||||
migrate_unique_id_devices = []
|
migrate_unique_id_devices = []
|
||||||
operation_sensors = []
|
operation_sensors = []
|
||||||
|
|
Loading…
Reference in New Issue