From 14387cf94b65b686b4cbe5f6d11970e45619172d Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sun, 26 Nov 2023 14:46:29 +0100 Subject: [PATCH] Remove Shelly Wall Display switch entity only if the relay is used as the thermostat actuator (#104506) --- homeassistant/components/shelly/climate.py | 13 ++++++++++--- homeassistant/components/shelly/utils.py | 7 +++++++ tests/components/shelly/conftest.py | 7 ++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/shelly/climate.py b/homeassistant/components/shelly/climate.py index dbc4960af58934..d855e8b238bfcb 100644 --- a/homeassistant/components/shelly/climate.py +++ b/homeassistant/components/shelly/climate.py @@ -42,7 +42,12 @@ ) from .coordinator import ShellyBlockCoordinator, ShellyRpcCoordinator, get_entry_data from .entity import ShellyRpcEntity -from .utils import async_remove_shelly_entity, get_device_entry_gen, get_rpc_key_ids +from .utils import ( + async_remove_shelly_entity, + get_device_entry_gen, + get_rpc_key_ids, + is_relay_used_as_actuator, +) async def async_setup_entry( @@ -125,8 +130,10 @@ def async_setup_rpc_entry( climate_ids = [] for id_ in climate_key_ids: climate_ids.append(id_) - unique_id = f"{coordinator.mac}-switch:{id_}" - async_remove_shelly_entity(hass, "switch", unique_id) + + if is_relay_used_as_actuator(id_, coordinator.mac, coordinator.device.config): + unique_id = f"{coordinator.mac}-switch:{id_}" + async_remove_shelly_entity(hass, "switch", unique_id) if not climate_ids: return diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 6b5c59f28dbd6c..0209dc63aa86e5 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -430,3 +430,10 @@ def get_release_url(gen: int, model: str, beta: bool) -> str | None: return None return GEN1_RELEASE_URL if gen == 1 else GEN2_RELEASE_URL + + +def is_relay_used_as_actuator(relay_id: int, mac: str, config: dict[str, Any]) -> bool: + """Return True if an internal relay is used as the thermostat actuator.""" + return f"{mac}/c/switch:{relay_id}".lower() in config[f"thermostat:{relay_id}"].get( + "actuator", "" + ) diff --git a/tests/components/shelly/conftest.py b/tests/components/shelly/conftest.py index aeeaf9242a1f42..1662405dc80600 100644 --- a/tests/components/shelly/conftest.py +++ b/tests/components/shelly/conftest.py @@ -149,7 +149,12 @@ def mock_light_set_state( "light:0": {"name": "test light_0"}, "switch:0": {"name": "test switch_0"}, "cover:0": {"name": "test cover_0"}, - "thermostat:0": {"id": 0, "enable": True, "type": "heating"}, + "thermostat:0": { + "id": 0, + "enable": True, + "type": "heating", + "actuator": f"shelly://shellywalldisplay-{MOCK_MAC.lower()}/c/switch:0", + }, "sys": { "ui_data": {}, "device": {"name": "Test name"},