1 """The Ecoforest integration."""
3 from __future__
import annotations
8 from pyecoforest.api
import EcoforestApi
9 from pyecoforest.exceptions
import (
10 EcoforestAuthenticationRequired,
11 EcoforestConnectionError,
19 from .const
import DOMAIN
20 from .coordinator
import EcoforestCoordinator
22 PLATFORMS: list[Platform] = [Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
24 _LOGGER = logging.getLogger(__name__)
28 """Set up Ecoforest from a config entry."""
30 host = entry.data[CONF_HOST]
31 auth = httpx.BasicAuth(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD])
32 api = EcoforestApi(host, auth)
35 device = await api.get()
36 _LOGGER.debug(
"Ecoforest: %s", device)
37 except EcoforestAuthenticationRequired:
38 _LOGGER.error(
"Authentication on device %s failed", host)
40 except EcoforestConnectionError
as err:
41 _LOGGER.error(
"Error communicating with device %s", host)
42 raise ConfigEntryNotReady
from err
46 await coordinator.async_config_entry_first_refresh()
48 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
50 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
56 """Unload a config entry."""
57 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
58 hass.data[DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)