From 94a025974335a97fe172775cf682187be7e29379 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 29 Jun 2021 08:38:21 +0200 Subject: [PATCH] Add state class support to SAJ Solar Inverter (#52261) --- homeassistant/components/saj/sensor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/saj/sensor.py b/homeassistant/components/saj/sensor.py index f1def71cc64..fb3b31764f8 100644 --- a/homeassistant/components/saj/sensor.py +++ b/homeassistant/components/saj/sensor.py @@ -1,11 +1,17 @@ """SAJ solar inverter interface.""" +from __future__ import annotations + from datetime import date import logging import pysaj import voluptuous as vol -from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity +from homeassistant.components.sensor import ( + PLATFORM_SCHEMA, + STATE_CLASS_MEASUREMENT, + SensorEntity, +) from homeassistant.const import ( CONF_HOST, CONF_NAME, @@ -27,6 +33,7 @@ from homeassistant.core import CALLBACK_TYPE, callback from homeassistant.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import async_call_later +from homeassistant.util import dt as dt_util _LOGGER = logging.getLogger(__name__) @@ -169,6 +176,11 @@ class SAJsensor(SensorEntity): self._serialnumber = serialnumber self._state = self._sensor.value + if pysaj_sensor.name in ("current_power", "total_yield", "temperature"): + self._attr_state_class = STATE_CLASS_MEASUREMENT + if pysaj_sensor.name == "total_yield": + self._attr_last_reset = dt_util.utc_from_timestamp(0) + @property def name(self): """Return the name of the sensor."""