-
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.
Added hot water switch, active alarm sensor
- Loading branch information
Showing
10 changed files
with
267 additions
and
71 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
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 @@ | ||
"""Thermia Heat Pump Sensors.""" |
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,60 @@ | ||
"""Thermia active alarms sensor integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.components.sensor import SensorEntity | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from ..const import DOMAIN | ||
|
||
|
||
class ThermiaActiveAlarmsSensor(CoordinatorEntity, SensorEntity): | ||
"""Representation of an Thermia active alarms sensor.""" | ||
|
||
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 sensor.""" | ||
return f"{self.coordinator.data.heat_pumps[self.idx].name} Active Alarms" | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the unique ID of the sensor.""" | ||
return f"{self.coordinator.data.heat_pumps[self.idx].name}_active_alarms" | ||
|
||
@property | ||
def icon(self): | ||
"""Return the icon of the sensor.""" | ||
return "mdi:bell-alert" | ||
|
||
@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 state_class(self): | ||
"""Return the state class.""" | ||
return "total" | ||
|
||
@property | ||
def native_value(self): | ||
"""Return active alarms count of the sensor.""" | ||
return self.coordinator.data.heat_pumps[self.idx].active_alarm_count | ||
|
||
async def async_update(self): | ||
"""Update the sensor.""" | ||
await self.coordinator.async_request_refresh() |
71 changes: 71 additions & 0 deletions
71
custom_components/thermia/sensors/outdoor_temperature_sensor.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,71 @@ | ||
"""Thermia outdoor temperature sensor integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.components.sensor import SensorEntity | ||
from homeassistant.const import TEMP_CELSIUS | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from ..const import DOMAIN | ||
|
||
|
||
class ThermiaOutdoorTemperatureSensor(CoordinatorEntity, SensorEntity): | ||
"""Representation of an Thermia outdoor temperature sensor.""" | ||
|
||
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 sensor.""" | ||
return f"{self.coordinator.data.heat_pumps[self.idx].name} Outdoor Temperature" | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the unique ID of the sensor.""" | ||
return f"{self.coordinator.data.heat_pumps[self.idx].name}_outdoor_temperature" | ||
|
||
@property | ||
def icon(self): | ||
"""Return the icon of the sensor.""" | ||
return "mdi:thermometer" | ||
|
||
@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.""" | ||
return "temperature" | ||
|
||
@property | ||
def state_class(self): | ||
"""Return the state class.""" | ||
return "measurement" | ||
|
||
@property | ||
def native_value(self): | ||
"""Return the temperature of the sensor.""" | ||
return self.coordinator.data.heat_pumps[self.idx].outdoor_temperature | ||
|
||
@property | ||
def native_unit_of_measurement(self): | ||
"""Return the unit of measurement of the sensor.""" | ||
return TEMP_CELSIUS | ||
|
||
async def async_update(self): | ||
"""Update the sensor.""" | ||
await self.coordinator.async_request_refresh() |
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,30 @@ | ||
"""Thermia switch integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .switches.hot_water_switch import ThermiaHotWaterSwitch | ||
|
||
from .const import DOMAIN | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the Thermia switches.""" | ||
|
||
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 | ||
] | ||
|
||
async_add_entities(hass_thermia_hot_water_switches) |
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 @@ | ||
"""Thermia Heat Pump Switches.""" |
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,83 @@ | ||
"""Thermia hot water switch integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.components.switch import SwitchEntity | ||
from homeassistant.helpers.update_coordinator import CoordinatorEntity | ||
|
||
from ..const import DOMAIN | ||
|
||
|
||
class ThermiaHotWaterSwitch(CoordinatorEntity, SwitchEntity): | ||
"""Representation of an Thermia hot water 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" | ||
|
||
@property | ||
def unique_id(self): | ||
"""Return the unique ID of the switch.""" | ||
return f"{self.coordinator.data.heat_pumps[self.idx].name}_hot_water" | ||
|
||
@property | ||
def icon(self): | ||
"""Return the icon of the switch.""" | ||
return "mdi:water-boiler" | ||
|
||
@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_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_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_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() | ||
|
||
async def async_update(self): | ||
"""Update the switch.""" | ||
await self.coordinator.async_request_refresh() |