From d4d294f54368a481c7955c47922ca841102a5aa0 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Mon, 26 Dec 2022 18:31:31 +0200 Subject: [PATCH 1/3] Add hot water boost switch --- custom_components/thermia/manifest.json | 2 +- custom_components/thermia/switch.py | 17 ++-- .../switches/hot_water_boost_switch.py | 81 +++++++++++++++++++ 3 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 custom_components/thermia/switches/hot_water_boost_switch.py diff --git a/custom_components/thermia/manifest.json b/custom_components/thermia/manifest.json index d46c5e3..7862272 100644 --- a/custom_components/thermia/manifest.json +++ b/custom_components/thermia/manifest.json @@ -9,7 +9,7 @@ "@klejejs" ], "requirements": [ - "ThermiaOnlineAPI==3.2" + "ThermiaOnlineAPI==3.4.dev1" ], "version": "1.0", "iot_class": "cloud_polling", diff --git a/custom_components/thermia/switch.py b/custom_components/thermia/switch.py index 7c21b80..109888f 100644 --- a/custom_components/thermia/switch.py +++ b/custom_components/thermia/switch.py @@ -7,6 +7,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .switches.hot_water_switch import ThermiaHotWaterSwitch +from .switches.hot_water_boost_switch import ThermiaHotWaterBoostSwitch from .const import DOMAIN @@ -20,11 +21,13 @@ async def async_setup_entry( coordinator = hass.data[DOMAIN][config_entry.entry_id] - hass_thermia_hot_water_switches = [ - ThermiaHotWaterSwitch(coordinator, idx) - for idx, heat_pump in enumerate(coordinator.data.heat_pumps) - if heat_pump.is_hot_water_switch_available - and heat_pump.hot_water_switch_state is not None - ] + hass_thermia_switches = [] - async_add_entities(hass_thermia_hot_water_switches) + for idx, heat_pump in enumerate(coordinator.data.heat_pumps): + if heat_pump.hot_water_switch_state is not None: + hass_thermia_switches.append(ThermiaHotWaterSwitch(coordinator, idx)) + + if heat_pump.hot_water_boost_switch_state is not None: + hass_thermia_switches.append(ThermiaHotWaterBoostSwitch(coordinator, idx)) + + async_add_entities(hass_thermia_switches) diff --git a/custom_components/thermia/switches/hot_water_boost_switch.py b/custom_components/thermia/switches/hot_water_boost_switch.py new file mode 100644 index 0000000..84bd348 --- /dev/null +++ b/custom_components/thermia/switches/hot_water_boost_switch.py @@ -0,0 +1,81 @@ +"""Thermia hot water boost switch integration.""" + +from __future__ import annotations + +from homeassistant.components.switch import SwitchEntity +from homeassistant.helpers.update_coordinator import CoordinatorEntity + +from ..const import DOMAIN + + +class ThermiaHotWaterBoostSwitch(CoordinatorEntity, SwitchEntity): + """Representation of an Thermia hot water boost switch.""" + + def __init__(self, coordinator, idx): + super().__init__(coordinator) + self.idx = idx + + @property + def available(self): + """Return True if entity is available.""" + return self.coordinator.data.heat_pumps[self.idx].is_online + + @property + def name(self): + """Return the name of the switch.""" + return f"{self.coordinator.data.heat_pumps[self.idx].name} Hot Water Boost" + + @property + def unique_id(self): + """Return the unique ID of the switch.""" + return f"{self.coordinator.data.heat_pumps[self.idx].name}_hot_water_boost" + + @property + def icon(self): + """Return the icon of the switch.""" + return "mdi:waves-arrow-up" + + @property + def device_info(self): + """Return device information.""" + return { + "identifiers": {(DOMAIN, self.coordinator.data.heat_pumps[self.idx].id)}, + "name": self.coordinator.data.heat_pumps[self.idx].name, + "manufacturer": "Thermia", + "model": self.coordinator.data.heat_pumps[self.idx].model, + } + + @property + def device_class(self): + """Return the device class of the switch.""" + return "switch" + + @property + def is_on(self): + """Return true if switch is on.""" + return ( + self.coordinator.data.heat_pumps[self.idx].hot_water_boost_switch_state == 1 + ) + + async def async_turn_on(self, **kwargs): + """Turn on the switch.""" + await self.hass.async_add_executor_job( + lambda: self.coordinator.data.heat_pumps[ + self.idx + ].set_hot_water_boost_switch_state(1) + ) + + async def async_turn_off(self, **kwargs): + """Turn off the switch.""" + await self.hass.async_add_executor_job( + lambda: self.coordinator.data.heat_pumps[ + self.idx + ].set_hot_water_boost_switch_state(0) + ) + + async def async_toggle(self, **kwargs): + """Toggle the switch.""" + if self.is_on: + await self.async_turn_off() + else: + await self.async_turn_on() From 0423306065d3cb003e8fb7775330f6f3417f4c69 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Tue, 27 Dec 2022 16:23:03 +0200 Subject: [PATCH 2/3] Update underlying API version --- custom_components/thermia/__init__.py | 2 +- custom_components/thermia/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/thermia/__init__.py b/custom_components/thermia/__init__.py index 3de3b6c..55e3fce 100644 --- a/custom_components/thermia/__init__.py +++ b/custom_components/thermia/__init__.py @@ -73,7 +73,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): class ThermiaDataUpdateCoordinator(DataUpdateCoordinator): """Thermia Data Update Coordinator.""" - def __init__(self, hass: HomeAssistant, thermia: ThermiaAPI): + def __init__(self, hass: HomeAssistant, thermia: Thermia): """Initialize the data update object.""" self.thermia = thermia diff --git a/custom_components/thermia/manifest.json b/custom_components/thermia/manifest.json index 7862272..622c8f1 100644 --- a/custom_components/thermia/manifest.json +++ b/custom_components/thermia/manifest.json @@ -9,7 +9,7 @@ "@klejejs" ], "requirements": [ - "ThermiaOnlineAPI==3.4.dev1" + "ThermiaOnlineAPI==3.4.dev2" ], "version": "1.0", "iot_class": "cloud_polling", From a318a9b775691d6abb11244016291b2606c90837 Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Wed, 28 Dec 2022 00:22:45 +0200 Subject: [PATCH 3/3] Update underlying API version, fix typo --- custom_components/thermia/manifest.json | 2 +- custom_components/thermia/sensors/generic_sensor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/thermia/manifest.json b/custom_components/thermia/manifest.json index 622c8f1..27157a3 100644 --- a/custom_components/thermia/manifest.json +++ b/custom_components/thermia/manifest.json @@ -9,7 +9,7 @@ "@klejejs" ], "requirements": [ - "ThermiaOnlineAPI==3.4.dev2" + "ThermiaOnlineAPI==3.4" ], "version": "1.0", "iot_class": "cloud_polling", diff --git a/custom_components/thermia/sensors/generic_sensor.py b/custom_components/thermia/sensors/generic_sensor.py index f56a77c..1d1f8cd 100644 --- a/custom_components/thermia/sensors/generic_sensor.py +++ b/custom_components/thermia/sensors/generic_sensor.py @@ -83,7 +83,7 @@ def state_class(self): @property def native_value(self): - """Return active alarms count of the sensor.""" + """Return value of the sensor.""" return getattr(self.coordinator.data.heat_pumps[self.idx], self._value_prop) @property