mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add statistics support for SMA energy sensors (#53589)
This commit is contained in:
parent
a004a0dd4f
commit
127c9fc877
@ -7,7 +7,11 @@ from typing import Any
|
|||||||
import pysma
|
import pysma
|
||||||
import voluptuous as vol
|
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.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -16,6 +20,8 @@ from homeassistant.const import (
|
|||||||
CONF_SENSORS,
|
CONF_SENSORS,
|
||||||
CONF_SSL,
|
CONF_SSL,
|
||||||
CONF_VERIFY_SSL,
|
CONF_VERIFY_SSL,
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -26,6 +32,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_CUSTOM,
|
CONF_CUSTOM,
|
||||||
@ -157,6 +164,11 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
|||||||
self._config_entry_unique_id = config_entry_unique_id
|
self._config_entry_unique_id = config_entry_unique_id
|
||||||
self._device_info = device_info
|
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.
|
# Set sensor enabled to False.
|
||||||
# Will be enabled by async_added_to_hass if actually used.
|
# Will be enabled by async_added_to_hass if actually used.
|
||||||
self._sensor.enabled = False
|
self._sensor.enabled = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user