mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Fix UniFi Protect doorbell messages expiring after 60 seconds (#182008)
This commit is contained in:
@@ -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, ...] = (
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user