The use of the DEVICE_CLASS_* constants and DEVICE_CLASSES constants in all entity platforms, has now been depreacted. Instead, use the equavalent DeviceClass StrEnum provided by each platform.

This commit is contained in:
tomaae 2021-12-13 11:42:55 +01:00
parent e10ab3e0ee
commit 74a4a367dd
2 changed files with 11 additions and 11 deletions

View file

@ -3,9 +3,10 @@
import logging import logging
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
DEVICE_CLASS_CONNECTIVITY, BinarySensorDeviceClass,
) )
from homeassistant.const import ( from homeassistant.const import (
CONF_NAME, CONF_NAME,
@ -332,7 +333,7 @@ class MikrotikControllerPPPSecretBinarySensor(MikrotikControllerBinarySensor):
@property @property
def device_class(self) -> Optional[str]: def device_class(self) -> Optional[str]:
"""Return the device class.""" """Return the device class."""
return DEVICE_CLASS_CONNECTIVITY return BinarySensorDeviceClass.CONNECTIVITY
@property @property
def available(self) -> bool: def available(self) -> bool:
@ -426,7 +427,7 @@ class MikrotikControllerPortBinarySensor(MikrotikControllerBinarySensor):
@property @property
def device_class(self) -> Optional[str]: def device_class(self) -> Optional[str]:
"""Return the device class.""" """Return the device class."""
return DEVICE_CLASS_CONNECTIVITY return BinarySensorDeviceClass.CONNECTIVITY
@property @property
def available(self) -> bool: def available(self) -> bool:

View file

@ -7,12 +7,11 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
ATTR_ATTRIBUTION, ATTR_ATTRIBUTION,
ATTR_DEVICE_CLASS, ATTR_DEVICE_CLASS,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
DEVICE_CLASS_POWER,
TEMP_CELSIUS, TEMP_CELSIUS,
) )
from homeassistant.components.sensor import SensorDeviceClass
from .const import ( from .const import (
CONF_SENSOR_PORT_TRAFFIC, CONF_SENSOR_PORT_TRAFFIC,
DEFAULT_SENSOR_PORT_TRAFFIC, DEFAULT_SENSOR_PORT_TRAFFIC,
@ -54,7 +53,7 @@ ATTR_ATTR = "data_attr"
SENSOR_TYPES = { SENSOR_TYPES = {
"system_temperature": { "system_temperature": {
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_LABEL: "Temperature", ATTR_LABEL: "Temperature",
ATTR_UNIT: TEMP_CELSIUS, ATTR_UNIT: TEMP_CELSIUS,
@ -63,7 +62,7 @@ SENSOR_TYPES = {
ATTR_ATTR: "temperature", ATTR_ATTR: "temperature",
}, },
"system_cpu-temperature": { "system_cpu-temperature": {
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_LABEL: "CPU temperature", ATTR_LABEL: "CPU temperature",
ATTR_UNIT: TEMP_CELSIUS, ATTR_UNIT: TEMP_CELSIUS,
@ -72,7 +71,7 @@ SENSOR_TYPES = {
ATTR_ATTR: "cpu-temperature", ATTR_ATTR: "cpu-temperature",
}, },
"system_board-temperature1": { "system_board-temperature1": {
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_ICON: "mdi:thermometer", ATTR_ICON: "mdi:thermometer",
ATTR_LABEL: "Board temperature", ATTR_LABEL: "Board temperature",
ATTR_UNIT: TEMP_CELSIUS, ATTR_UNIT: TEMP_CELSIUS,
@ -81,7 +80,7 @@ SENSOR_TYPES = {
ATTR_ATTR: "board-temperature1", ATTR_ATTR: "board-temperature1",
}, },
"system_power-consumption": { "system_power-consumption": {
ATTR_DEVICE_CLASS: DEVICE_CLASS_POWER, ATTR_DEVICE_CLASS: SensorDeviceClass.POWER,
ATTR_ICON: "mdi:transmission-tower", ATTR_ICON: "mdi:transmission-tower",
ATTR_LABEL: "Power consumption", ATTR_LABEL: "Power consumption",
ATTR_UNIT: "W", ATTR_UNIT: "W",
@ -108,7 +107,7 @@ SENSOR_TYPES = {
ATTR_ATTR: "fan2-speed", ATTR_ATTR: "fan2-speed",
}, },
"system_uptime": { "system_uptime": {
ATTR_DEVICE_CLASS: DEVICE_CLASS_TIMESTAMP, ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
ATTR_ICON: None, ATTR_ICON: None,
ATTR_LABEL: "Uptime", ATTR_LABEL: "Uptime",
ATTR_UNIT: None, ATTR_UNIT: None,