Skip to content

Commit

Permalink
FR: Add temperature threshholds to control heating and cooling
Browse files Browse the repository at this point in the history
Fixes #74
  • Loading branch information
peribeir committed Jun 24, 2023
1 parent 9c1da3f commit cd60708
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
4 changes: 0 additions & 4 deletions custom_components/rademacher/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ def update_unique_id(entity_entry):
config_entry, title=f"{nodename} ({mac_address})", unique_id=mac_address, data=config_entry.data, options=config_entry.options
)





config_entry.version = 2

_LOGGER.info("Migration to version %s successful", config_entry.version)
Expand Down
4 changes: 2 additions & 2 deletions custom_components/rademacher/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/peribeir/homeassistant-rademacher/issues",
"requirements": ["pyrademacher==0.9.16"],
"version": "1.12.3"
"requirements": ["pyrademacher==0.9.20"],
"version": "1.13.1"
}
53 changes: 51 additions & 2 deletions custom_components/rademacher/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

from homeassistant.helpers.entity import EntityCategory

from homeassistant.const import CONF_EXCLUDE
from homeassistant.const import CONF_EXCLUDE, TEMP_CELSIUS, PERCENTAGE
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from homepilot.manager import HomePilotManager
from homepilot.device import HomePilotDevice
from homepilot.cover import HomePilotCover
from homepilot.thermostat import HomePilotThermostat

from .const import DOMAIN
from .entity import HomePilotEntity
Expand All @@ -33,6 +34,20 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
if cover.has_ventilation_position_config:
_LOGGER.info("Found Ventilation Position Config for Device ID: %s", device.did)
new_entities.append(HomePilotVentilationPositionEntity(coordinator, device))
if isinstance(device, HomePilotThermostat):
thermostat: HomePilotThermostat = device
if thermostat.has_temperature_thresh_cfg[0]:
_LOGGER.info("Found Temperature Threshold Config 1 for Device ID: %s", device.did)
new_entities.append(HomePilotTemperatureThresholdEntity(coordinator, device, 1))
if thermostat.has_temperature_thresh_cfg[1]:
_LOGGER.info("Found Temperature Threshold Config 2 for Device ID: %s", device.did)
new_entities.append(HomePilotTemperatureThresholdEntity(coordinator, device, 2))
if thermostat.has_temperature_thresh_cfg[2]:
_LOGGER.info("Found Temperature Threshold Config 3 for Device ID: %s", device.did)
new_entities.append(HomePilotTemperatureThresholdEntity(coordinator, device, 3))
if thermostat.has_temperature_thresh_cfg[3]:
_LOGGER.info("Found Temperature Threshold Config 4 for Device ID: %s", device.did)
new_entities.append(HomePilotTemperatureThresholdEntity(coordinator, device, 4))
# If we have any new devices, add them
if new_entities:
async_add_entities(new_entities)
Expand All @@ -56,7 +71,7 @@ def __init__(
self._attr_native_max_value = 100
self._attr_native_min_value = 0
self._attr_native_step = 1
self._attr_native_unit_of_measurement = "%"
self._attr_native_unit_of_measurement = PERCENTAGE

@property
def available(self):
Expand All @@ -74,3 +89,37 @@ async def async_set_native_value(self, value):
await device.async_set_ventilation_position(value)
await asyncio.sleep(5)
await self.coordinator.async_request_refresh()

class HomePilotTemperatureThresholdEntity(HomePilotEntity, NumberEntity):
"""This class represents Cover Ventilation Position"""
thresh_number: int = 0

def __init__(
self, coordinator: DataUpdateCoordinator, device: HomePilotThermostat, thresh_number: int
) -> None:
super().__init__(
coordinator,
device,
unique_id=f"{device.uid}_temperature_thresh_{thresh_number}",
name=f"{device.name} Temp Threshold {thresh_number}",
device_class=NumberDeviceClass.TEMPERATURE,
entity_category=EntityCategory.CONFIG,
)
self._attr_mode = NumberMode.SLIDER
self._attr_native_max_value = device.temperature_thresh_cfg_max[thresh_number-1]
self._attr_native_min_value = device.temperature_thresh_cfg_min[thresh_number-1]
self._attr_native_step = device.temperature_thresh_cfg_step[thresh_number-1]
self._attr_native_unit_of_measurement = TEMP_CELSIUS
self._thresh_number = thresh_number

@property
def native_value(self):
device: HomePilotThermostat = self.coordinator.data[self.did]
return device.temperature_thresh_cfg_value[self._thresh_number-1]

async def async_set_native_value(self, value):
"""Turn the entity on."""
device: HomePilotThermostat = self.coordinator.data[self.did]
await device.async_set_temperature_thresh_cfg(self._thresh_number, value)
await asyncio.sleep(5)
await self.coordinator.async_request_refresh()
13 changes: 4 additions & 9 deletions custom_components/rademacher/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
id_suffix="contact_state",
name_suffix="Contact State",
value_attr="contact_state_value",
state_class=None,
icon_template=lambda val: "mdi:square-outline"
if val == ContactState.OPEN
else (
Expand Down Expand Up @@ -193,6 +194,7 @@ def __init__(
icon_template=None,
entity_category=None,
options=None,
state_class=SensorStateClass.MEASUREMENT
) -> None:
super().__init__(
coordinator,
Expand All @@ -205,23 +207,16 @@ def __init__(
)
self._value_attr = value_attr
self._icon_template = icon_template
self._native_unit_of_measurement = native_unit_of_measurement
self._attr_native_unit_of_measurement = native_unit_of_measurement
self._attr_options = options
self._attr_state_class = state_class

@property
def value_attr(self):
"""This property stores which attribute contains the is_on value on
the HomePilotDevice supporting class"""
return self._value_attr

@property
def native_unit_of_measurement(self):
return self._native_unit_of_measurement

@property
def state_class(self):
return SensorStateClass.MEASUREMENT

@property
def native_value(self):
value = getattr(self.coordinator.data[self.did], self.value_attr)
Expand Down

0 comments on commit cd60708

Please sign in to comment.