Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b60f931

Browse files
authored
Improve tests for Shelly WallDisplay (home-assistant#110435)
Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
1 parent da50e45 commit b60f931

File tree

3 files changed

+54
-24
lines changed

3 files changed

+54
-24
lines changed

‎homeassistant/components/shelly/switch.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
from typing import Any, cast
66

77
from aioshelly.block_device import Block
8-
from aioshelly.const import MODEL_2, MODEL_25, MODEL_GAS, RPC_GENERATIONS
8+
from aioshelly.const import (
9+
MODEL_2,
10+
MODEL_25,
11+
MODEL_GAS,
12+
MODEL_WALL_DISPLAY,
13+
RPC_GENERATIONS,
14+
)
915

1016
from homeassistant.components.automation import automations_with_entity
1117
from homeassistant.components.script import scripts_with_entity
@@ -20,7 +26,7 @@
2026
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2127
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
2228

23-
from .const import DOMAIN, GAS_VALVE_OPEN_STATES, MODEL_WALL_DISPLAY
29+
from .const import DOMAIN, GAS_VALVE_OPEN_STATES
2430
from .coordinator import ShellyBlockCoordinator, ShellyRpcCoordinator, get_entry_data
2531
from .entity import (
2632
BlockEntityDescription,

‎tests/components/shelly/test_climate.py‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from copy import deepcopy
33
from unittest.mock import AsyncMock, Mock, PropertyMock
44

5-
from aioshelly.const import MODEL_VALVE
5+
from aioshelly.const import MODEL_VALVE, MODEL_WALL_DISPLAY
66
from aioshelly.exceptions import DeviceConnectionError, InvalidAuthError
77
import pytest
88

@@ -21,7 +21,8 @@
2121
HVACAction,
2222
HVACMode,
2323
)
24-
from homeassistant.components.shelly.const import DOMAIN, MODEL_WALL_DISPLAY
24+
from homeassistant.components.shelly.const import DOMAIN
25+
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
2526
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
2627
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE
2728
from homeassistant.core import HomeAssistant, State
@@ -682,3 +683,30 @@ async def test_rpc_climate_hvac_mode_cool(
682683
state = hass.states.get(ENTITY_ID)
683684
assert state.state == HVACMode.COOL
684685
assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.COOLING
686+
687+
688+
async def test_wall_display_thermostat_mode(
689+
hass: HomeAssistant,
690+
mock_rpc_device: Mock,
691+
entity_registry: EntityRegistry,
692+
monkeypatch: pytest.MonkeyPatch,
693+
) -> None:
694+
"""Test Wall Display in thermostat mode."""
695+
climate_entity_id = "climate.test_name"
696+
switch_entity_id = "switch.test_switch_0"
697+
698+
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
699+
700+
# the switch entity should be removed
701+
assert hass.states.get(switch_entity_id) is None
702+
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 0
703+
704+
# the climate entity should be created
705+
state = hass.states.get(climate_entity_id)
706+
assert state
707+
assert state.state == HVACMode.HEAT
708+
assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 1
709+
710+
entry = entity_registry.async_get(climate_entity_id)
711+
assert entry
712+
assert entry.unique_id == "123456789ABC-thermostat:0"

‎tests/components/shelly/test_switch.py‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -317,30 +317,15 @@ async def test_block_device_gas_valve(
317317
assert state.state == STATE_ON # valve is open
318318

319319

320-
async def test_wall_display_thermostat_mode(
321-
hass: HomeAssistant,
322-
mock_rpc_device: Mock,
323-
) -> None:
324-
"""Test Wall Display in thermostat mode."""
325-
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
326-
327-
# the switch entity should not be created, only the climate entity
328-
assert hass.states.get("switch.test_name") is None
329-
assert hass.states.get("climate.test_name")
330-
331-
332320
async def test_wall_display_relay_mode(
333321
hass: HomeAssistant,
334322
mock_rpc_device: Mock,
323+
entity_registry: EntityRegistry,
335324
monkeypatch: pytest.MonkeyPatch,
336325
) -> None:
337-
"""Test Wall Display in thermostat mode."""
338-
entity_id = register_entity(
339-
hass,
340-
CLIMATE_DOMAIN,
341-
"test_name",
342-
"thermostat:0",
343-
)
326+
"""Test Wall Display in relay mode."""
327+
climate_entity_id = "climate.test_name"
328+
switch_entity_id = "switch.test_switch_0"
344329

345330
new_shelly = deepcopy(mock_rpc_device.shelly)
346331
new_shelly["relay_in_thermostat"] = False
@@ -349,7 +334,18 @@ async def test_wall_display_relay_mode(
349334
await init_integration(hass, 2, model=MODEL_WALL_DISPLAY)
350335

351336
# the climate entity should be removed
352-
assert hass.states.get(entity_id) is None
337+
assert hass.states.get(climate_entity_id) is None
338+
assert len(hass.states.async_entity_ids(CLIMATE_DOMAIN)) == 0
339+
340+
# the switch entity should be created
341+
state = hass.states.get(switch_entity_id)
342+
assert state
343+
assert state.state == STATE_ON
344+
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
345+
346+
entry = entity_registry.async_get(switch_entity_id)
347+
assert entry
348+
assert entry.unique_id == "123456789ABC-switch:0"
353349

354350

355351
async def test_create_issue_valve_switch(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /