Use runtime_data for august (#116610)

pull/116619/head
Marc Mueller 2024-05-02 14:39:02 +02:00 committed by GitHub
parent ef242f2883
commit 1fc8fdf9ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 48 deletions

View File

@ -49,6 +49,8 @@ API_CACHED_ATTRS = {
}
YALEXS_BLE_DOMAIN = "yalexs_ble"
AugustConfigEntry = ConfigEntry["AugustData"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""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
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bool:
"""Unload a config entry."""
data: AugustData = hass.data[DOMAIN][entry.entry_id]
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
entry.runtime_data.async_stop()
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
async def async_setup_august(
hass: HomeAssistant, config_entry: ConfigEntry, august_gateway: AugustGateway
hass: HomeAssistant, config_entry: AugustConfigEntry, august_gateway: AugustGateway
) -> bool:
"""Set up the August component."""
@ -95,10 +89,7 @@ async def async_setup_august(
await august_gateway.async_authenticate()
await august_gateway.async_refresh_access_token_if_needed()
hass.data.setdefault(DOMAIN, {})
data = hass.data[DOMAIN][config_entry.entry_id] = AugustData(
hass, config_entry, august_gateway
)
data = config_entry.runtime_data = AugustData(hass, config_entry, august_gateway)
await data.async_setup()
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(
hass: HomeAssistant, config_entry: ConfigEntry, device_entry: dr.DeviceEntry
hass: HomeAssistant, config_entry: AugustConfigEntry, device_entry: dr.DeviceEntry
) -> bool:
"""Remove august config entry from a device if its no longer present."""
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
return not any(
identifier
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])
)

View File

@ -22,14 +22,13 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.event import async_call_later
from . import AugustData
from .const import ACTIVITY_UPDATE_INTERVAL, DOMAIN
from . import AugustConfigEntry, AugustData
from .const import ACTIVITY_UPDATE_INTERVAL
from .entity import AugustEntityMixin
_LOGGER = logging.getLogger(__name__)
@ -154,11 +153,11 @@ SENSOR_TYPES_DOORBELL: tuple[AugustDoorbellBinarySensorEntityDescription, ...] =
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: AugustConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the August binary sensors."""
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
data = config_entry.runtime_data
entities: list[BinarySensorEntity] = []
for door in data.locks:

View File

@ -3,22 +3,20 @@
from yalexs.lock import Lock
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustData
from .const import DOMAIN
from . import AugustConfigEntry, AugustData
from .entity import AugustEntityMixin
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: AugustConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""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)

View File

@ -11,13 +11,12 @@ from yalexs.doorbell import ContentTokenExpired, Doorbell
from yalexs.util import update_doorbell_image_from_activity
from homeassistant.components.camera import Camera
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import aiohttp_client
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustData
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT, DOMAIN
from . import AugustConfigEntry, AugustData
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT
from .entity import AugustEntityMixin
_LOGGER = logging.getLogger(__name__)
@ -25,11 +24,11 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: AugustConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""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
# default one is likely to trigger august's WAF if another integration
# is also using Cloudflare

View File

@ -7,11 +7,10 @@ from typing import Any
from yalexs.const import DEFAULT_BRAND
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from . import AugustData
from .const import CONF_BRAND, DOMAIN
from . import AugustConfigEntry
from .const import CONF_BRAND
TO_REDACT = {
"HouseID",
@ -30,10 +29,10 @@ TO_REDACT = {
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
hass: HomeAssistant, entry: AugustConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
data: AugustData = hass.data[DOMAIN][entry.entry_id]
data = entry.runtime_data
return {
"locks": {

View File

@ -12,15 +12,13 @@ from yalexs.lock import Lock, LockStatus
from yalexs.util import get_latest_activity, update_lock_detail_from_activity
from homeassistant.components.lock import ATTR_CHANGED_BY, LockEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_BATTERY_LEVEL
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity
import homeassistant.util.dt as dt_util
from . import AugustData
from .const import DOMAIN
from . import AugustConfigEntry, AugustData
from .entity import AugustEntityMixin
_LOGGER = logging.getLogger(__name__)
@ -30,11 +28,11 @@ LOCK_JAMMED_ERR = 531
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: AugustConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""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)

View File

@ -19,7 +19,6 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
PERCENTAGE,
@ -30,7 +29,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AugustData
from . import AugustConfigEntry, AugustData
from .const import (
ATTR_OPERATION_AUTORELOCK,
ATTR_OPERATION_KEYPAD,
@ -95,11 +94,11 @@ SENSOR_TYPE_KEYPAD_BATTERY = AugustSensorEntityDescription[KeypadDetail](
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
config_entry: AugustConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the August sensors."""
data: AugustData = hass.data[DOMAIN][config_entry.entry_id]
data = config_entry.runtime_data
entities: list[SensorEntity] = []
migrate_unique_id_devices = []
operation_sensors = []