Use enums in senses (#62050)

This commit is contained in:
Robert Hillis 2021-12-16 08:25:12 -05:00 committed by GitHub
parent 65b67d9d91
commit b6ed3e87e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View file

@ -1,8 +1,11 @@
"""Support for monitoring a Sense energy sensor device."""
import logging
from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, DEVICE_CLASS_POWER
from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_registry import async_get_registry
@ -113,7 +116,7 @@ class SenseDevice(BinarySensorEntity):
@property
def device_class(self):
"""Return the device class of the binary sensor."""
return DEVICE_CLASS_POWER
return BinarySensorDeviceClass.POWER
@property
def should_poll(self):

View file

@ -1,13 +1,11 @@
"""Support for monitoring a Sense energy sensor."""
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
@ -157,7 +155,7 @@ class SenseActiveSensor(SensorEntity):
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
_attr_should_poll = False
_attr_available = False
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_state_class = SensorStateClass.MEASUREMENT
def __init__(
self,
@ -250,8 +248,8 @@ class SenseVoltageSensor(SensorEntity):
class SenseTrendsSensor(CoordinatorEntity, SensorEntity):
"""Implementation of a Sense energy sensor."""
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_state_class = STATE_CLASS_TOTAL
_attr_device_class = SensorDeviceClass.ENERGY
_attr_state_class = SensorStateClass.TOTAL
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
_attr_icon = ICON
@ -299,10 +297,10 @@ class SenseEnergyDevice(SensorEntity):
"""Implementation of a Sense energy device."""
_attr_available = False
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = POWER_WATT
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
_attr_device_class = DEVICE_CLASS_POWER
_attr_device_class = SensorDeviceClass.POWER
_attr_should_poll = False
def __init__(self, sense_devices_data, device, sense_monitor_id):