Store integration type in AirVisual config entry (#34621)

This commit is contained in:
Aaron Bach authored and GitHub committed 2020-04-24 10:11:17 -07:00
1 parent 1d22936a82
commit 86d3321d59
4 files changed
+41 -5

No files matched your search

+27 -1
View File
@@ -30,6 +30,7 @@ from .const import (
CONF_CITY,
CONF_COUNTRY,
CONF_GEOGRAPHIES,
CONF_INTEGRATION_TYPE,
DATA_CLIENT,
DOMAIN,
INTEGRATION_TYPE_GEOGRAPHY,
@@ -120,7 +121,7 @@ async def async_setup(hass, config):
@callback
def _standardize_geography_config_entry(hass, config_entry):
"""Ensure that geography observables have appropriate properties."""
"""Ensure that geography config entries have appropriate properties."""
entry_updates = {}
if not config_entry.unique_id:
@@ -129,6 +130,30 @@ def _standardize_geography_config_entry(hass, config_entry):
if not config_entry.options:
# If the config entry doesn't already have any options set, set defaults:
entry_updates["options"] = {CONF_SHOW_ON_MAP: True}
if CONF_INTEGRATION_TYPE not in config_entry.data:
# If the config entry data doesn't contain the integration type, add it:
entry_updates["data"] = {
**config_entry.data,
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_GEOGRAPHY,
}
if not entry_updates:
return
hass.config_entries.async_update_entry(config_entry, **entry_updates)
@callback
def _standardize_node_pro_config_entry(hass, config_entry):
"""Ensure that Node/Pro config entries have appropriate properties."""
entry_updates = {}
if CONF_INTEGRATION_TYPE not in config_entry.data:
# If the config entry data doesn't contain the integration type, add it:
entry_updates["data"] = {
**config_entry.data,
CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_NODE_PRO,
}
if not entry_updates:
return
@@ -151,6 +176,7 @@ async def async_setup_entry(hass, config_entry):
# Only geography-based entries have options:
config_entry.add_update_listener(async_update_options)
else:
_standardize_node_pro_config_entry(hass, config_entry)
airvisual = AirVisualNodeProData(hass, Client(websession), config_entry)
await airvisual.async_update()