From 194d4e4f66d6307b6b158b1effd408d0ed6c44e0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 16 Jul 2023 12:11:35 -1000 Subject: [PATCH] Guard type checking assertions in unifiprotect (#96721) --- homeassistant/components/unifiprotect/entity.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/unifiprotect/entity.py b/homeassistant/components/unifiprotect/entity.py index fa85a0629cb..a8a4c78465d 100644 --- a/homeassistant/components/unifiprotect/entity.py +++ b/homeassistant/components/unifiprotect/entity.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Callable, Sequence import logging -from typing import Any +from typing import TYPE_CHECKING, Any from pyunifiprotect.data import ( NVR, @@ -57,7 +57,8 @@ def _async_device_entities( else data.get_by_types({model_type}, ignore_unadopted=False) ) for device in devices: - assert isinstance(device, (Camera, Light, Sensor, Viewer, Doorlock, Chime)) + if TYPE_CHECKING: + assert isinstance(device, (Camera, Light, Sensor, Viewer, Doorlock, Chime)) if not device.is_adopted_by_us: for description in unadopted_descs: entities.append( @@ -237,7 +238,8 @@ class ProtectDeviceEntity(Entity): @callback def _async_update_device_from_protect(self, device: ProtectModelWithId) -> None: """Update Entity object from Protect device.""" - assert isinstance(device, ProtectAdoptableDeviceModel) + if TYPE_CHECKING: + assert isinstance(device, ProtectAdoptableDeviceModel) if last_update_success := self.data.last_update_success: self.device = device