From ce3502291da758155df31d1160f1da74d9f8d38b Mon Sep 17 00:00:00 2001 From: Christopher Bailey Date: Mon, 22 Aug 2022 20:58:31 -0400 Subject: [PATCH] Add better support for UniFi Protect Cameras with Removable Lens (#76942) --- homeassistant/components/unifiprotect/camera.py | 5 +++++ homeassistant/components/unifiprotect/sensor.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/homeassistant/components/unifiprotect/camera.py b/homeassistant/components/unifiprotect/camera.py index 76bfc72408d..bff8af7be98 100644 --- a/homeassistant/components/unifiprotect/camera.py +++ b/homeassistant/components/unifiprotect/camera.py @@ -190,6 +190,11 @@ class ProtectCamera(ProtectDeviceEntity, Camera): self._attr_is_recording = ( self.device.state == StateType.CONNECTED and self.device.is_recording ) + is_connected = ( + self.data.last_update_success and self.device.state == StateType.CONNECTED + ) + # some cameras have detachable lens that could cause the camera to be offline + self._attr_available = is_connected and self.device.is_video_ready self._async_set_stream_source() self._attr_extra_state_attributes = { diff --git a/homeassistant/components/unifiprotect/sensor.py b/homeassistant/components/unifiprotect/sensor.py index 7a9f4652a2e..3dac8e46aee 100644 --- a/homeassistant/components/unifiprotect/sensor.py +++ b/homeassistant/components/unifiprotect/sensor.py @@ -200,6 +200,14 @@ CAMERA_SENSORS: tuple[ProtectSensorEntityDescription, ...] = ( ufp_value="last_ring", entity_registry_enabled_default=False, ), + ProtectSensorEntityDescription( + key="lens_type", + name="Lens Type", + entity_category=EntityCategory.DIAGNOSTIC, + icon="mdi:camera-iris", + ufp_required_field="has_removable_lens", + ufp_value="feature_flags.lens_type", + ), ProtectSensorEntityDescription( key="mic_level", name="Microphone Level",