diff --git a/homeassistant/components/huum/manifest.json b/homeassistant/components/huum/manifest.json index 62775c8a5ac3..7b7c1a699762 100644 --- a/homeassistant/components/huum/manifest.json +++ b/homeassistant/components/huum/manifest.json @@ -9,5 +9,5 @@ "integration_type": "device", "iot_class": "cloud_polling", "quality_scale": "silver", - "requirements": ["huum==0.8.2"] + "requirements": ["huum==0.8.4"] } diff --git a/homeassistant/components/huum/number.py b/homeassistant/components/huum/number.py index 0e81cb1f9e25..179e910f1556 100644 --- a/homeassistant/components/huum/number.py +++ b/homeassistant/components/huum/number.py @@ -54,6 +54,18 @@ class HuumSteamer(HuumBaseEntity, NumberEntity): """Return the current value.""" return self.coordinator.data.humidity + @property + @override + def native_max_value(self) -> float: + """Return the maximum value.""" + # The allowed steamer level drops as the target temperature rises. + data = self.coordinator.data + if data.maximum_target_humidity is not None: + return data.maximum_target_humidity + if data.target_temperature is not None: + return self.coordinator.huum.get_max_humidity(data.target_temperature) + return super().native_max_value + @override async def async_set_native_value(self, value: float) -> None: """Update the current value.""" diff --git a/requirements_all.txt b/requirements_all.txt index 0c74d9a4078e..5c781ec159ab 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1385,7 +1385,7 @@ horimote==0.4.1 huawei-lte-api==1.11.0 # homeassistant.components.huum -huum==0.8.2 +huum==0.8.4 # homeassistant.components.hydroquebec_peak hydropeak-opendata==0.2.0 diff --git a/tests/components/huum/conftest.py b/tests/components/huum/conftest.py index 2142d3ecfcc5..80b2479b2342 100644 --- a/tests/components/huum/conftest.py +++ b/tests/components/huum/conftest.py @@ -36,6 +36,7 @@ def mock_huum_client() -> Generator[AsyncMock]: config=3, light=1, humidity=5, + maximum_target_humidity=20, sauna_config=SaunaConfig( child_lock="OFF", max_heating_time=3, diff --git a/tests/components/huum/snapshots/test_diagnostics.ambr b/tests/components/huum/snapshots/test_diagnostics.ambr index 67e5dfb55162..a323b8bee586 100644 --- a/tests/components/huum/snapshots/test_diagnostics.ambr +++ b/tests/components/huum/snapshots/test_diagnostics.ambr @@ -13,6 +13,8 @@ 'humidity': 5, 'is_private': None, 'light': 1, + 'maximum_target_humidity': 20, + 'measured_humidity': None, 'payment_end_date': None, 'remote_safety_state': None, 'sauna_config': dict({ diff --git a/tests/components/huum/snapshots/test_number.ambr b/tests/components/huum/snapshots/test_number.ambr index 1d9ad62264c1..bb9b9b22173d 100644 --- a/tests/components/huum/snapshots/test_number.ambr +++ b/tests/components/huum/snapshots/test_number.ambr @@ -6,7 +6,7 @@ ]), 'area_id': None, 'capabilities': dict({ - : 40, + : 20, : 0, : , : 1, @@ -46,7 +46,7 @@ 'attributes': ReadOnlyDict({ : 'humidity', : 'Huum sauna Humidity', - : 40, + : 20, : 0, : , : 1, diff --git a/tests/components/huum/test_number.py b/tests/components/huum/test_number.py index 441dc7bebe05..1252cbee1a98 100644 --- a/tests/components/huum/test_number.py +++ b/tests/components/huum/test_number.py @@ -1,6 +1,6 @@ """Tests for the Huum number entity.""" -from unittest.mock import AsyncMock +from unittest.mock import AsyncMock, patch from huum.const import SaunaStatus import pytest @@ -8,12 +8,14 @@ from pytest_homeassistant.common import MockConfigEntry, snapshot_platform from syrupy.assertion import SnapshotAssertion from homeassistant.components.number import ( + ATTR_MAX, ATTR_VALUE, DOMAIN as NUMBER_DOMAIN, SERVICE_SET_VALUE, ) from homeassistant.const import ATTR_ENTITY_ID, Platform from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ServiceValidationError from homeassistant.helpers import entity_registry as er ENTITY_ID = "number.huum_sauna_humidity" @@ -74,3 +76,105 @@ async def test_dont_set_humidity_when_sauna_not_heating( ) mock_huum_client.turn_on.assert_not_called() + + +async def setup_number_platform( + hass: HomeAssistant, mock_config_entry: MockConfigEntry +) -> None: + """Set up the integration with only the number platform.""" + mock_config_entry.add_to_hass(hass) + with patch("homeassistant.components.huum.PLATFORMS", [Platform.NUMBER]): + assert await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + +async def test_set_humidity_above_controller_maximum( + hass: HomeAssistant, + mock_huum_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test humidity above the maximum reported by the controller is rejected.""" + mock_huum_client.status.return_value.status = SaunaStatus.ONLINE_HEATING + mock_huum_client.status.return_value.maximum_target_humidity = 10 + await setup_number_platform(hass, mock_config_entry) + + assert hass.states.get(ENTITY_ID).attributes[ATTR_MAX] == 10 + + with pytest.raises(ServiceValidationError): + await hass.services.async_call( + NUMBER_DOMAIN, + SERVICE_SET_VALUE, + { + ATTR_ENTITY_ID: ENTITY_ID, + ATTR_VALUE: 20, + }, + blocking=True, + ) + + mock_huum_client.turn_on.assert_not_called() + + +async def test_set_humidity_at_controller_maximum( + hass: HomeAssistant, + mock_huum_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test humidity equal to the maximum reported by the controller is set.""" + mock_huum_client.status.return_value.status = SaunaStatus.ONLINE_HEATING + mock_huum_client.status.return_value.maximum_target_humidity = 10 + await setup_number_platform(hass, mock_config_entry) + + await hass.services.async_call( + NUMBER_DOMAIN, + SERVICE_SET_VALUE, + { + ATTR_ENTITY_ID: ENTITY_ID, + ATTR_VALUE: 10, + }, + blocking=True, + ) + + mock_huum_client.turn_on.assert_awaited_once_with(temperature=80, humidity=10) + + +async def test_humidity_maximum_without_controller_value( + hass: HomeAssistant, + mock_huum_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test the library limit is used when the controller reports no maximum.""" + mock_huum_client.status.return_value.status = SaunaStatus.ONLINE_HEATING + mock_huum_client.status.return_value.target_temperature = 95 + mock_huum_client.status.return_value.maximum_target_humidity = None + mock_huum_client.get_max_humidity.return_value = 0 + await setup_number_platform(hass, mock_config_entry) + + assert hass.states.get(ENTITY_ID).attributes[ATTR_MAX] == 0 + mock_huum_client.get_max_humidity.assert_called_with(95) + + with pytest.raises(ServiceValidationError): + await hass.services.async_call( + NUMBER_DOMAIN, + SERVICE_SET_VALUE, + { + ATTR_ENTITY_ID: ENTITY_ID, + ATTR_VALUE: 5, + }, + blocking=True, + ) + + mock_huum_client.turn_on.assert_not_called() + + +async def test_humidity_maximum_without_target_temperature( + hass: HomeAssistant, + mock_huum_client: AsyncMock, + mock_config_entry: MockConfigEntry, +) -> None: + """Test the default maximum is used without a reported maximum or target.""" + mock_huum_client.status.return_value.target_temperature = None + mock_huum_client.status.return_value.maximum_target_humidity = None + await setup_number_platform(hass, mock_config_entry) + + assert hass.states.get(ENTITY_ID).attributes[ATTR_MAX] == 40 + mock_huum_client.get_max_humidity.assert_not_called()