Use enums in Powerwall (#62072)

This commit is contained in:
Robert Hillis 2021-12-16 12:38:56 -05:00 committed by GitHub
parent 31bef18e9a
commit 619529b40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 23 deletions

View File

@ -2,11 +2,9 @@
from tesla_powerwall import GridStatus, MeterType
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import DEVICE_CLASS_POWER
from .const import (
DOMAIN,
@ -61,7 +59,7 @@ class PowerWallRunningSensor(PowerWallEntity, BinarySensorEntity):
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_POWER
return BinarySensorDeviceClass.POWER
@property
def unique_id(self):
@ -85,7 +83,7 @@ class PowerWallConnectedSensor(PowerWallEntity, BinarySensorEntity):
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_CONNECTIVITY
return BinarySensorDeviceClass.CONNECTIVITY
@property
def unique_id(self):
@ -109,7 +107,7 @@ class PowerWallGridServicesActiveSensor(PowerWallEntity, BinarySensorEntity):
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_POWER
return BinarySensorDeviceClass.POWER
@property
def unique_id(self):
@ -133,7 +131,7 @@ class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorEntity):
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_POWER
return BinarySensorDeviceClass.POWER
@property
def unique_id(self):
@ -157,7 +155,7 @@ class PowerWallChargingStatusSensor(PowerWallEntity, BinarySensorEntity):
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_BATTERY_CHARGING
return BinarySensorDeviceClass.BATTERY_CHARGING
@property
def unique_id(self):

View File

@ -4,18 +4,11 @@ import logging
from tesla_powerwall import MeterType
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_KILO_WATT,
)
from homeassistant.const import ENERGY_KILO_WATT_HOUR, PERCENTAGE, POWER_KILO_WATT
from .const import (
ATTR_FREQUENCY,
@ -92,7 +85,7 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
_attr_name = "Powerwall Charge"
_attr_native_unit_of_measurement = PERCENTAGE
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_device_class = SensorDeviceClass.BATTERY
@property
def unique_id(self):
@ -108,9 +101,9 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Energy sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = POWER_KILO_WATT
_attr_device_class = DEVICE_CLASS_POWER
_attr_device_class = SensorDeviceClass.POWER
def __init__(
self,
@ -155,9 +148,9 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
class PowerWallEnergyDirectionSensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Direction Energy sensor."""
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
_attr_state_class = SensorStateClass.TOTAL_INCREASING
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_device_class = SensorDeviceClass.ENERGY
def __init__(
self,