Skip to content

Commit

Permalink
Added support for long term stats, fixes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
CJNE committed Aug 8, 2021
1 parent a11a245 commit a81faf6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion custom_components/sunspec/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sunspec/manifest.json
Original file line number Diff line number Diff line change
@@ -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": [],
Expand Down
25 changes: 20 additions & 5 deletions custom_components/sunspec/sensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a81faf6

Please sign in to comment.