-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
43 lines (31 loc) · 1.39 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""The frigidaire integration."""
from __future__ import annotations
from . import frigidaire
from homeassistant import data_entry_flow
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from .const import DOMAIN, PLATFORMS
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up frigidaire from a config entry."""
hass.data.setdefault(DOMAIN, {})
def setup(username: str, password: str) -> frigidaire.Frigidaire:
try:
hass.data[DOMAIN][entry.entry_id] = frigidaire.Frigidaire(
username, password, timeout=60
)
except ConnectionError as err:
raise ConfigEntryNotReady("Cannot connect to Frigidaire") from err
except frigidaire.FrigidaireException as err:
raise data_entry_flow.AbortFlow from err
await hass.async_add_executor_job(
setup, entry.data["username"], entry.data["password"]
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok