Make sure Ambient PWS data storage conforms to standards (#57807)

This commit is contained in:
Aaron Bach 2021-10-22 04:17:25 -06:00 committed by GitHub
parent 8bc10db0bb
commit 61e093cecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 12 deletions

View File

@ -26,7 +26,6 @@ from homeassistant.helpers.event import async_call_later
from .const import ( from .const import (
ATTR_LAST_DATA, ATTR_LAST_DATA,
CONF_APP_KEY, CONF_APP_KEY,
DATA_CLIENT,
DOMAIN, DOMAIN,
LOGGER, LOGGER,
TYPE_SOLARRADIATION, TYPE_SOLARRADIATION,
@ -59,7 +58,8 @@ def async_hydrate_station_data(data: dict[str, Any]) -> dict[str, Any]:
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up the Ambient PWS as config entry.""" """Set up the Ambient PWS as config entry."""
hass.data.setdefault(DOMAIN, {DATA_CLIENT: {}}) hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {}
if not entry.unique_id: if not entry.unique_id:
hass.config_entries.async_update_entry( hass.config_entries.async_update_entry(
@ -78,7 +78,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
), ),
) )
hass.loop.create_task(ambient.ws_connect()) hass.loop.create_task(ambient.ws_connect())
hass.data[DOMAIN][DATA_CLIENT][entry.entry_id] = ambient hass.data[DOMAIN][entry.entry_id] = ambient
except WebsocketError as err: except WebsocketError as err:
LOGGER.error("Config entry failed: %s", err) LOGGER.error("Config entry failed: %s", err)
raise ConfigEntryNotReady from err raise ConfigEntryNotReady from err
@ -97,10 +97,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload an Ambient PWS config entry.""" """Unload an Ambient PWS config entry."""
ambient = hass.data[DOMAIN][DATA_CLIENT].pop(entry.entry_id) unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
hass.async_create_task(ambient.ws_disconnect()) if unload_ok:
ambient = hass.data[DOMAIN].pop(entry.entry_id)
hass.async_create_task(ambient.ws_disconnect())
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) return unload_ok
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

View File

@ -16,7 +16,7 @@ from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import AmbientWeatherEntity from . import AmbientWeatherEntity
from .const import ATTR_LAST_DATA, DATA_CLIENT, DOMAIN from .const import ATTR_LAST_DATA, DOMAIN
TYPE_BATT1 = "batt1" TYPE_BATT1 = "batt1"
TYPE_BATT10 = "batt10" TYPE_BATT10 = "batt10"
@ -234,7 +234,7 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Ambient PWS binary sensors based on a config entry.""" """Set up Ambient PWS binary sensors based on a config entry."""
ambient = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id] ambient = hass.data[DOMAIN][entry.entry_id]
async_add_entities( async_add_entities(
[ [

View File

@ -8,7 +8,5 @@ ATTR_LAST_DATA = "last_data"
CONF_APP_KEY = "app_key" CONF_APP_KEY = "app_key"
DATA_CLIENT = "data_client"
TYPE_SOLARRADIATION = "solarradiation" TYPE_SOLARRADIATION = "solarradiation"
TYPE_SOLARRADIATION_LX = "solarradiation_lx" TYPE_SOLARRADIATION_LX = "solarradiation_lx"

View File

@ -39,7 +39,7 @@ from . import (
AmbientStation, AmbientStation,
AmbientWeatherEntity, AmbientWeatherEntity,
) )
from .const import ATTR_LAST_DATA, DATA_CLIENT, DOMAIN from .const import ATTR_LAST_DATA, DOMAIN
TYPE_24HOURRAININ = "24hourrainin" TYPE_24HOURRAININ = "24hourrainin"
TYPE_BAROMABSIN = "baromabsin" TYPE_BAROMABSIN = "baromabsin"
@ -609,7 +609,7 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up Ambient PWS sensors based on a config entry.""" """Set up Ambient PWS sensors based on a config entry."""
ambient = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id] ambient = hass.data[DOMAIN][entry.entry_id]
async_add_entities( async_add_entities(
[ [