-
Notifications
You must be signed in to change notification settings - Fork 1
/
__init__.py
42 lines (34 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
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .api import SmartHubAPI
from .const import DOMAIN, CONF_POLL_INTERVAL, DEFAULT_POLL_INTERVAL
import logging
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up the integration from a config entry."""
config = entry.data
# Initialize the API object
api = SmartHubAPI(
email=config["email"],
password=config["password"],
account_id=config["account_id"],
location_id=config["location_id"],
host=config["host"],
)
# Store the API instance in hass.data
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {
"api": api,
"poll_interval": config.get(CONF_POLL_INTERVAL, DEFAULT_POLL_INTERVAL),
}
# Debug log to confirm what is being stored
_LOGGER.debug("Stored API instance in hass.data: %s", type(hass.data[DOMAIN][entry.entry_id]))
# Forward setup to the sensor platform
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
if await hass.config_entries.async_unload_platforms(entry, ["sensor"]):
hass.data[DOMAIN].pop(entry.entry_id, None)
return True
return False