Remove Shelly Wall Display switch entity only if the relay is used as the thermostat actuator (#104506)
This commit is contained in:
parent
c831802774
commit
14387cf94b
3 changed files with 23 additions and 4 deletions
|
@ -42,7 +42,12 @@ from .const import (
|
|||
)
|
||||
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
|
||||
|
|
|
@ -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", ""
|
||||
)
|
||||
|
|
|
@ -149,7 +149,12 @@ MOCK_CONFIG = {
|
|||
"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"},
|
||||
|
|
Loading…
Add table
Reference in a new issue