mirror of
https://github.com/home-assistant/core.git
synced 2026-07-01 11:46:40 +01:00
c7cf78952e
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
62 lines
1.8 KiB
Python
62 lines
1.8 KiB
Python
"""The Omnilogic integration."""
|
|
|
|
import logging
|
|
|
|
from omnilogic import LoginException, OmniLogic, OmniLogicException
|
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
from homeassistant.helpers import aiohttp_client
|
|
|
|
from .const import CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
|
|
from .coordinator import OmniLogicConfigEntry, OmniLogicUpdateCoordinator
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
PLATFORMS = [Platform.SENSOR, Platform.SWITCH]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: OmniLogicConfigEntry) -> bool:
|
|
"""Set up Omnilogic from a config entry."""
|
|
|
|
conf = entry.data
|
|
username = conf[CONF_USERNAME]
|
|
password = conf[CONF_PASSWORD]
|
|
|
|
polling_interval = conf.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
|
|
|
session = aiohttp_client.async_get_clientsession(hass)
|
|
|
|
api = OmniLogic(username, password, session)
|
|
|
|
try:
|
|
await api.connect()
|
|
await api.get_telemetry_data()
|
|
except LoginException as error:
|
|
_LOGGER.error("Login Failed: %s", error)
|
|
return False
|
|
except OmniLogicException as error:
|
|
_LOGGER.debug("OmniLogic API error: %s", error)
|
|
raise ConfigEntryNotReady from error
|
|
|
|
coordinator = OmniLogicUpdateCoordinator(
|
|
hass=hass,
|
|
api=api,
|
|
name="Omnilogic",
|
|
config_entry=entry,
|
|
polling_interval=polling_interval,
|
|
)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
entry.runtime_data = coordinator
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: OmniLogicConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|