Use identity checks for unifiprotect enums (#106795)
enums are singletons in this case and there is no need to use the slower equality checks herepull/105955/head
parent
85cdbb5ade
commit
bc539a946f
|
@ -191,13 +191,11 @@ class ProtectCamera(ProtectDeviceEntity, Camera):
|
|||
self._attr_motion_detection_enabled = (
|
||||
motion_enabled if motion_enabled is not None else True
|
||||
)
|
||||
state_type_is_connected = updated_device.state is StateType.CONNECTED
|
||||
self._attr_is_recording = (
|
||||
updated_device.state == StateType.CONNECTED and updated_device.is_recording
|
||||
)
|
||||
is_connected = (
|
||||
self.data.last_update_success
|
||||
and updated_device.state == StateType.CONNECTED
|
||||
state_type_is_connected and updated_device.is_recording
|
||||
)
|
||||
is_connected = self.data.last_update_success and state_type_is_connected
|
||||
# some cameras have detachable lens that could cause the camera to be offline
|
||||
self._attr_available = is_connected and updated_device.is_video_ready
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ class ProtectData:
|
|||
) -> None:
|
||||
self._async_signal_device_update(device)
|
||||
if (
|
||||
device.model == ModelType.CAMERA
|
||||
device.model is ModelType.CAMERA
|
||||
and device.id in self._pending_camera_ids
|
||||
and "channels" in changed_data
|
||||
):
|
||||
|
@ -249,7 +249,7 @@ class ProtectData:
|
|||
obj.id,
|
||||
)
|
||||
|
||||
if obj.type == EventType.DEVICE_ADOPTED:
|
||||
if obj.type is EventType.DEVICE_ADOPTED:
|
||||
if obj.metadata is not None and obj.metadata.device_id is not None:
|
||||
device = self.api.bootstrap.get_device_from_id(
|
||||
obj.metadata.device_id
|
||||
|
|
|
@ -80,12 +80,12 @@ def _async_device_entities(
|
|||
can_write = device.can_write(data.api.bootstrap.auth_user)
|
||||
for description in descs:
|
||||
if description.ufp_perm is not None:
|
||||
if description.ufp_perm == PermRequired.WRITE and not can_write:
|
||||
if description.ufp_perm is PermRequired.WRITE and not can_write:
|
||||
continue
|
||||
if description.ufp_perm == PermRequired.NO_WRITE and can_write:
|
||||
if description.ufp_perm is PermRequired.NO_WRITE and can_write:
|
||||
continue
|
||||
if (
|
||||
description.ufp_perm == PermRequired.DELETE
|
||||
description.ufp_perm is PermRequired.DELETE
|
||||
and not device.can_delete(data.api.bootstrap.auth_user)
|
||||
):
|
||||
continue
|
||||
|
@ -157,17 +157,17 @@ def async_all_device_entities(
|
|||
)
|
||||
|
||||
descs = []
|
||||
if ufp_device.model == ModelType.CAMERA:
|
||||
if ufp_device.model is ModelType.CAMERA:
|
||||
descs = camera_descs
|
||||
elif ufp_device.model == ModelType.LIGHT:
|
||||
elif ufp_device.model is ModelType.LIGHT:
|
||||
descs = light_descs
|
||||
elif ufp_device.model == ModelType.SENSOR:
|
||||
elif ufp_device.model is ModelType.SENSOR:
|
||||
descs = sense_descs
|
||||
elif ufp_device.model == ModelType.VIEWPORT:
|
||||
elif ufp_device.model is ModelType.VIEWPORT:
|
||||
descs = viewer_descs
|
||||
elif ufp_device.model == ModelType.DOORLOCK:
|
||||
elif ufp_device.model is ModelType.DOORLOCK:
|
||||
descs = lock_descs
|
||||
elif ufp_device.model == ModelType.CHIME:
|
||||
elif ufp_device.model is ModelType.CHIME:
|
||||
descs = chime_descs
|
||||
|
||||
if not descs and not unadopted_descs or ufp_device.model is None:
|
||||
|
@ -249,7 +249,7 @@ class ProtectDeviceEntity(Entity):
|
|||
self._attr_available = (
|
||||
last_update_success
|
||||
and (
|
||||
device.state == StateType.CONNECTED
|
||||
device.state is StateType.CONNECTED
|
||||
or (not device.is_adopted_by_us and device.can_adopt)
|
||||
)
|
||||
and (not async_get_ufp_enabled or async_get_ufp_enabled(device))
|
||||
|
|
|
@ -34,7 +34,7 @@ async def async_setup_entry(
|
|||
data: ProtectData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async def _add_new_device(device: ProtectAdoptableDeviceModel) -> None:
|
||||
if device.model == ModelType.LIGHT and device.can_write(
|
||||
if device.model is ModelType.LIGHT and device.can_write(
|
||||
data.api.bootstrap.auth_user
|
||||
):
|
||||
async_add_entities([ProtectLight(data, device)])
|
||||
|
|
|
@ -79,11 +79,11 @@ class ProtectLock(ProtectDeviceEntity, LockEntity):
|
|||
self._attr_is_locking = False
|
||||
self._attr_is_unlocking = False
|
||||
self._attr_is_jammed = False
|
||||
if lock_status == LockStatusType.CLOSED:
|
||||
if lock_status is LockStatusType.CLOSED:
|
||||
self._attr_is_locked = True
|
||||
elif lock_status == LockStatusType.CLOSING:
|
||||
elif lock_status is LockStatusType.CLOSING:
|
||||
self._attr_is_locking = True
|
||||
elif lock_status == LockStatusType.OPENING:
|
||||
elif lock_status is LockStatusType.OPENING:
|
||||
self._attr_is_unlocking = True
|
||||
elif lock_status in (
|
||||
LockStatusType.FAILED_WHILE_CLOSING,
|
||||
|
|
|
@ -110,7 +110,7 @@ class ProtectMediaPlayer(ProtectDeviceEntity, MediaPlayerEntity):
|
|||
self._attr_state = MediaPlayerState.IDLE
|
||||
|
||||
is_connected = self.data.last_update_success and (
|
||||
updated_device.state == StateType.CONNECTED
|
||||
updated_device.state is StateType.CONNECTED
|
||||
or (not updated_device.is_adopted_by_us and updated_device.can_adopt)
|
||||
)
|
||||
self._attr_available = is_connected and updated_device.feature_flags.has_speaker
|
||||
|
|
|
@ -116,7 +116,7 @@ def _get_doorbell_options(api: ProtectApiClient) -> list[dict[str, Any]]:
|
|||
|
||||
for item in messages:
|
||||
msg_type = item.type.value
|
||||
if item.type == DoorbellMessageType.CUSTOM_MESSAGE:
|
||||
if item.type is DoorbellMessageType.CUSTOM_MESSAGE:
|
||||
msg_type = f"{DoorbellMessageType.CUSTOM_MESSAGE.value}:{item.text}"
|
||||
|
||||
built_messages.append({"id": msg_type, "name": item.text})
|
||||
|
|
|
@ -111,8 +111,8 @@ def async_get_light_motion_current(obj: Light) -> str:
|
|||
"""Get light motion mode for Flood Light."""
|
||||
|
||||
if (
|
||||
obj.light_mode_settings.mode == LightModeType.MOTION
|
||||
and obj.light_mode_settings.enable_at == LightModeEnableType.DARK
|
||||
obj.light_mode_settings.mode is LightModeType.MOTION
|
||||
and obj.light_mode_settings.enable_at is LightModeEnableType.DARK
|
||||
):
|
||||
return f"{LightModeType.MOTION.value}Dark"
|
||||
return obj.light_mode_settings.mode.value
|
||||
|
|
Loading…
Reference in New Issue