Guard type checking assertions in unifiprotect (#96721)

pull/96727/head
J. Nick Koston 2023-07-16 12:11:35 -10:00 committed by GitHub
parent 1e9a5e48c3
commit 194d4e4f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -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