1 """The Enphase Envoy integration."""
3 from __future__
import annotations
6 from pyenphase
import Envoy
17 OPTION_DISABLE_KEEP_ALIVE,
18 OPTION_DISABLE_KEEP_ALIVE_DEFAULT_VALUE,
21 from .coordinator
import EnphaseConfigEntry, EnphaseUpdateCoordinator
25 """Set up Enphase Envoy from a config entry."""
27 host = entry.data[CONF_HOST]
28 options = entry.options
33 verify=
False, limits=httpx.Limits(max_keepalive_connections=0)
37 OPTION_DISABLE_KEEP_ALIVE, OPTION_DISABLE_KEEP_ALIVE_DEFAULT_VALUE
43 await coordinator.async_config_entry_first_refresh()
44 if not entry.unique_id:
45 hass.config_entries.async_update_entry(entry, unique_id=envoy.serial_number)
47 if entry.unique_id != envoy.serial_number:
54 f
"Unexpected device found at {host}; expected {entry.unique_id}, "
55 f
"found {envoy.serial_number}"
58 entry.runtime_data = coordinator
60 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
63 entry.async_on_unload(entry.add_update_listener(async_reload_entry))
69 """Reload the config entry when it changed."""
70 await hass.config_entries.async_reload(entry.entry_id)
74 """Unload a config entry."""
75 coordinator: EnphaseUpdateCoordinator = entry.runtime_data
76 coordinator.async_cancel_token_refresh()
77 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
81 hass: HomeAssistant, config_entry: EnphaseConfigEntry, device_entry: dr.DeviceEntry
83 """Remove an enphase_envoy config entry from a device."""
84 dev_ids = {dev_id[1]
for dev_id
in device_entry.identifiers
if dev_id[0] == DOMAIN}
85 coordinator = config_entry.runtime_data
86 envoy_data = coordinator.envoy.data
87 envoy_serial_num = config_entry.unique_id
88 if envoy_serial_num
in dev_ids:
91 if envoy_data.inverters:
92 for inverter
in envoy_data.inverters:
93 if str(inverter)
in dev_ids:
95 if envoy_data.encharge_inventory:
96 for encharge
in envoy_data.encharge_inventory:
97 if str(encharge)
in dev_ids:
99 if envoy_data.enpower:
100 if str(envoy_data.enpower.serial_number)
in dev_ids:
bool async_setup_entry(HomeAssistant hass, EnphaseConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, EnphaseConfigEntry entry)
bool async_remove_config_entry_device(HomeAssistant hass, EnphaseConfigEntry config_entry, dr.DeviceEntry device_entry)
None async_reload_entry(HomeAssistant hass, ConfigEntry entry)
httpx.AsyncClient get_async_client(HomeAssistant hass, bool verify_ssl=True)