diff --git a/tests/components/axis/const.py b/tests/components/axis/const.py index 16b9d17f99e..2efb464efd7 100644 --- a/tests/components/axis/const.py +++ b/tests/components/axis/const.py @@ -4,8 +4,8 @@ from axis.models.api import CONTEXT MAC = "00408C123456" FORMATTED_MAC = "00:40:8c:12:34:56" -MODEL = "model" -NAME = "name" +MODEL = "A1234" +NAME = "home" DEFAULT_HOST = "1.2.3.4" diff --git a/tests/components/axis/snapshots/test_diagnostics.ambr b/tests/components/axis/snapshots/test_diagnostics.ambr index 8ea316d00cf..3a643f55d3e 100644 --- a/tests/components/axis/snapshots/test_diagnostics.ambr +++ b/tests/components/axis/snapshots/test_diagnostics.ambr @@ -30,8 +30,8 @@ 'config': dict({ 'data': dict({ 'host': '1.2.3.4', - 'model': 'model', - 'name': 'name', + 'model': 'A1234', + 'name': 'home', 'password': '**REDACTED**', 'port': 80, 'username': '**REDACTED**', diff --git a/tests/components/axis/snapshots/test_hub.ambr b/tests/components/axis/snapshots/test_hub.ambr new file mode 100644 index 00000000000..16579287f09 --- /dev/null +++ b/tests/components/axis/snapshots/test_hub.ambr @@ -0,0 +1,73 @@ +# serializer version: 1 +# name: test_device_registry_entry[api_discovery_items0] + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'configuration_url': 'http://1.2.3.4:80', + 'connections': set({ + tuple( + 'mac', + '00:40:8c:12:34:56', + ), + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'axis', + '00:40:8c:12:34:56', + ), + }), + 'is_new': False, + 'labels': set({ + }), + 'manufacturer': 'Axis Communications AB', + 'model': 'A1234 Network Camera', + 'model_id': None, + 'name': 'home', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': '00:40:8c:12:34:56', + 'suggested_area': None, + 'sw_version': '9.10.1', + 'via_device_id': None, + }) +# --- +# name: test_device_registry_entry[api_discovery_items1] + DeviceRegistryEntrySnapshot({ + 'area_id': None, + 'config_entries': , + 'configuration_url': 'http://1.2.3.4:80', + 'connections': set({ + tuple( + 'mac', + '00:40:8c:12:34:56', + ), + }), + 'disabled_by': None, + 'entry_type': None, + 'hw_version': None, + 'id': , + 'identifiers': set({ + tuple( + 'axis', + '00:40:8c:12:34:56', + ), + }), + 'is_new': False, + 'labels': set({ + }), + 'manufacturer': 'Axis Communications AB', + 'model': 'A1234 Network Camera', + 'model_id': None, + 'name': 'home', + 'name_by_user': None, + 'primary_config_entry': , + 'serial_number': '00:40:8c:12:34:56', + 'suggested_area': None, + 'sw_version': '9.80.1', + 'via_device_id': None, + }) +# --- diff --git a/tests/components/axis/test_hub.py b/tests/components/axis/test_hub.py index 012cef3bc5b..a28f6f4dabc 100644 --- a/tests/components/axis/test_hub.py +++ b/tests/components/axis/test_hub.py @@ -1,27 +1,21 @@ """Test Axis device.""" -from collections.abc import Callable, Generator +from collections.abc import Callable from ipaddress import ip_address from types import MappingProxyType from typing import Any from unittest import mock -from unittest.mock import ANY, AsyncMock, Mock, call, patch +from unittest.mock import ANY, Mock, call, patch import axis as axislib import pytest +from syrupy import SnapshotAssertion from homeassistant.components import axis, zeroconf from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigEntry -from homeassistant.const import ( - CONF_HOST, - CONF_MODEL, - CONF_NAME, - STATE_OFF, - STATE_ON, - STATE_UNAVAILABLE, -) +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr @@ -38,54 +32,19 @@ from tests.common import async_fire_mqtt_message from tests.typing import MqttMockHAClient -@pytest.fixture(name="forward_entry_setups") -def hass_mock_forward_entry_setup(hass: HomeAssistant) -> Generator[AsyncMock]: - """Mock async_forward_entry_setups.""" - with patch.object( - hass.config_entries, "async_forward_entry_setups" - ) as forward_mock: - yield forward_mock - - -async def test_device_setup( - forward_entry_setups: AsyncMock, - config_entry_data: MappingProxyType[str, Any], +@pytest.mark.parametrize( + "api_discovery_items", [({}), (API_DISCOVERY_BASIC_DEVICE_INFO)] +) +async def test_device_registry_entry( config_entry_setup: ConfigEntry, device_registry: dr.DeviceRegistry, + snapshot: SnapshotAssertion, ) -> None: """Successful setup.""" - hub = config_entry_setup.runtime_data - - assert hub.api.vapix.firmware_version == "9.10.1" - assert hub.api.vapix.product_number == "M1065-LW" - assert hub.api.vapix.product_type == "Network Camera" - assert hub.api.vapix.serial_number == "00408C123456" - - assert len(forward_entry_setups.mock_calls) == 1 - platforms = set(forward_entry_setups.mock_calls[0][1][1]) - assert platforms == {"binary_sensor", "camera", "light", "switch"} - - assert hub.config.host == config_entry_data[CONF_HOST] - assert hub.config.model == config_entry_data[CONF_MODEL] - assert hub.config.name == config_entry_data[CONF_NAME] - assert hub.unique_id == FORMATTED_MAC - device_entry = device_registry.async_get_device( - identifiers={(AXIS_DOMAIN, hub.unique_id)} + identifiers={(AXIS_DOMAIN, config_entry_setup.unique_id)} ) - - assert device_entry.configuration_url == hub.api.config.url - - -@pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_BASIC_DEVICE_INFO]) -async def test_device_info(config_entry_setup: ConfigEntry) -> None: - """Verify other path of device information works.""" - hub = config_entry_setup.runtime_data - - assert hub.api.vapix.firmware_version == "9.80.1" - assert hub.api.vapix.product_number == "M1065-LW" - assert hub.api.vapix.product_type == "Network Camera" - assert hub.api.vapix.serial_number == "00408C123456" + assert device_entry == snapshot @pytest.mark.parametrize("api_discovery_items", [API_DISCOVERY_MQTT])