Skip to content

Commit

Permalink
Fix unhandled exception with Guardian paired sensor coordinators (#53663
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bachya authored Jul 29, 2021
1 parent a2d66bd commit c04671a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
17 changes: 9 additions & 8 deletions homeassistant/components/guardian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CONF_UID,
DATA_CLIENT,
DATA_COORDINATOR,
DATA_COORDINATOR_PAIRED_SENSOR,
DATA_PAIRED_SENSOR_MANAGER,
DATA_UNSUB_DISPATCHER_CONNECT,
DOMAIN,
Expand All @@ -44,16 +45,16 @@ 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: {},
},
)
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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -143,8 +145,8 @@ async def async_pair_sensor(self, uid: str) -> None:

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,
Expand Down Expand Up @@ -194,8 +196,8 @@ async def async_unpair_sensor(self, uid: str) -> None:

# 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
Expand Down Expand Up @@ -297,7 +299,6 @@ def available(self) -> bool:
return any(
coordinator.last_update_success
for coordinator in self.coordinators.values()
if coordinator
)

async def _async_continue_entity_setup(self) -> None:
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/guardian/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -95,8 +95,8 @@ def add_new_paired_sensor(uid: str) -> None:
)

# 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]
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/guardian/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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"

Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/guardian/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -96,8 +96,8 @@ def add_new_paired_sensor(uid: str) -> None:
)

# 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]
Expand Down

0 comments on commit c04671a

Please sign in to comment.