Fix UniFi Protect doorbell messages expiring after 60 seconds (#182008)

This commit is contained in:
Raphael Hehl
2026-09-12 17:40:23 +02:00
committed by GitHub
parent 2f79d1fd2a
commit 3a74193c41
4 changed files with 19 additions and 30 deletions
@@ -192,15 +192,14 @@ async def _set_paired_camera(obj: Light | Sensor, camera_id: str) -> None:
async def _set_doorbell_message(obj: Camera, message: str) -> None:
if message.startswith(DoorbellMessageType.CUSTOM_MESSAGE.value):
message = message.rsplit(":", maxsplit=1)[-1]
# reset_at=None keeps the message up until it is changed
await obj.set_lcd_message_public(
DoorbellMessageType.CUSTOM_MESSAGE, text=message
DoorbellMessageType.CUSTOM_MESSAGE, text=message, reset_at=None
)
elif message == TYPE_EMPTY_VALUE:
# Public API has no endpoint to clear the LCD message; fall back to
# the non-deprecated legacy helper.
await obj.set_lcd_text(None)
await obj.set_lcd_message_public(None)
else:
await obj.set_lcd_message_public(DoorbellMessageType(message))
await obj.set_lcd_message_public(DoorbellMessageType(message), reset_at=None)
async def _set_liveview(obj: Viewer, liveview_id: str) -> None:
@@ -42,7 +42,10 @@ def _get_doorbell_current(obj: Camera) -> str | None:
async def _set_doorbell_message(obj: Camera, message: str) -> None:
await obj.set_lcd_text(DoorbellMessageType.CUSTOM_MESSAGE, text=message)
# reset_at=None keeps the message up until it is changed
await obj.set_lcd_message_public(
DoorbellMessageType.CUSTOM_MESSAGE, text=message, reset_at=None
)
CAMERA: tuple[ProtectTextEntityDescription, ...] = (
+9 -22
View File
@@ -649,8 +649,10 @@ async def test_select_set_option_camera_doorbell_custom(
blocking=True,
)
# reset_at=None keeps the message up; omitting it lets the NVR
# clear it after its own timeout
mock_method.assert_called_once_with(
DoorbellMessageType.CUSTOM_MESSAGE, text="Test"
DoorbellMessageType.CUSTOM_MESSAGE, text="Test", reset_at=None
)
@@ -666,14 +668,9 @@ async def test_select_set_option_camera_doorbell_unifi(
hass, Platform.SELECT, doorbell, CAMERA_SELECTS[2]
)
with (
patch_ufp_method(
doorbell, "set_lcd_message_public", new_callable=AsyncMock
) as mock_public,
patch_ufp_method(
doorbell, "set_lcd_text", new_callable=AsyncMock
) as mock_legacy,
):
with patch_ufp_method(
doorbell, "set_lcd_message_public", new_callable=AsyncMock
) as mock_method:
await hass.services.async_call(
"select",
"select_option",
@@ -684,20 +681,10 @@ async def test_select_set_option_camera_doorbell_unifi(
blocking=True,
)
mock_public.assert_called_once_with(DoorbellMessageType.LEAVE_PACKAGE_AT_DOOR)
await hass.services.async_call(
"select",
"select_option",
{
ATTR_ENTITY_ID: entity_id,
ATTR_OPTION: "Default Message (Welcome)",
},
blocking=True,
mock_method.assert_called_once_with(
DoorbellMessageType.LEAVE_PACKAGE_AT_DOOR, reset_at=None
)
mock_legacy.assert_called_once_with(None)
async def test_select_set_option_camera_doorbell_default(
hass: HomeAssistant, ufp: MockUFPFixture, doorbell: Camera
@@ -712,7 +699,7 @@ async def test_select_set_option_camera_doorbell_default(
)
with patch_ufp_method(
doorbell, "set_lcd_text", new_callable=AsyncMock
doorbell, "set_lcd_message_public", new_callable=AsyncMock
) as mock_method:
await hass.services.async_call(
"select",
+2 -2
View File
@@ -78,7 +78,7 @@ async def test_text_camera_set(
)
with patch_ufp_method(
doorbell, "set_lcd_text", new_callable=AsyncMock
doorbell, "set_lcd_message_public", new_callable=AsyncMock
) as mock_method:
await hass.services.async_call(
"text",
@@ -88,5 +88,5 @@ async def test_text_camera_set(
)
mock_method.assert_called_once_with(
DoorbellMessageType.CUSTOM_MESSAGE, text="Test test"
DoorbellMessageType.CUSTOM_MESSAGE, text="Test test", reset_at=None
)