1 """Initialization of FYTA integration."""
3 from __future__
import annotations
5 from datetime
import datetime
8 from fyta_cli.fyta_connector
import FytaConnector
21 from .const
import CONF_EXPIRATION
22 from .coordinator
import FytaCoordinator
24 _LOGGER = logging.getLogger(__name__)
29 type FytaConfigEntry = ConfigEntry[FytaCoordinator]
33 """Set up the Fyta integration."""
34 tz: str = hass.config.time_zone
36 username = entry.data[CONF_USERNAME]
37 password = entry.data[CONF_PASSWORD]
38 access_token: str = entry.data[CONF_ACCESS_TOKEN]
39 expiration: datetime = datetime.fromisoformat(
40 entry.data[CONF_EXPIRATION]
49 await coordinator.async_config_entry_first_refresh()
51 entry.runtime_data = coordinator
53 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
59 """Unload Fyta entity."""
61 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
65 """Migrate old entry."""
66 _LOGGER.debug(
"Migrating from version %s", config_entry.version)
68 if config_entry.version > 1:
72 if config_entry.version == 1:
73 if config_entry.minor_version < 2:
74 new = {**config_entry.data}
76 config_entry.data[CONF_USERNAME], config_entry.data[CONF_PASSWORD]
78 credentials = await fyta.login()
79 await fyta.client.close()
81 new[CONF_ACCESS_TOKEN] = credentials.access_token
82 new[CONF_EXPIRATION] = credentials.expiration.isoformat()
84 hass.config_entries.async_update_entry(
85 config_entry, data=new, minor_version=2, version=1
89 "Migration to version %s.%s successful",
91 config_entry.minor_version,
bool async_migrate_entry(HomeAssistant hass, ConfigEntry config_entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, FytaConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)
zoneinfo.ZoneInfo|None async_get_time_zone(str time_zone_str)