1 """Support for the OSO Energy devices and services."""
5 from aiohttp.web_exceptions
import HTTPException
6 from apyosoenergyapi
import OSOEnergy
7 from apyosoenergyapi.helper.osoenergy_exceptions
import OSOEnergyReauthRequired
15 from .const
import DOMAIN
18 Platform.BINARY_SENSOR,
20 Platform.WATER_HEATER,
23 Platform.BINARY_SENSOR:
"binary_sensor",
24 Platform.SENSOR:
"sensor",
25 Platform.WATER_HEATER:
"water_heater",
30 """Set up OSO Energy from a config entry."""
31 subscription_key = entry.data[CONF_API_KEY]
32 websession = aiohttp_client.async_get_clientsession(hass)
33 osoenergy = OSOEnergy(subscription_key, websession)
35 osoenergy_config =
dict(entry.data)
37 hass.data.setdefault(DOMAIN, {})
40 devices: Any = await osoenergy.session.start_session(osoenergy_config)
41 except HTTPException
as error:
42 raise ConfigEntryNotReady
from error
43 except OSOEnergyReauthRequired
as err:
44 raise ConfigEntryAuthFailed
from err
46 hass.data[DOMAIN][entry.entry_id] = osoenergy
49 for ha_type, oso_type
in PLATFORM_LOOKUP.items():
50 device_list = devices.get(oso_type, [])
52 platforms.add(ha_type)
54 await hass.config_entries.async_forward_entry_setups(entry, platforms)
59 """Unload a config entry."""
60 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
62 hass.data[DOMAIN].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)