Fix unhandled exception with Guardian paired sensor coordinators (#53663)

This commit is contained in:
Aaron Bach 2021-07-28 23:16:14 -06:00 committed by GitHub
parent a2d66bd1c0
commit c04671ac64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 20 deletions

View file

@ -26,6 +26,7 @@ from .const import (
CONF_UID,
DATA_CLIENT,
DATA_COORDINATOR,
DATA_COORDINATOR_PAIRED_SENSOR,
DATA_PAIRED_SENSOR_MANAGER,
DATA_UNSUB_DISPATCHER_CONNECT,
DOMAIN,
@ -44,6 +45,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
{
DATA_CLIENT: {},
DATA_COORDINATOR: {},
DATA_COORDINATOR_PAIRED_SENSOR: {},
DATA_PAIRED_SENSOR_MANAGER: {},
DATA_UNSUB_DISPATCHER_CONNECT: {},
},
@ -51,9 +53,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
client = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id] = Client(
entry.data[CONF_IP_ADDRESS], port=entry.data[CONF_PORT]
)
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {
API_SENSOR_PAIRED_SENSOR_STATUS: {}
}
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {}
hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][entry.entry_id] = {}
hass.data[DOMAIN][DATA_UNSUB_DISPATCHER_CONNECT][entry.entry_id] = []
# The valve controller's UDP-based API can't handle concurrent requests very well,
@ -113,6 +114,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if unload_ok:
hass.data[DOMAIN][DATA_CLIENT].pop(entry.entry_id)
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR].pop(entry.entry_id)
for unsub in hass.data[DOMAIN][DATA_UNSUB_DISPATCHER_CONNECT][entry.entry_id]:
unsub()
hass.data[DOMAIN][DATA_UNSUB_DISPATCHER_CONNECT].pop(entry.entry_id)
@ -143,8 +145,8 @@ class PairedSensorManager:
self._paired_uids.add(uid)
coordinator = self._hass.data[DOMAIN][DATA_COORDINATOR][self._entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
coordinator = self._hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][
self._entry.entry_id
][uid] = GuardianDataUpdateCoordinator(
self._hass,
client=self._client,
@ -194,8 +196,8 @@ class PairedSensorManager:
# Clear out objects related to this paired sensor:
self._paired_uids.remove(uid)
self._hass.data[DOMAIN][DATA_COORDINATOR][self._entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
self._hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][
self._entry.entry_id
].pop(uid)
# Remove the paired sensor device from the device registry (which will
@ -297,7 +299,6 @@ class ValveControllerEntity(GuardianEntity):
return any(
coordinator.last_update_success
for coordinator in self.coordinators.values()
if coordinator
)
async def _async_continue_entity_setup(self) -> None:

View file

@ -15,11 +15,11 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import PairedSensorEntity, ValveControllerEntity
from .const import (
API_SENSOR_PAIRED_SENSOR_STATUS,
API_SYSTEM_ONBOARD_SENSOR_STATUS,
API_WIFI_STATUS,
CONF_UID,
DATA_COORDINATOR,
DATA_COORDINATOR_PAIRED_SENSOR,
DATA_UNSUB_DISPATCHER_CONNECT,
DOMAIN,
SIGNAL_PAIRED_SENSOR_COORDINATOR_ADDED,
@ -49,9 +49,9 @@ async def async_setup_entry(
@callback
def add_new_paired_sensor(uid: str) -> None:
"""Add a new paired sensor."""
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
][uid]
coordinator = hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][entry.entry_id][
uid
]
entities = []
for kind in PAIRED_SENSOR_SENSORS:
@ -95,8 +95,8 @@ async def async_setup_entry(
)
# Add all paired sensor-specific binary sensors:
for coordinator in hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
for coordinator in hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][
entry.entry_id
].values():
for kind in PAIRED_SENSOR_SENSORS:
name, device_class = SENSOR_ATTRS_MAP[kind]

View file

@ -16,6 +16,7 @@ CONF_UID = "uid"
DATA_CLIENT = "client"
DATA_COORDINATOR = "coordinator"
DATA_COORDINATOR_PAIRED_SENSOR = "coordinator_paired_sensor"
DATA_PAIRED_SENSOR_MANAGER = "paired_sensor_manager"
DATA_UNSUB_DISPATCHER_CONNECT = "unsub_dispatcher_connect"

View file

@ -17,11 +17,11 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import PairedSensorEntity, ValveControllerEntity
from .const import (
API_SENSOR_PAIRED_SENSOR_STATUS,
API_SYSTEM_DIAGNOSTICS,
API_SYSTEM_ONBOARD_SENSOR_STATUS,
CONF_UID,
DATA_COORDINATOR,
DATA_COORDINATOR_PAIRED_SENSOR,
DATA_UNSUB_DISPATCHER_CONNECT,
DOMAIN,
SIGNAL_PAIRED_SENSOR_COORDINATOR_ADDED,
@ -54,9 +54,9 @@ async def async_setup_entry(
@callback
def add_new_paired_sensor(uid: str) -> None:
"""Add a new paired sensor."""
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
][uid]
coordinator = hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][entry.entry_id][
uid
]
entities = []
for kind in PAIRED_SENSOR_SENSORS:
@ -96,8 +96,8 @@ async def async_setup_entry(
)
# Add all paired sensor-specific binary sensors:
for coordinator in hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][
API_SENSOR_PAIRED_SENSOR_STATUS
for coordinator in hass.data[DOMAIN][DATA_COORDINATOR_PAIRED_SENSOR][
entry.entry_id
].values():
for kind in PAIRED_SENSOR_SENSORS:
name, device_class, icon, unit = SENSOR_ATTRS_MAP[kind]