-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
44 lines (32 loc) · 1.84 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
42
43
44
"""The Huawei Fusionsolar integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from .const import CONF_USERNAME, CONF_PASSWORD, CONF_REGION
from .const import DOMAIN
# from FusionSolarPy.src.fusion_solar_py.client import FusionSolarClient
from fusion_solar_py.client import FusionSolarClient
# TODO List the platforms that you want to support.
# For your initial PR, limit it to 1 platform.
PLATFORMS: list[Platform] = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Huawei Fusionsolar from a config entry."""
# Store an instance of the "connecting" class (=API object) that does the work of speaking
# with your actual devices.
#TODO below only works for a single plant for now
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = FusionSolarClient(entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD],
entry.data[CONF_REGION])
# This creates each HA object for each platform your device requires.
# It's done by calling the `async_setup_entry` function in each platform module.
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
# This is called when an entry/configured device is to be removed. The class
# needs to unload itself, and remove callbacks. See the classes for further
# details
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok