From 41e244fc7347f2f71d8d56812b0098102c52f553 Mon Sep 17 00:00:00 2001 From: Thomas Germain <12560542+thomasgermain@users.noreply.github.com> Date: Sun, 3 Oct 2021 20:35:11 +0200 Subject: [PATCH] Stats (#99) Sensor entities compatible with statistics --- custom_components/multimatic/manifest.json | 3 +-- custom_components/multimatic/sensor.py | 28 +++++++++++++++------- hacs.json | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/custom_components/multimatic/manifest.json b/custom_components/multimatic/manifest.json index 93dd36d..e9de4e6 100644 --- a/custom_components/multimatic/manifest.json +++ b/custom_components/multimatic/manifest.json @@ -14,7 +14,6 @@ "codeowners": [ "@thomasgermain" ], - "version": "1.9.0", - "homeassistant": "2021.9.1", + "version": "1.10.0", "iot_class": "cloud_polling" } diff --git a/custom_components/multimatic/sensor.py b/custom_components/multimatic/sensor.py index c04e2ea..fea3b93 100644 --- a/custom_components/multimatic/sensor.py +++ b/custom_components/multimatic/sensor.py @@ -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 @@ -56,7 +58,7 @@ 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: @@ -64,7 +66,7 @@ def __init__(self, coordinator: MultimaticCoordinator) -> None: 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 @@ -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 @@ -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: @@ -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 @@ -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 @@ -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.""" @@ -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 @@ -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 diff --git a/hacs.json b/hacs.json index dd0bdb2..c405af8 100644 --- a/hacs.json +++ b/hacs.json @@ -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" }