diff --git a/homeassistant/components/mystrom/__init__.py b/homeassistant/components/mystrom/__init__.py index 64f7dafc1b7..972db00e476 100644 --- a/homeassistant/components/mystrom/__init__.py +++ b/homeassistant/components/mystrom/__init__.py @@ -50,6 +50,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.error("No route to myStrom plug: %s", host) raise ConfigEntryNotReady() from err + info.setdefault("type", 101) + device_type = info["type"] if device_type in [101, 106, 107]: device = _get_mystrom_switch(host) diff --git a/tests/components/mystrom/__init__.py b/tests/components/mystrom/__init__.py index 8b3e2f8535f..21f6bd7a549 100644 --- a/tests/components/mystrom/__init__.py +++ b/tests/components/mystrom/__init__.py @@ -2,12 +2,11 @@ from typing import Any, Optional -def get_default_device_response(device_type: int) -> dict[str, Any]: +def get_default_device_response(device_type: int | None) -> dict[str, Any]: """Return default device response.""" - return { + response = { "version": "2.59.32", "mac": "6001940376EB", - "type": device_type, "ssid": "personal", "ip": "192.168.0.23", "mask": "255.255.255.0", @@ -17,6 +16,9 @@ def get_default_device_response(device_type: int) -> dict[str, Any]: "connected": True, "signal": 94, } + if device_type is not None: + response["type"] = device_type + return response def get_default_bulb_state() -> dict[str, Any]: diff --git a/tests/components/mystrom/test_init.py b/tests/components/mystrom/test_init.py index 281d7af9947..80011b47915 100644 --- a/tests/components/mystrom/test_init.py +++ b/tests/components/mystrom/test_init.py @@ -44,7 +44,7 @@ async def test_init_switch_and_unload( hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: """Test the initialization of a myStrom switch.""" - await init_integration(hass, config_entry, 101) + await init_integration(hass, config_entry, 106) state = hass.states.get("switch.mystrom_device") assert state is not None assert config_entry.state is ConfigEntryState.LOADED @@ -58,7 +58,7 @@ async def test_init_switch_and_unload( @pytest.mark.parametrize( ("device_type", "platform", "entry_state", "entity_state_none"), [ - (101, "switch", ConfigEntryState.LOADED, False), + (None, "switch", ConfigEntryState.LOADED, False), (102, "light", ConfigEntryState.LOADED, False), (103, "button", ConfigEntryState.SETUP_ERROR, True), (104, "button", ConfigEntryState.SETUP_ERROR, True),