Fix climate entity creation when Shelly WallDisplay uses external relay as actuator (#115216)

* Fix climate entity creation when Shelly WallDisplay uses external relay as actuator

* More comments

* Wrap condition into function

---------

Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
Maciej Bieniek
2024-04-27 07:27:27 +00:00
committed by Paulus Schoutsen
co-authored by Maciej Bieniek
parent 0c44051d2a
commit c65187cbfb
5 changed files with 62 additions and 6 deletions
+39 -1
View File
@@ -25,7 +25,12 @@ from homeassistant.components.climate import (
from homeassistant.components.shelly.const import DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_TEMPERATURE,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant, State
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
from homeassistant.helpers.device_registry import DeviceRegistry
@@ -711,3 +716,36 @@ async def test_wall_display_thermostat_mode(
entry = entity_registry.async_get(climate_entity_id)
assert entry
assert entry.unique_id == "123456789ABC-thermostat:0"
async def test_wall_display_thermostat_mode_external_actuator(
hass: HomeAssistant,
mock_rpc_device: Mock,
entity_registry: EntityRegistry,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Test Wall Display in thermostat mode with an external actuator."""
climate_entity_id = "climate.test_name"
switch_entity_id = "switch.test_switch_0"
new_status = deepcopy(mock_rpc_device.status)
new_status["sys"]["relay_in_thermostat"] = False
monkeypatch.setattr(mock_rpc_device, "status", new_status)
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
# the switch entity should be created
state = hass.states.get(switch_entity_id)
assert state
assert state.state == STATE_ON
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
# the climate entity should be created
state = hass.states.get(climate_entity_id)
assert state
assert state.state == HVACMode.HEAT
assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1
entry = entity_registry.async_get(climate_entity_id)
assert entry
assert entry.unique_id == "123456789ABC-thermostat:0"
+1
View File
@@ -330,6 +330,7 @@ async def test_wall_display_relay_mode(
new_status = deepcopy(mock_rpc_device.status)
new_status["sys"]["relay_in_thermostat"] = False
new_status.pop("thermostat:0")
monkeypatch.setattr(mock_rpc_device, "status", new_status)
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)