Add statistics support for SMA energy sensors (#53589)
This commit is contained in:
parent
a004a0dd4f
commit
127c9fc877
1 changed files with 13 additions and 1 deletions
|
@ -7,7 +7,11 @@ from typing import Any
|
|||
import pysma
|
||||
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.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
|
@ -16,6 +20,8 @@ from homeassistant.const import (
|
|||
CONF_SENSORS,
|
||||
CONF_SSL,
|
||||
CONF_VERIFY_SSL,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -26,6 +32,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
CONF_CUSTOM,
|
||||
|
@ -157,6 +164,11 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
|||
self._config_entry_unique_id = config_entry_unique_id
|
||||
self._device_info = device_info
|
||||
|
||||
if self.unit_of_measurement == ENERGY_KILO_WATT_HOUR:
|
||||
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
self._attr_device_class = DEVICE_CLASS_ENERGY
|
||||
self._attr_last_reset = dt_util.utc_from_timestamp(0)
|
||||
|
||||
# Set sensor enabled to False.
|
||||
# Will be enabled by async_added_to_hass if actually used.
|
||||
self._sensor.enabled = False
|
||||
|
|
Loading…
Add table
Reference in a new issue