From b73be2df6e4e12fc5116adc5c7edffbab3e64259 Mon Sep 17 00:00:00 2001 From: Bouwe Westerdijk <11290930+bouwew@users.noreply.github.com> Date: Mon, 16 Sep 2024 20:01:12 +0200 Subject: [PATCH] Implement model_id's in Plugwise (#126069) --- homeassistant/components/plugwise/__init__.py | 3 ++- homeassistant/components/plugwise/entity.py | 1 + tests/components/plugwise/conftest.py | 11 ++++++++++ tests/components/plugwise/test_init.py | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/plugwise/__init__.py b/homeassistant/components/plugwise/__init__.py index de2250ac72e0d..f7677e39f7a9d 100644 --- a/homeassistant/components/plugwise/__init__.py +++ b/homeassistant/components/plugwise/__init__.py @@ -31,9 +31,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: PlugwiseConfigEntry) -> identifiers={(DOMAIN, str(coordinator.api.gateway_id))}, manufacturer="Plugwise", model=coordinator.api.smile_model, + model_id=coordinator.api.smile_model_id, name=coordinator.api.smile_name, sw_version=coordinator.api.smile_version[0], - ) + ) # required for adding the entity-less P1 Gateway await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/homeassistant/components/plugwise/entity.py b/homeassistant/components/plugwise/entity.py index b2562ef8f396c..e24f3d1e1bb2f 100644 --- a/homeassistant/components/plugwise/entity.py +++ b/homeassistant/components/plugwise/entity.py @@ -47,6 +47,7 @@ def __init__( connections=connections, manufacturer=data.get("vendor"), model=data.get("model"), + model_id=data.get("model_id"), name=coordinator.data.gateway["smile_name"], sw_version=data.get("firmware"), hw_version=data.get("hardware"), diff --git a/tests/components/plugwise/conftest.py b/tests/components/plugwise/conftest.py index ec857a965e59a..825a82e75959a 100644 --- a/tests/components/plugwise/conftest.py +++ b/tests/components/plugwise/conftest.py @@ -65,6 +65,7 @@ def mock_smile_config_flow() -> Generator[MagicMock]: smile = smile_mock.return_value smile.smile_hostname = "smile12345" smile.smile_model = "Test Model" + smile.smile_model_id = "Test Model ID" smile.smile_name = "Test Smile Name" smile.connect.return_value = True yield smile @@ -86,6 +87,7 @@ def mock_smile_adam() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_open_therm" smile.smile_name = "Adam" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -112,6 +114,7 @@ def mock_smile_adam_2() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_open_therm" smile.smile_name = "Adam" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -138,6 +141,7 @@ def mock_smile_adam_3() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_open_therm" smile.smile_name = "Adam" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -164,6 +168,7 @@ def mock_smile_adam_4() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_open_therm" smile.smile_name = "Adam" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -189,6 +194,7 @@ def mock_smile_anna() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_thermo" smile.smile_name = "Smile Anna" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -214,6 +220,7 @@ def mock_smile_anna_2() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_thermo" smile.smile_name = "Smile Anna" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -239,6 +246,7 @@ def mock_smile_anna_3() -> Generator[MagicMock]: smile.smile_type = "thermostat" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile_thermo" smile.smile_name = "Smile Anna" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -264,6 +272,7 @@ def mock_smile_p1() -> Generator[MagicMock]: smile.smile_type = "power" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile" smile.smile_name = "Smile P1" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -289,6 +298,7 @@ def mock_smile_p1_2() -> Generator[MagicMock]: smile.smile_type = "power" smile.smile_hostname = "smile98765" smile.smile_model = "Gateway" + smile.smile_model_id = "smile" smile.smile_name = "Smile P1" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") @@ -314,6 +324,7 @@ def mock_stretch() -> Generator[MagicMock]: smile.smile_type = "stretch" smile.smile_hostname = "stretch98765" smile.smile_model = "Gateway" + smile.smile_model_id = None smile.smile_name = "Stretch" smile.connect.return_value = True all_data = _read_json(chosen_env, "all_data") diff --git a/tests/components/plugwise/test_init.py b/tests/components/plugwise/test_init.py index 46ef7b89d0948..65c9fb6c5a5ec 100644 --- a/tests/components/plugwise/test_init.py +++ b/tests/components/plugwise/test_init.py @@ -110,6 +110,28 @@ async def test_gateway_config_entry_not_ready( assert mock_config_entry.state is entry_state +async def test_device_in_dr( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_smile_p1: MagicMock, + device_registry: dr.DeviceRegistry, +) -> None: + """Test Gateway device registry data.""" + mock_config_entry.add_to_hass(hass) + assert await async_setup_component(hass, DOMAIN, {}) + await hass.async_block_till_done() + + device_entry = device_registry.async_get_device( + identifiers={(DOMAIN, "a455b61e52394b2db5081ce025a430f3")} + ) + assert device_entry.hw_version == "AME Smile 2.0 board" + assert device_entry.manufacturer == "Plugwise" + assert device_entry.model == "Gateway" + assert device_entry.model_id == "smile" + assert device_entry.name == "Smile P1" + assert device_entry.sw_version == "4.4.2" + + @pytest.mark.parametrize( ("entitydata", "old_unique_id", "new_unique_id"), [