Skip to content

Commit

Permalink
Merge pull request #295 from Eradash/target_temperature
Browse files Browse the repository at this point in the history
Add target temperature as a sensor
  • Loading branch information
valleedelisle authored Oct 15, 2023
2 parents 33d42d0 + 5f17dc4 commit 766c422
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def generate_entities_from_device(device, hilo, scan_interval):
)
if device.has_attribute("current_temperature"):
entities.append(TemperatureSensor(hilo, device))
if device.has_attribute("target_temperature"):
entities.append(TargetTemperatureSensor(hilo, device))
if device.has_attribute("co2"):
entities.append(Co2Sensor(hilo, device))
if device.has_attribute("noise"):
Expand Down Expand Up @@ -364,6 +366,37 @@ def icon(self):
return f"mdi:thermometer-{thermometer}"


class TargetTemperatureSensor(HiloEntity, SensorEntity):
"""Define a Hilo target temperature sensor entity."""

_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = TEMP_CELSIUS
_attr_state_class = SensorStateClass.MEASUREMENT

def __init__(self, hilo, device):
self._attr_name = f"{device.name} Target Temperature"
super().__init__(hilo, name=self._attr_name, device=device)
self._attr_unique_id = f"{slugify(device.name)}-target-temperature"
LOG.debug(f"Setting up TargetTemperatureSensor entity: {self._attr_name}")

@property
def state(self):
return str(float(self._device.get_value("target_temperature", 0)))

@property
def icon(self):
target_temperature = int(self._device.get_value("target_temperature", 0))
if not self._device.available:
thermometer = "off"
elif target_temperature >= 22:
thermometer = "high"
elif target_temperature >= 18:
thermometer = "low"
else:
thermometer = "alert"
return f"mdi:thermometer-{thermometer}"


class WifiStrengthSensor(HiloEntity, SensorEntity):
"""Define a Wifi strength sensor entity."""

Expand Down Expand Up @@ -630,7 +663,6 @@ def icon(self):


class HiloCostSensor(RestoreEntity, SensorEntity):

_attr_device_class = SensorDeviceClass.MONETARY
_attr_native_unit_of_measurement = f"{CURRENCY_DOLLAR}/{ENERGY_KILO_WATT_HOUR}"
_attr_state_class = SensorStateClass.MEASUREMENT
Expand Down

0 comments on commit 766c422

Please sign in to comment.