Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Shelly Wall Display switch entity only if the relay is used as the thermostat actuator #104506

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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