Fix bug with non-existent Notion bridge IDs (#106152)
parent
0ca8e52e57
commit
0beb47ac2c
|
@ -290,17 +290,19 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
bridge = self.coordinator.data.bridges[bridge_id]
|
|
||||||
sensor = self.coordinator.data.sensors[sensor_id]
|
sensor = self.coordinator.data.sensors[sensor_id]
|
||||||
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, sensor.hardware_id)},
|
identifiers={(DOMAIN, sensor.hardware_id)},
|
||||||
manufacturer="Silicon Labs",
|
manufacturer="Silicon Labs",
|
||||||
model=str(sensor.hardware_revision),
|
model=str(sensor.hardware_revision),
|
||||||
name=str(sensor.name).capitalize(),
|
name=str(sensor.name).capitalize(),
|
||||||
sw_version=sensor.firmware_version,
|
sw_version=sensor.firmware_version,
|
||||||
via_device=(DOMAIN, bridge.hardware_id),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if bridge := self._async_get_bridge(bridge_id):
|
||||||
|
self._attr_device_info["via_device"] = (DOMAIN, bridge.hardware_id)
|
||||||
|
|
||||||
self._attr_extra_state_attributes = {}
|
self._attr_extra_state_attributes = {}
|
||||||
self._attr_unique_id = listener_id
|
self._attr_unique_id = listener_id
|
||||||
self._bridge_id = bridge_id
|
self._bridge_id = bridge_id
|
||||||
|
@ -322,6 +324,14 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
|
||||||
"""Return the listener related to this entity."""
|
"""Return the listener related to this entity."""
|
||||||
return self.coordinator.data.listeners[self._listener_id]
|
return self.coordinator.data.listeners[self._listener_id]
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_get_bridge(self, bridge_id: int) -> Bridge | None:
|
||||||
|
"""Get a bridge by ID (if it exists)."""
|
||||||
|
if (bridge := self.coordinator.data.bridges.get(bridge_id)) is None:
|
||||||
|
LOGGER.debug("Entity references a non-existent bridge ID: %s", bridge_id)
|
||||||
|
return None
|
||||||
|
return bridge
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_update_bridge_id(self) -> None:
|
def _async_update_bridge_id(self) -> None:
|
||||||
"""Update the entity's bridge ID if it has changed.
|
"""Update the entity's bridge ID if it has changed.
|
||||||
|
@ -330,13 +340,12 @@ class NotionEntity(CoordinatorEntity[DataUpdateCoordinator[NotionData]]):
|
||||||
"""
|
"""
|
||||||
sensor = self.coordinator.data.sensors[self._sensor_id]
|
sensor = self.coordinator.data.sensors[self._sensor_id]
|
||||||
|
|
||||||
# If the sensor's bridge ID is the same as what we had before or if it points
|
# If the bridge ID hasn't changed, return:
|
||||||
# to a bridge that doesn't exist (which can happen due to a Notion API bug),
|
if self._bridge_id == sensor.bridge.id:
|
||||||
# return immediately:
|
return
|
||||||
if (
|
|
||||||
self._bridge_id == sensor.bridge.id
|
# If the bridge doesn't exist, return:
|
||||||
or sensor.bridge.id not in self.coordinator.data.bridges
|
if (bridge := self._async_get_bridge(sensor.bridge.id)) is None:
|
||||||
):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self._bridge_id = sensor.bridge.id
|
self._bridge_id = sensor.bridge.id
|
||||||
|
|
Loading…
Reference in New Issue