Skip to content

Commit 18ef4af

Browse files
vincentwolsinkfrenck
authored andcommitted
Return default temp range if API responds 0 in Huum. (home-assistant#153871)
1 parent 3c67882 commit 18ef4af

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

homeassistant/components/huum/climate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from homeassistant.exceptions import HomeAssistantError
1919
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
2020

21+
from .const import CONFIG_DEFAULT_MAX_TEMP, CONFIG_DEFAULT_MIN_TEMP
2122
from .coordinator import HuumConfigEntry, HuumDataUpdateCoordinator
2223
from .entity import HuumBaseEntity
2324

@@ -55,12 +56,12 @@ def __init__(self, coordinator: HuumDataUpdateCoordinator) -> None:
5556
@property
5657
def min_temp(self) -> int:
5758
"""Return configured minimal temperature."""
58-
return self.coordinator.data.sauna_config.min_temp
59+
return self.coordinator.data.sauna_config.min_temp or CONFIG_DEFAULT_MIN_TEMP
5960

6061
@property
6162
def max_temp(self) -> int:
6263
"""Return configured maximum temperature."""
63-
return self.coordinator.data.sauna_config.max_temp
64+
return self.coordinator.data.sauna_config.max_temp or CONFIG_DEFAULT_MAX_TEMP
6465

6566
@property
6667
def hvac_mode(self) -> HVACMode:

homeassistant/components/huum/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
CONFIG_STEAMER = 1
1010
CONFIG_LIGHT = 2
1111
CONFIG_STEAMER_AND_LIGHT = 3
12+
13+
CONFIG_DEFAULT_MIN_TEMP = 40
14+
CONFIG_DEFAULT_MAX_TEMP = 110

tests/components/huum/test_climate.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
SERVICE_SET_TEMPERATURE,
1212
HVACMode,
1313
)
14+
from homeassistant.components.huum.const import (
15+
CONFIG_DEFAULT_MAX_TEMP,
16+
CONFIG_DEFAULT_MIN_TEMP,
17+
)
1418
from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, Platform
1519
from homeassistant.core import HomeAssistant
1620
from homeassistant.helpers import entity_registry as er
@@ -76,3 +80,39 @@ async def test_set_temperature(
7680
)
7781

7882
mock_huum.turn_on.assert_called_once_with(60)
83+
84+
85+
async def test_temperature_range(
86+
hass: HomeAssistant,
87+
mock_huum: AsyncMock,
88+
mock_config_entry: MockConfigEntry,
89+
) -> None:
90+
"""Test the temperature range."""
91+
await setup_with_selected_platforms(hass, mock_config_entry, [Platform.CLIMATE])
92+
93+
# API response.
94+
state = hass.states.get(ENTITY_ID)
95+
assert state.attributes["min_temp"] == 40
96+
assert state.attributes["max_temp"] == 110
97+
98+
# Empty/unconfigured API response should return default values.
99+
mock_huum.sauna_config.min_temp = 0
100+
mock_huum.sauna_config.max_temp = 0
101+
102+
await mock_config_entry.runtime_data.async_refresh()
103+
await hass.async_block_till_done()
104+
105+
state = hass.states.get(ENTITY_ID)
106+
assert state.attributes["min_temp"] == CONFIG_DEFAULT_MIN_TEMP
107+
assert state.attributes["max_temp"] == CONFIG_DEFAULT_MAX_TEMP
108+
109+
# Custom configured API response.
110+
mock_huum.sauna_config.min_temp = 50
111+
mock_huum.sauna_config.max_temp = 80
112+
113+
await mock_config_entry.runtime_data.async_refresh()
114+
await hass.async_block_till_done()
115+
116+
state = hass.states.get(ENTITY_ID)
117+
assert state.attributes["min_temp"] == 50
118+
assert state.attributes["max_temp"] == 80

0 commit comments

Comments
 (0)