Skip to content

Commit

Permalink
Merge pull request #37 from klejejs/feature/add-hot-water-boost-switch
Browse files Browse the repository at this point in the history
Add hot water boost switch
  • Loading branch information
klejejs authored Dec 27, 2022
2 parents 41e2176 + a318a9b commit 5b6e310
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/thermia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/thermia/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@klejejs"
],
"requirements": [
"ThermiaOnlineAPI==3.2"
"ThermiaOnlineAPI==3.4"
],
"version": "1.0",
"iot_class": "cloud_polling",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/thermia/sensors/generic_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions custom_components/thermia/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
81 changes: 81 additions & 0 deletions custom_components/thermia/switches/hot_water_boost_switch.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 5b6e310

Please sign in to comment.