From 1e6cddaa1d4e1eb5b983800298bd6557d1933e5e Mon Sep 17 00:00:00 2001 From: Richard Mikalsen Date: Fri, 1 Sep 2023 19:05:35 +0200 Subject: [PATCH] Turn off Mill heaters using local API (#99348) * Update mill_local * Add ability to turn heater on and off * Use OperationMode from upstream library * Fix: compare against value --- homeassistant/components/mill/climate.py | 24 ++++++++++++++++----- homeassistant/components/mill/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/mill/climate.py b/homeassistant/components/mill/climate.py index 2ddcf97f25a..a5e59b4f8ec 100644 --- a/homeassistant/components/mill/climate.py +++ b/homeassistant/components/mill/climate.py @@ -2,6 +2,7 @@ from typing import Any import mill +from mill_local import OperationMode import voluptuous as vol from homeassistant.components.climate import ( @@ -176,8 +177,7 @@ class LocalMillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntit """Representation of a Mill Thermostat device.""" _attr_has_entity_name = True - _attr_hvac_mode = HVACMode.HEAT - _attr_hvac_modes = [HVACMode.HEAT] + _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF] _attr_max_temp = MAX_TEMP _attr_min_temp = MIN_TEMP _attr_name = None @@ -210,6 +210,15 @@ class LocalMillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntit ) await self.coordinator.async_request_refresh() + async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: + """Set new target hvac mode.""" + if hvac_mode == HVACMode.HEAT: + await self.coordinator.mill_data_connection.set_operation_mode_control_individually() + await self.coordinator.async_request_refresh() + elif hvac_mode == HVACMode.OFF: + await self.coordinator.mill_data_connection.set_operation_mode_off() + await self.coordinator.async_request_refresh() + @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" @@ -222,7 +231,12 @@ class LocalMillHeater(CoordinatorEntity[MillDataUpdateCoordinator], ClimateEntit self._attr_target_temperature = data["set_temperature"] self._attr_current_temperature = data["ambient_temperature"] - if data["current_power"] > 0: - self._attr_hvac_action = HVACAction.HEATING + if data["operation_mode"] == OperationMode.OFF.value: + self._attr_hvac_mode = HVACMode.OFF + self._attr_hvac_action = HVACAction.OFF else: - self._attr_hvac_action = HVACAction.IDLE + self._attr_hvac_mode = HVACMode.HEAT + if data["current_power"] > 0: + self._attr_hvac_action = HVACAction.HEATING + else: + self._attr_hvac_action = HVACAction.IDLE diff --git a/homeassistant/components/mill/manifest.json b/homeassistant/components/mill/manifest.json index b2dbf993dae..39b91570190 100644 --- a/homeassistant/components/mill/manifest.json +++ b/homeassistant/components/mill/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/mill", "iot_class": "local_polling", "loggers": ["mill", "mill_local"], - "requirements": ["millheater==0.11.1", "mill-local==0.2.0"] + "requirements": ["millheater==0.11.1", "mill-local==0.3.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 9a227358391..c84a21f3d8c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1210,7 +1210,7 @@ mficlient==0.3.0 micloud==0.5 # homeassistant.components.mill -mill-local==0.2.0 +mill-local==0.3.0 # homeassistant.components.mill millheater==0.11.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e34cc14052f..ef67aca2937 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -924,7 +924,7 @@ mficlient==0.3.0 micloud==0.5 # homeassistant.components.mill -mill-local==0.2.0 +mill-local==0.3.0 # homeassistant.components.mill millheater==0.11.1