mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
SMA: Add statistics support for power sensors (#54422)
This commit is contained in:
parent
d5fe7e0e5a
commit
0fdea8ec8f
@ -9,6 +9,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
)
|
)
|
||||||
@ -21,7 +22,9 @@ from homeassistant.const import (
|
|||||||
CONF_SSL,
|
CONF_SSL,
|
||||||
CONF_VERIFY_SSL,
|
CONF_VERIFY_SSL,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
|
DEVICE_CLASS_POWER,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
POWER_WATT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -166,6 +169,9 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
|||||||
if self.unit_of_measurement == ENERGY_KILO_WATT_HOUR:
|
if self.unit_of_measurement == ENERGY_KILO_WATT_HOUR:
|
||||||
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||||
self._attr_device_class = DEVICE_CLASS_ENERGY
|
self._attr_device_class = DEVICE_CLASS_ENERGY
|
||||||
|
if self.unit_of_measurement == POWER_WATT:
|
||||||
|
self._attr_state_class = STATE_CLASS_MEASUREMENT
|
||||||
|
self._attr_device_class = DEVICE_CLASS_POWER
|
||||||
|
|
||||||
# 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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user