diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index 481d51ec529e..dc579ad6b7c1 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -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 diff --git a/homeassistant/components/unifiprotect/data.py b/homeassistant/components/unifiprotect/data.py index 8b8ec80c5ba5..11782c42bee2 100644 --- a/homeassistant/components/unifiprotect/data.py +++ b/homeassistant/components/unifiprotect/data.py @@ -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 diff --git a/homeassistant/components/unifiprotect/entity.py b/homeassistant/components/unifiprotect/entity.py index 28149d349c9a..00160005fe0e 100644 --- a/homeassistant/components/unifiprotect/entity.py +++ b/homeassistant/components/unifiprotect/entity.py @@ -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)) diff --git a/homeassistant/components/unifiprotect/light.py b/homeassistant/components/unifiprotect/light.py index 38ce73828c27..6cc56009cead 100644 --- a/homeassistant/components/unifiprotect/light.py +++ b/homeassistant/components/unifiprotect/light.py @@ -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)]) diff --git a/homeassistant/components/unifiprotect/lock.py b/homeassistant/components/unifiprotect/lock.py index 791a5e958eaf..2b7ce4f11473 100644 --- a/homeassistant/components/unifiprotect/lock.py +++ b/homeassistant/components/unifiprotect/lock.py @@ -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, diff --git a/homeassistant/components/unifiprotect/media_player.py b/homeassistant/components/unifiprotect/media_player.py index b2376277e6f8..5daac033048f 100644 --- a/homeassistant/components/unifiprotect/media_player.py +++ b/homeassistant/components/unifiprotect/media_player.py @@ -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 diff --git a/homeassistant/components/unifiprotect/select.py b/homeassistant/components/unifiprotect/select.py index dfc3be2d4a11..ecbc22f57874 100644 --- a/homeassistant/components/unifiprotect/select.py +++ b/homeassistant/components/unifiprotect/select.py @@ -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}) diff --git a/homeassistant/components/unifiprotect/utils.py b/homeassistant/components/unifiprotect/utils.py index 3e2b5e1b19e1..f07e1eb9554f 100644 --- a/homeassistant/components/unifiprotect/utils.py +++ b/homeassistant/components/unifiprotect/utils.py @@ -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