mirror of
https://github.com/home-assistant/core.git
synced 2025-11-13 13:00:11 +00:00
Deprecate entity_id template variable in camera services (#128592)
* Deprecate entity_id template variable in camera services * Update snapshots * Tiny lang tweak * Fix translation --------- Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
@@ -7,6 +7,7 @@ from types import ModuleType
|
||||
from unittest.mock import ANY, AsyncMock, Mock, PropertyMock, mock_open, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components import camera
|
||||
from homeassistant.components.camera.const import (
|
||||
@@ -23,7 +24,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
@@ -227,22 +228,36 @@ async def test_get_image_fails(hass: HomeAssistant) -> None:
|
||||
|
||||
@pytest.mark.usefixtures("mock_camera")
|
||||
@pytest.mark.parametrize(
|
||||
("filename_template", "expected_filename"),
|
||||
("filename_template", "expected_filename", "expected_issues"),
|
||||
[
|
||||
("/test/snapshot.jpg", "/test/snapshot.jpg"),
|
||||
(
|
||||
"/test/snapshot.jpg",
|
||||
"/test/snapshot.jpg",
|
||||
[],
|
||||
),
|
||||
(
|
||||
"/test/snapshot_{{ entity_id }}.jpg",
|
||||
"/test/snapshot_<entity camera.demo_camera=streaming>.jpg",
|
||||
["deprecated_filename_template_camera.demo_camera_snapshot"],
|
||||
),
|
||||
(
|
||||
"/test/snapshot_{{ entity_id.name }}.jpg",
|
||||
"/test/snapshot_Demo camera.jpg",
|
||||
["deprecated_filename_template_camera.demo_camera_snapshot"],
|
||||
),
|
||||
("/test/snapshot_{{ entity_id.name }}.jpg", "/test/snapshot_Demo camera.jpg"),
|
||||
(
|
||||
"/test/snapshot_{{ entity_id.entity_id }}.jpg",
|
||||
"/test/snapshot_camera.demo_camera.jpg",
|
||||
["deprecated_filename_template_camera.demo_camera_snapshot"],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_snapshot_service(
|
||||
hass: HomeAssistant, filename_template: str, expected_filename: str
|
||||
hass: HomeAssistant,
|
||||
filename_template: str,
|
||||
expected_filename: str,
|
||||
expected_issues: list,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test snapshot service."""
|
||||
mopen = mock_open()
|
||||
@@ -271,6 +286,13 @@ async def test_snapshot_service(
|
||||
assert len(mock_write.mock_calls) == 1
|
||||
assert mock_write.mock_calls[0][1][0] == b"Test"
|
||||
|
||||
issue_registry = ir.async_get(hass)
|
||||
assert len(issue_registry.issues) == 1 + len(expected_issues)
|
||||
for expected_issue in expected_issues:
|
||||
issue = issue_registry.async_get_issue(DOMAIN, expected_issue)
|
||||
assert issue is not None
|
||||
assert issue == snapshot
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_camera")
|
||||
async def test_snapshot_service_not_allowed_path(hass: HomeAssistant) -> None:
|
||||
@@ -602,22 +624,32 @@ async def test_record_service_invalid_path(hass: HomeAssistant) -> None:
|
||||
|
||||
@pytest.mark.usefixtures("mock_camera", "mock_stream")
|
||||
@pytest.mark.parametrize(
|
||||
("filename_template", "expected_filename"),
|
||||
("filename_template", "expected_filename", "expected_issues"),
|
||||
[
|
||||
("/test/recording.mpg", "/test/recording.mpg"),
|
||||
("/test/recording.mpg", "/test/recording.mpg", []),
|
||||
(
|
||||
"/test/recording_{{ entity_id }}.mpg",
|
||||
"/test/recording_<entity camera.demo_camera=streaming>.mpg",
|
||||
["deprecated_filename_template_camera.demo_camera_record"],
|
||||
),
|
||||
(
|
||||
"/test/recording_{{ entity_id.name }}.mpg",
|
||||
"/test/recording_Demo camera.mpg",
|
||||
["deprecated_filename_template_camera.demo_camera_record"],
|
||||
),
|
||||
("/test/recording_{{ entity_id.name }}.mpg", "/test/recording_Demo camera.mpg"),
|
||||
(
|
||||
"/test/recording_{{ entity_id.entity_id }}.mpg",
|
||||
"/test/recording_camera.demo_camera.mpg",
|
||||
["deprecated_filename_template_camera.demo_camera_record"],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_record_service(
|
||||
hass: HomeAssistant, filename_template: str, expected_filename: str
|
||||
hass: HomeAssistant,
|
||||
filename_template: str,
|
||||
expected_filename: str,
|
||||
expected_issues: list,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test record service."""
|
||||
with (
|
||||
@@ -646,6 +678,13 @@ async def test_record_service(
|
||||
ANY, expected_filename, duration=30, lookback=0
|
||||
)
|
||||
|
||||
issue_registry = ir.async_get(hass)
|
||||
assert len(issue_registry.issues) == 1 + len(expected_issues)
|
||||
for expected_issue in expected_issues:
|
||||
issue = issue_registry.async_get_issue(DOMAIN, expected_issue)
|
||||
assert issue is not None
|
||||
assert issue == snapshot
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_camera")
|
||||
async def test_camera_proxy_stream(hass_client: ClientSessionGenerator) -> None:
|
||||
|
||||
Reference in New Issue
Block a user