mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use enums in tplink (#62023)
This commit is contained in:
parent
357d91fb0e
commit
fcda72a337
@ -7,18 +7,14 @@ from typing import cast
|
|||||||
from kasa import SmartDevice
|
from kasa import SmartDevice
|
||||||
|
|
||||||
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 (
|
||||||
ATTR_VOLTAGE,
|
ATTR_VOLTAGE,
|
||||||
DEVICE_CLASS_CURRENT,
|
|
||||||
DEVICE_CLASS_ENERGY,
|
|
||||||
DEVICE_CLASS_POWER,
|
|
||||||
DEVICE_CLASS_VOLTAGE,
|
|
||||||
ELECTRIC_CURRENT_AMPERE,
|
ELECTRIC_CURRENT_AMPERE,
|
||||||
ELECTRIC_POTENTIAL_VOLT,
|
ELECTRIC_POTENTIAL_VOLT,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
@ -51,8 +47,8 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = (
|
|||||||
TPLinkSensorEntityDescription(
|
TPLinkSensorEntityDescription(
|
||||||
key=ATTR_CURRENT_POWER_W,
|
key=ATTR_CURRENT_POWER_W,
|
||||||
native_unit_of_measurement=POWER_WATT,
|
native_unit_of_measurement=POWER_WATT,
|
||||||
device_class=DEVICE_CLASS_POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
name="Current Consumption",
|
name="Current Consumption",
|
||||||
emeter_attr="power",
|
emeter_attr="power",
|
||||||
precision=1,
|
precision=1,
|
||||||
@ -60,8 +56,8 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = (
|
|||||||
TPLinkSensorEntityDescription(
|
TPLinkSensorEntityDescription(
|
||||||
key=ATTR_TOTAL_ENERGY_KWH,
|
key=ATTR_TOTAL_ENERGY_KWH,
|
||||||
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,
|
||||||
name="Total Consumption",
|
name="Total Consumption",
|
||||||
emeter_attr="total",
|
emeter_attr="total",
|
||||||
precision=3,
|
precision=3,
|
||||||
@ -69,16 +65,16 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = (
|
|||||||
TPLinkSensorEntityDescription(
|
TPLinkSensorEntityDescription(
|
||||||
key=ATTR_TODAY_ENERGY_KWH,
|
key=ATTR_TODAY_ENERGY_KWH,
|
||||||
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,
|
||||||
name="Today's Consumption",
|
name="Today's Consumption",
|
||||||
precision=3,
|
precision=3,
|
||||||
),
|
),
|
||||||
TPLinkSensorEntityDescription(
|
TPLinkSensorEntityDescription(
|
||||||
key=ATTR_VOLTAGE,
|
key=ATTR_VOLTAGE,
|
||||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||||
device_class=DEVICE_CLASS_VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
name="Voltage",
|
name="Voltage",
|
||||||
emeter_attr="voltage",
|
emeter_attr="voltage",
|
||||||
precision=1,
|
precision=1,
|
||||||
@ -86,8 +82,8 @@ ENERGY_SENSORS: tuple[TPLinkSensorEntityDescription, ...] = (
|
|||||||
TPLinkSensorEntityDescription(
|
TPLinkSensorEntityDescription(
|
||||||
key=ATTR_CURRENT_A,
|
key=ATTR_CURRENT_A,
|
||||||
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,
|
||||||
name="Current",
|
name="Current",
|
||||||
emeter_attr="current",
|
emeter_attr="current",
|
||||||
precision=2,
|
precision=2,
|
||||||
|
@ -8,8 +8,8 @@ from kasa import SmartDevice
|
|||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ENTITY_CATEGORY_CONFIG
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import legacy_device_id
|
from . import legacy_device_id
|
||||||
@ -49,7 +49,7 @@ class SmartPlugLedSwitch(CoordinatedTPLinkEntity, SwitchEntity):
|
|||||||
|
|
||||||
coordinator: TPLinkDataUpdateCoordinator
|
coordinator: TPLinkDataUpdateCoordinator
|
||||||
|
|
||||||
_attr_entity_category = ENTITY_CATEGORY_CONFIG
|
_attr_entity_category = EntityCategory.CONFIG
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, device: SmartDevice, coordinator: TPLinkDataUpdateCoordinator
|
self, device: SmartDevice, coordinator: TPLinkDataUpdateCoordinator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user