Skip to content

Commit

Permalink
Remove Shelly Wall Display switch entity only if the relay is used as…
Browse files Browse the repository at this point in the history
… the thermostat actuator (#104506)
  • Loading branch information
bieniu committed Nov 26, 2023
1 parent c831802 commit 14387cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
13 changes: 10 additions & 3 deletions homeassistant/components/shelly/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/shelly/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""
)
7 changes: 6 additions & 1 deletion tests/components/shelly/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit 14387cf

Please sign in to comment.