Use enums in wallbox (#61997)

This commit is contained in:
Robert Hillis 2021-12-17 06:46:21 -05:00 committed by GitHub
parent 6b9447e3a2
commit 1c15e36afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,17 +6,13 @@ import logging
from typing import cast from typing import cast
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ELECTRIC_CURRENT_AMPERE, ELECTRIC_CURRENT_AMPERE,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
@ -63,23 +59,23 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
name="Charging Power", name="Charging Power",
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=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.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,
name="Max Available Power", name="Max Available Power",
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=SensorDeviceClass.CURRENT,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.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, state_class=SensorStateClass.MEASUREMENT,
), ),
CONF_ADDED_RANGE_KEY: WallboxSensorEntityDescription( CONF_ADDED_RANGE_KEY: WallboxSensorEntityDescription(
key=CONF_ADDED_RANGE_KEY, key=CONF_ADDED_RANGE_KEY,
@ -87,28 +83,28 @@ 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, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
CONF_ADDED_ENERGY_KEY: WallboxSensorEntityDescription( CONF_ADDED_ENERGY_KEY: WallboxSensorEntityDescription(
key=CONF_ADDED_ENERGY_KEY, key=CONF_ADDED_ENERGY_KEY,
name="Added Energy", name="Added Energy",
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=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.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, state_class=SensorStateClass.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=SensorDeviceClass.BATTERY,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
CONF_CURRENT_MODE_KEY: WallboxSensorEntityDescription( CONF_CURRENT_MODE_KEY: WallboxSensorEntityDescription(
key=CONF_CURRENT_MODE_KEY, key=CONF_CURRENT_MODE_KEY,
@ -130,8 +126,8 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = {
key=CONF_MAX_CHARGING_CURRENT_KEY, key=CONF_MAX_CHARGING_CURRENT_KEY,
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=SensorDeviceClass.CURRENT,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
} }