Use default MyStrom devicetype if not present (#96070)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Joost Lekkerkerker 2023-07-08 17:10:51 +02:00 committed by GitHub
parent 598610e313
commit 2c9910d9b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -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)

View File

@ -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]:

View File

@ -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),