* Add elmax integration. * Run hassfest and generate requirements_all * Remove secondary platforms from elmax integration as per first component integration. * Move ElmaxCoordinator and ElmaxEntity into external file Linting review * Remove useless variables * Fix wrong indentation. * Remove unecessary platforms. * Remove unnecessary attributes from manifest. * Rely on property getters/setters rathern than private attribute from parent. Update internal entity state just after transitory state update. * Update homeassistant/components/elmax/const.py Reference Platform constant Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de> * Update username/password values Rely on already-present templating constants Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de> * Add missing constant import. * Remove unnecessary test_unhandled_error() callback implementation. * Add common.py to coverage ignore list. * Improve coverage of config_flow. * Rename the integration. Co-authored-by: Franck Nijhof <frenck@frenck.nl> * Fix reauth bug and improve testing. * Refactor lambdas into generators. Co-authored-by: Marvin Wichmann <marvin@fam-wichmann.de> Co-authored-by: Franck Nijhof <frenck@frenck.nl>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""The elmax-cloud integration."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
import logging
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
|
|
|
from .common import ElmaxCoordinator
|
|
from .const import (
|
|
CONF_ELMAX_PANEL_ID,
|
|
CONF_ELMAX_PANEL_PIN,
|
|
CONF_ELMAX_PASSWORD,
|
|
CONF_ELMAX_USERNAME,
|
|
DOMAIN,
|
|
ELMAX_PLATFORMS,
|
|
POLLING_SECONDS,
|
|
)
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
|
"""Set up elmax-cloud from a config entry."""
|
|
# Create the API client object and attempt a login, so that we immediately know
|
|
# if there is something wrong with user credentials
|
|
coordinator = ElmaxCoordinator(
|
|
hass=hass,
|
|
logger=_LOGGER,
|
|
username=entry.data[CONF_ELMAX_USERNAME],
|
|
password=entry.data[CONF_ELMAX_PASSWORD],
|
|
panel_id=entry.data[CONF_ELMAX_PANEL_ID],
|
|
panel_pin=entry.data[CONF_ELMAX_PANEL_PIN],
|
|
name=f"Elmax Cloud {entry.entry_id}",
|
|
update_interval=timedelta(seconds=POLLING_SECONDS),
|
|
)
|
|
|
|
# Issue a first refresh, so that we trigger a re-auth flow if necessary
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
# Store a global reference to the coordinator for later use
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
|
|
|
# Perform platform initialization.
|
|
hass.config_entries.async_setup_platforms(entry, ELMAX_PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, ELMAX_PLATFORMS)
|
|
if unload_ok:
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|