diff --git a/homeassistant/components/axis/__init__.py b/homeassistant/components/axis/__init__.py index c2326bfa576..c4c05f1c515 100644 --- a/homeassistant/components/axis/__init__.py +++ b/homeassistant/components/axis/__init__.py @@ -25,7 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b raise ConfigEntryAuthFailed from err device = AxisNetworkDevice(hass, config_entry, api) - hass.data[AXIS_DOMAIN][config_entry.unique_id] = device + hass.data[AXIS_DOMAIN][config_entry.entry_id] = device await device.async_update_device_registry() await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS) device.async_setup_events() @@ -40,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Unload Axis device config entry.""" - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN].pop(config_entry.unique_id) + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN].pop(config_entry.entry_id) return await device.async_reset() diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index 4762e5b9152..8c3957e4d19 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -48,7 +48,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up a Axis binary sensor.""" - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id] @callback def async_create_entity(event: Event) -> None: diff --git a/homeassistant/components/axis/camera.py b/homeassistant/components/axis/camera.py index 992410d9725..b45cfc1ecc2 100644 --- a/homeassistant/components/axis/camera.py +++ b/homeassistant/components/axis/camera.py @@ -22,7 +22,7 @@ async def async_setup_entry( """Set up the Axis camera video stream.""" filter_urllib3_logging() - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id] if not device.api.vapix.params.image_format: return diff --git a/homeassistant/components/axis/config_flow.py b/homeassistant/components/axis/config_flow.py index 1fb9b9488fa..75354bb9884 100644 --- a/homeassistant/components/axis/config_flow.py +++ b/homeassistant/components/axis/config_flow.py @@ -232,7 +232,7 @@ class AxisOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry): self, user_input: dict[str, Any] | None = None ) -> FlowResult: """Manage the Axis device options.""" - self.device = self.hass.data[AXIS_DOMAIN][self.config_entry.unique_id] + self.device = self.hass.data[AXIS_DOMAIN][self.config_entry.entry_id] return await self.async_step_configure_stream() async def async_step_configure_stream( diff --git a/homeassistant/components/axis/device.py b/homeassistant/components/axis/device.py index 7eb40697b78..77901f03fc2 100644 --- a/homeassistant/components/axis/device.py +++ b/homeassistant/components/axis/device.py @@ -157,7 +157,7 @@ class AxisNetworkDevice: This is a static method because a class method (bound method), can not be used with weak references. """ - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][entry.entry_id] device.api.config.host = device.host async_dispatcher_send(hass, device.signal_new_address) diff --git a/homeassistant/components/axis/diagnostics.py b/homeassistant/components/axis/diagnostics.py index 1c805e8f35b..277f24513de 100644 --- a/homeassistant/components/axis/diagnostics.py +++ b/homeassistant/components/axis/diagnostics.py @@ -20,7 +20,7 @@ async def async_get_config_entry_diagnostics( hass: HomeAssistant, config_entry: ConfigEntry ) -> dict[str, Any]: """Return diagnostics for a config entry.""" - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id] diag: dict[str, Any] = {} diag["config"] = async_redact_data(config_entry.as_dict(), REDACT_CONFIG) diff --git a/homeassistant/components/axis/light.py b/homeassistant/components/axis/light.py index 6a6fd086780..24566b71974 100644 --- a/homeassistant/components/axis/light.py +++ b/homeassistant/components/axis/light.py @@ -19,7 +19,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up a Axis light.""" - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id] if ( device.api.vapix.light_control is None diff --git a/homeassistant/components/axis/switch.py b/homeassistant/components/axis/switch.py index 1b1165c3929..05ff8375415 100644 --- a/homeassistant/components/axis/switch.py +++ b/homeassistant/components/axis/switch.py @@ -19,7 +19,7 @@ async def async_setup_entry( async_add_entities: AddEntitiesCallback, ) -> None: """Set up a Axis switch.""" - device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device: AxisNetworkDevice = hass.data[AXIS_DOMAIN][config_entry.entry_id] @callback def async_create_entity(event: Event) -> None: diff --git a/tests/components/axis/test_config_flow.py b/tests/components/axis/test_config_flow.py index 2daf350ac93..c23731e4cd2 100644 --- a/tests/components/axis/test_config_flow.py +++ b/tests/components/axis/test_config_flow.py @@ -82,7 +82,7 @@ async def test_flow_manual_configuration(hass): async def test_manual_configuration_update_configuration(hass): """Test that config flow fails on already configured device.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] result = await hass.config_entries.flow.async_init( AXIS_DOMAIN, context={"source": SOURCE_USER} @@ -214,7 +214,7 @@ async def test_flow_create_entry_multiple_existing_entries_of_same_model(hass): async def test_reauth_flow_update_configuration(hass): """Test that config flow fails on already configured device.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] result = await hass.config_entries.flow.async_init( AXIS_DOMAIN, @@ -576,15 +576,13 @@ async def test_discovery_flow_ignore_link_local_address( async def test_option_flow(hass): """Test config flow options.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] assert device.option_stream_profile == DEFAULT_STREAM_PROFILE assert device.option_video_source == DEFAULT_VIDEO_SOURCE with respx.mock: mock_default_vapix_requests(respx) - result = await hass.config_entries.options.async_init( - device.config_entry.entry_id - ) + result = await hass.config_entries.options.async_init(config_entry.entry_id) assert result["type"] == FlowResultType.FORM assert result["step_id"] == "configure_stream" diff --git a/tests/components/axis/test_device.py b/tests/components/axis/test_device.py index 1d54904dce9..23ab093eed1 100644 --- a/tests/components/axis/test_device.py +++ b/tests/components/axis/test_device.py @@ -302,20 +302,18 @@ async def test_device_setup(hass): return_value=True, ) as forward_entry_setup: config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] assert device.api.vapix.firmware_version == "9.10.1" assert device.api.vapix.product_number == "M1065-LW" assert device.api.vapix.product_type == "Network Camera" assert device.api.vapix.serial_number == "00408C123456" - entry = device.config_entry - assert len(forward_entry_setup.mock_calls) == 4 - assert forward_entry_setup.mock_calls[0][1] == (entry, "binary_sensor") - assert forward_entry_setup.mock_calls[1][1] == (entry, "camera") - assert forward_entry_setup.mock_calls[2][1] == (entry, "light") - assert forward_entry_setup.mock_calls[3][1] == (entry, "switch") + assert forward_entry_setup.mock_calls[0][1] == (config_entry, "binary_sensor") + assert forward_entry_setup.mock_calls[1][1] == (config_entry, "camera") + assert forward_entry_setup.mock_calls[2][1] == (config_entry, "light") + assert forward_entry_setup.mock_calls[3][1] == (config_entry, "switch") assert device.host == ENTRY_CONFIG[CONF_HOST] assert device.model == ENTRY_CONFIG[CONF_MODEL] @@ -337,7 +335,7 @@ async def test_device_info(hass): with patch.dict(API_DISCOVERY_RESPONSE, api_discovery): config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] assert device.api.vapix.firmware_version == "9.80.1" assert device.api.vapix.product_number == "M1065-LW" @@ -371,7 +369,7 @@ async def test_device_support_mqtt(hass, mqtt_mock): async def test_update_address(hass): """Test update address works.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] assert device.api.config.host == "1.2.3.4" with patch( @@ -435,7 +433,7 @@ async def test_device_unavailable(hass, mock_rtsp_event, mock_rtsp_signal_state) async def test_device_reset(hass): """Successfully reset device.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] result = await device.async_reset() assert result is True diff --git a/tests/components/axis/test_init.py b/tests/components/axis/test_init.py index 3473ef831b2..92e1e9b4943 100644 --- a/tests/components/axis/test_init.py +++ b/tests/components/axis/test_init.py @@ -4,10 +4,9 @@ from unittest.mock import AsyncMock, Mock, patch from homeassistant.components import axis from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN from homeassistant.const import CONF_MAC -from homeassistant.helpers.device_registry import format_mac from homeassistant.setup import async_setup_component -from .test_device import MAC, setup_axis_integration +from .test_device import setup_axis_integration from tests.common import MockConfigEntry @@ -20,9 +19,9 @@ async def test_setup_no_config(hass): async def test_setup_entry(hass): """Test successful setup of entry.""" - await setup_axis_integration(hass) + config_entry = await setup_axis_integration(hass) assert len(hass.data[AXIS_DOMAIN]) == 1 - assert format_mac(MAC) in hass.data[AXIS_DOMAIN] + assert config_entry.entry_id in hass.data[AXIS_DOMAIN] async def test_setup_entry_fails(hass): @@ -44,10 +43,9 @@ async def test_setup_entry_fails(hass): async def test_unload_entry(hass): """Test successful unload of entry.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] assert hass.data[AXIS_DOMAIN] - assert await hass.config_entries.async_unload(device.config_entry.entry_id) + assert await hass.config_entries.async_unload(config_entry.entry_id) assert not hass.data[AXIS_DOMAIN] diff --git a/tests/components/axis/test_switch.py b/tests/components/axis/test_switch.py index 541c377d3ff..aabab54a372 100644 --- a/tests/components/axis/test_switch.py +++ b/tests/components/axis/test_switch.py @@ -41,7 +41,7 @@ async def test_no_switches(hass): async def test_switches_with_port_cgi(hass, mock_rtsp_event): """Test that switches are loaded properly using port.cgi.""" config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()} device.api.vapix.ports["0"].name = "Doorbell" @@ -103,7 +103,7 @@ async def test_switches_with_port_management( with patch.dict(API_DISCOVERY_RESPONSE, api_discovery): config_entry = await setup_axis_integration(hass) - device = hass.data[AXIS_DOMAIN][config_entry.unique_id] + device = hass.data[AXIS_DOMAIN][config_entry.entry_id] device.api.vapix.ports = {"0": AsyncMock(), "1": AsyncMock()} device.api.vapix.ports["0"].name = "Doorbell"