Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Stats (#99)
Browse files Browse the repository at this point in the history
Sensor entities compatible with statistics
  • Loading branch information
thomasgermain authored Oct 3, 2021
1 parent cdab4e8 commit 41e244f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
3 changes: 1 addition & 2 deletions custom_components/multimatic/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"codeowners": [
"@thomasgermain"
],
"version": "1.9.0",
"homeassistant": "2021.9.1",
"version": "1.10.0",
"iot_class": "cloud_polling"
}
28 changes: 20 additions & 8 deletions custom_components/multimatic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
DOMAIN,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
)
from homeassistant.const import ENERGY_WATT_HOUR, TEMP_CELSIUS
from homeassistant.helpers.typing import StateType
from homeassistant.util.dt import utc_from_timestamp

from .const import EMF_REPORTS, OUTDOOR_TEMP, REPORTS
Expand Down Expand Up @@ -56,15 +58,15 @@ async def async_setup_entry(hass, entry, async_add_entities):
return True


class OutdoorTemperatureSensor(MultimaticEntity):
class OutdoorTemperatureSensor(MultimaticEntity, SensorEntity):
"""Outdoor temperature sensor."""

def __init__(self, coordinator: MultimaticCoordinator) -> None:
"""Initialize entity."""
super().__init__(coordinator, DOMAIN, "outdoor_temperature")

@property
def state(self):
def native_value(self) -> StateType:
"""Return the state of the entity."""
return self.coordinator.data

Expand All @@ -74,7 +76,7 @@ def available(self):
return super().available and self.coordinator.data is not None

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity, if any."""
return TEMP_CELSIUS

Expand All @@ -88,8 +90,13 @@ def device_class(self) -> str:
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_TEMPERATURE

@property
def state_class(self) -> str | None:
"""Return the state class of this entity."""
return STATE_CLASS_MEASUREMENT


class ReportSensor(MultimaticEntity):
class ReportSensor(MultimaticEntity, SensorEntity):
"""Report sensor."""

def __init__(self, coordinator: MultimaticCoordinator, report: Report) -> None:
Expand All @@ -115,7 +122,7 @@ def report(self):
)

@property
def state(self):
def native_value(self) -> StateType:
"""Return the state of the entity."""
return self.report.value

Expand All @@ -125,7 +132,7 @@ def available(self):
return super().available and self.report is not None

@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity, if any."""
return self._unit

Expand All @@ -139,6 +146,11 @@ def device_info(self):
"model": self.report.device_id,
}

@property
def state_class(self) -> str | None:
"""Return the state class of this entity, from STATE_CLASSES, if any."""
return STATE_CLASS_MEASUREMENT

@property
def device_class(self) -> str | None:
"""Return the class of this device, from component DEVICE_CLASSES."""
Expand Down Expand Up @@ -173,7 +185,7 @@ def report(self):
)

@property
def state(self):
def native_value(self):
"""Return the state of the entity."""
return self.report.value

Expand All @@ -183,7 +195,7 @@ def available(self):
return super().available and self.report is not None

@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity, if any."""
return ENERGY_WATT_HOUR

Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "multimatic",
"domains": ["binary_sensor", "climate", "fan", "sensor", "water_heater"],
"render_readme": true,
"iot_class": "Cloud Polling"
"homeassistant": "2021.9.1"
}

0 comments on commit 41e244f

Please sign in to comment.