1 """Support for HomematicIP Cloud devices."""
3 import voluptuous
as vol
5 from homeassistant
import config_entries
10 config_validation
as cv,
11 device_registry
as dr,
12 entity_registry
as er,
24 from .hap
import HomematicipHAP
25 from .services
import async_setup_services, async_unload_services
27 CONFIG_SCHEMA = vol.Schema(
29 vol.Optional(DOMAIN, default=[]): vol.All(
34 vol.Optional(CONF_NAME, default=
""): vol.Any(cv.string),
35 vol.Required(CONF_ACCESSPOINT): cv.string,
36 vol.Required(CONF_AUTHTOKEN): cv.string,
42 extra=vol.ALLOW_EXTRA,
46 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
47 """Set up the HomematicIP Cloud component."""
48 hass.data[DOMAIN] = {}
50 accesspoints = config.get(DOMAIN, [])
52 for conf
in accesspoints:
53 if conf[CONF_ACCESSPOINT]
not in {
54 entry.data[HMIPC_HAPID]
55 for entry
in hass.config_entries.async_entries(DOMAIN)
57 hass.async_create_task(
58 hass.config_entries.flow.async_init(
60 context={
"source": config_entries.SOURCE_IMPORT},
62 HMIPC_HAPID: conf[CONF_ACCESSPOINT],
63 HMIPC_AUTHTOKEN: conf[CONF_AUTHTOKEN],
64 HMIPC_NAME: conf[CONF_NAME],
73 """Set up an access point from a config entry."""
76 if entry.unique_id
is None:
77 new_data =
dict(entry.data)
79 hass.config_entries.async_update_entry(
80 entry, unique_id=new_data[HMIPC_HAPID], data=new_data
84 hass.data[DOMAIN][entry.unique_id] = hap
86 if not await hap.async_setup():
93 hap.reset_connection_listener = hass.bus.async_listen_once(
94 EVENT_HOMEASSISTANT_STOP, hap.shutdown
98 device_registry = dr.async_get(hass)
101 hapname = home.label
if home.label != entry.unique_id
else f
"Home-{home.label}"
103 device_registry.async_get_or_create(
104 config_entry_id=entry.entry_id,
105 identifiers={(DOMAIN, home.id)},
114 """Unload a config entry."""
115 hap = hass.data[DOMAIN].pop(entry.unique_id)
116 hap.reset_connection_listener()
120 return await hap.async_reset()
125 hass: HomeAssistant, entry: ConfigEntry, hap: HomematicipHAP
127 """Remove obsolete entities from entity registry."""
129 if hap.home.currentAPVersion <
"2.2.12":
132 entity_registry = er.async_get(hass)
133 er_entries = er.async_entries_for_config_entry(entity_registry, entry.entry_id)
134 for er_entry
in er_entries:
135 if er_entry.unique_id.startswith(
"HomematicipAccesspointStatus"):
136 entity_registry.async_remove(er_entry.entity_id)
139 for hapid
in hap.home.accessPointUpdateStates:
140 if er_entry.unique_id == f
"HomematicipBatterySensor_{hapid}":
141 entity_registry.async_remove(er_entry.entity_id)
None async_unload_services(HomeAssistant hass)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
def _async_remove_obsolete_entities(HomeAssistant hass, ConfigEntry entry, HomematicipHAP hap)
bool async_setup(HomeAssistant hass, ConfigType config)
None async_setup_services(HomeAssistant hass)