Make sure OpenUV data storage conforms to standards (#57813)

This commit is contained in:
Aaron Bach 2021-10-16 23:59:19 -06:00 committed by GitHub
parent 3da3d26573
commit fd49da37b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 7 deletions

View file

@ -31,7 +31,6 @@ from .const import (
CONF_FROM_WINDOW,
CONF_TO_WINDOW,
DATA_CLIENT,
DATA_LISTENER,
DATA_PROTECTION_WINDOW,
DATA_UV,
DEFAULT_FROM_WINDOW,
@ -52,7 +51,8 @@ PLATFORMS = ["binary_sensor", "sensor"]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up OpenUV as config entry."""
hass.data.setdefault(DOMAIN, {DATA_CLIENT: {}, DATA_LISTENER: {}})
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {}
_verify_domain_control = verify_domain_control(hass, DOMAIN)
@ -69,11 +69,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
),
)
await openuv.async_update()
hass.data[DOMAIN][DATA_CLIENT][entry.entry_id] = openuv
except OpenUvError as err:
LOGGER.error("Config entry failed: %s", err)
raise ConfigEntryNotReady from err
hass.data[DOMAIN][entry.entry_id][DATA_CLIENT] = openuv
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
@_verify_domain_control
@ -111,7 +111,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload an OpenUV config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN][DATA_CLIENT].pop(entry.entry_id)
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok

View file

@ -33,7 +33,7 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up an OpenUV sensor based on a config entry."""
openuv = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
openuv = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
async_add_entities(
[OpenUvBinarySensor(openuv, BINARY_SENSOR_DESCRIPTION_PROTECTION_WINDOW)]
)

View file

@ -8,7 +8,6 @@ CONF_FROM_WINDOW = "from_window"
CONF_TO_WINDOW = "to_window"
DATA_CLIENT = "data_client"
DATA_LISTENER = "data_listener"
DATA_PROTECTION_WINDOW = "protection_window"
DATA_UV = "uv"

View file

@ -122,7 +122,7 @@ async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up a OpenUV sensor based on a config entry."""
openuv = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
openuv = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
async_add_entities(
[OpenUvSensor(openuv, description) for description in SENSOR_DESCRIPTIONS]
)