1 """Support for August devices."""
3 from __future__
import annotations
5 from pathlib
import Path
6 from typing
import cast
8 from aiohttp
import ClientResponseError
9 from yalexs.const
import Brand
10 from yalexs.exceptions
import AugustApiAIOHTTPError
11 from yalexs.manager.exceptions
import CannotConnect, InvalidAuth, RequireValidation
12 from yalexs.manager.gateway
import Config
as YaleXSConfig
20 from .const
import DOMAIN, PLATFORMS
21 from .data
import AugustData
22 from .gateway
import AugustGateway
23 from .util
import async_create_august_clientsession
25 type AugustConfigEntry = ConfigEntry[AugustData]
30 hass: HomeAssistant, entry: AugustConfigEntry
32 """Create an issue for a brand migration."""
33 ir.async_create_issue(
36 "yale_brand_migration",
37 breaks_in_ha_version=
"2024.9",
38 learn_more_url=
"https://www.home-assistant.io/integrations/yale",
39 translation_key=
"yale_brand_migration",
41 severity=ir.IssueSeverity.CRITICAL,
42 translation_placeholders={
43 "migrate_url":
"https://my.home-assistant.io/redirect/config_flow_start?domain=yale"
49 """Set up August from a config entry."""
51 august_gateway =
AugustGateway(Path(hass.config.config_dir), session)
54 except (RequireValidation, InvalidAuth)
as err:
55 raise ConfigEntryAuthFailed
from err
56 except TimeoutError
as err:
58 except (AugustApiAIOHTTPError, ClientResponseError, CannotConnect)
as err:
59 raise ConfigEntryNotReady
from err
60 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
65 """Remove an August config entry."""
66 ir.async_delete_issue(hass, DOMAIN,
"yale_brand_migration")
70 """Unload a config entry."""
71 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
75 hass: HomeAssistant, entry: AugustConfigEntry, august_gateway: AugustGateway
77 """Set up the August component."""
78 config = cast(YaleXSConfig, entry.data)
79 await august_gateway.async_setup(config)
80 if august_gateway.api.brand == Brand.YALE_HOME:
82 await august_gateway.async_authenticate()
83 await august_gateway.async_refresh_access_token_if_needed()
84 data = entry.runtime_data =
AugustData(hass, august_gateway)
85 entry.async_on_unload(
86 hass.bus.async_listen(EVENT_HOMEASSISTANT_STOP, data.async_stop)
88 entry.async_on_unload(data.async_stop)
89 await data.async_setup()
93 hass: HomeAssistant, config_entry: AugustConfigEntry, device_entry: dr.DeviceEntry
95 """Remove august config entry from a device if its no longer present."""
98 for identifier
in device_entry.identifiers
99 if identifier[0] == DOMAIN
100 and config_entry.runtime_data.get_device(identifier[1])
aiohttp.ClientSession async_create_august_clientsession(HomeAssistant hass)
None async_setup_august(HomeAssistant hass, AugustConfigEntry entry, AugustGateway august_gateway)
bool async_remove_config_entry_device(HomeAssistant hass, AugustConfigEntry config_entry, dr.DeviceEntry device_entry)
bool async_setup_entry(HomeAssistant hass, AugustConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, AugustConfigEntry entry)
None async_remove_entry(HomeAssistant hass, AugustConfigEntry entry)
None _async_create_yale_brand_migration_issue(HomeAssistant hass, AugustConfigEntry entry)