From a81faf6607adc9d1fb7149cf6f3caee37c4b817a Mon Sep 17 00:00:00 2001 From: Johan Isacsson Date: Mon, 9 Aug 2021 00:15:19 +0200 Subject: [PATCH] Added support for long term stats, fixes #26 --- custom_components/sunspec/const.py | 2 +- custom_components/sunspec/manifest.json | 2 +- custom_components/sunspec/sensor.py | 25 ++++++++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/custom_components/sunspec/const.py b/custom_components/sunspec/const.py index 2c81c42..08a0489 100644 --- a/custom_components/sunspec/const.py +++ b/custom_components/sunspec/const.py @@ -3,7 +3,7 @@ NAME = "SunSpec" DOMAIN = "sunspec" DOMAIN_DATA = f"{DOMAIN}_data" -VERSION = "0.0.4" +VERSION = "0.0.7" ATTRIBUTION = "Data provided by SunSpec alliance - https://sunspec.org" ISSUE_URL = "https://github.com/cjne/ha-sunspec/issues" diff --git a/custom_components/sunspec/manifest.json b/custom_components/sunspec/manifest.json index 894997d..28e194b 100644 --- a/custom_components/sunspec/manifest.json +++ b/custom_components/sunspec/manifest.json @@ -1,7 +1,7 @@ { "domain": "sunspec", "name": "SunSpec", - "version": "0.0.6", + "version": "0.0.7", "documentation": "https://github.com/cjne/ha-sunspec", "issue_tracker": "https://github.com/cjne/ha-sunspec/issues", "dependencies": [], diff --git a/custom_components/sunspec/sensor.py b/custom_components/sunspec/sensor.py index 90159e6..4e47974 100644 --- a/custom_components/sunspec/sensor.py +++ b/custom_components/sunspec/sensor.py @@ -1,14 +1,15 @@ """Sensor platform for SunSpec.""" import logging +from homeassistant.components.sensor import DEVICE_CLASS_CURRENT +from homeassistant.components.sensor import DEVICE_CLASS_ENERGY +from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE +from homeassistant.components.sensor import DEVICE_CLASS_VOLTAGE +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT from homeassistant.const import DATA_RATE_BITS_PER_SECOND from homeassistant.const import DATA_RATE_MEGABITS_PER_SECOND from homeassistant.const import DEGREE -from homeassistant.const import DEVICE_CLASS_CURRENT -from homeassistant.const import DEVICE_CLASS_ENERGY from homeassistant.const import DEVICE_CLASS_POWER -from homeassistant.const import DEVICE_CLASS_TEMPERATURE -from homeassistant.const import DEVICE_CLASS_VOLTAGE from homeassistant.const import ELECTRIC_CURRENT_AMPERE from homeassistant.const import ELECTRIC_POTENTIAL_VOLT from homeassistant.const import ENERGY_KILO_WATT_HOUR @@ -127,12 +128,14 @@ def __init__(self, coordinator, config_entry, data): self._name = f"{name.capitalize()} {desc}" _LOGGER.debug( - "Createed sensor for %s in model %s using prefix %s: %s uid %s", + "Createed sensor for %s in model %s using prefix %s: %s uid %s, device class %s unit %s", self.key, self.model_id, data["prefix"], self._name, self._uniqe_id, + self.use_device_class, + self.unit, ) # def async_will_remove_from_hass(self): @@ -185,12 +188,24 @@ def device_class(self): """Return de device class of the sensor.""" return self.use_device_class + # @property + # def state_class(self): + # """Return de device class of the sensor.""" + # return STATE_CLASS_MEASUREMENT + + # @property + # def last_reset(self): + # """Return de device class of the sensor.""" + # return 0 + @property def device_state_attributes(self): """Return the state attributes.""" attrs = { "integration": DOMAIN, "sunspec_key": self.key, + "state_class": STATE_CLASS_MEASUREMENT, + "last_reset": 0, } label = self._meta.get("label", None) if label is not None: