Add state class to wallbox component (#58801)

This commit is contained in:
hesselonline 2021-11-04 09:58:58 +01:00 committed by GitHub
parent a64cec6da1
commit 4345432d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,12 @@ from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
import logging import logging
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT, DEVICE_CLASS_CURRENT,
@ -54,6 +59,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
precision=2, precision=2,
native_unit_of_measurement=POWER_KILO_WATT, native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER, device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
), ),
CONF_MAX_AVAILABLE_POWER_KEY: WallboxSensorEntityDescription( CONF_MAX_AVAILABLE_POWER_KEY: WallboxSensorEntityDescription(
key=CONF_MAX_AVAILABLE_POWER_KEY, key=CONF_MAX_AVAILABLE_POWER_KEY,
@ -61,12 +67,14 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
precision=0, precision=0,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT, device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
), ),
CONF_CHARGING_SPEED_KEY: WallboxSensorEntityDescription( CONF_CHARGING_SPEED_KEY: WallboxSensorEntityDescription(
key=CONF_CHARGING_SPEED_KEY, key=CONF_CHARGING_SPEED_KEY,
icon="mdi:speedometer", icon="mdi:speedometer",
name="Charging Speed", name="Charging Speed",
precision=0, precision=0,
state_class=STATE_CLASS_MEASUREMENT,
), ),
CONF_ADDED_RANGE_KEY: WallboxSensorEntityDescription( CONF_ADDED_RANGE_KEY: WallboxSensorEntityDescription(
key=CONF_ADDED_RANGE_KEY, key=CONF_ADDED_RANGE_KEY,
@ -74,6 +82,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
name="Added Range", name="Added Range",
precision=0, precision=0,
native_unit_of_measurement=LENGTH_KILOMETERS, native_unit_of_measurement=LENGTH_KILOMETERS,
state_class=STATE_CLASS_TOTAL_INCREASING,
), ),
CONF_ADDED_ENERGY_KEY: WallboxSensorEntityDescription( CONF_ADDED_ENERGY_KEY: WallboxSensorEntityDescription(
key=CONF_ADDED_ENERGY_KEY, key=CONF_ADDED_ENERGY_KEY,
@ -81,17 +90,20 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
precision=2, precision=2,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
), ),
CONF_COST_KEY: WallboxSensorEntityDescription( CONF_COST_KEY: WallboxSensorEntityDescription(
key=CONF_COST_KEY, key=CONF_COST_KEY,
icon="mdi:ev-station", icon="mdi:ev-station",
name="Cost", name="Cost",
state_class=STATE_CLASS_TOTAL_INCREASING,
), ),
CONF_STATE_OF_CHARGE_KEY: WallboxSensorEntityDescription( CONF_STATE_OF_CHARGE_KEY: WallboxSensorEntityDescription(
key=CONF_STATE_OF_CHARGE_KEY, key=CONF_STATE_OF_CHARGE_KEY,
name="State of Charge", name="State of Charge",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY, device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
), ),
CONF_CURRENT_MODE_KEY: WallboxSensorEntityDescription( CONF_CURRENT_MODE_KEY: WallboxSensorEntityDescription(
key=CONF_CURRENT_MODE_KEY, key=CONF_CURRENT_MODE_KEY,
@ -114,6 +126,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
name="Max. Charging Current", name="Max. Charging Current",
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT, device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
), ),
} }