-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from klejejs/feature/add-hot-water-boost-switch
Add hot water boost switch
- Loading branch information
Showing
5 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
custom_components/thermia/switches/hot_water_boost_switch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |