Added entity category support

This commit is contained in:
tomaae 2021-12-13 13:45:07 +01:00
parent 448483da22
commit 274de8c6fd
2 changed files with 32 additions and 1 deletions

View file

@ -11,6 +11,7 @@ from homeassistant.const import (
TEMP_CELSIUS,
)
from homeassistant.helpers.entity import EntityCategory
from homeassistant.components.sensor import SensorDeviceClass
from .const import (
@ -51,6 +52,7 @@ ATTR_UNIT_ATTR = "unit_attr"
ATTR_GROUP = "group"
ATTR_PATH = "data_path"
ATTR_ATTR = "data_attr"
ATTR_CTGR = "entity_category"
SENSOR_TYPES = {
"system_temperature": {
@ -115,6 +117,7 @@ SENSOR_TYPES = {
ATTR_GROUP: "System",
ATTR_PATH: "resource",
ATTR_ATTR: "uptime",
ATTR_CTGR: EntityCategory.DIAGNOSTIC,
},
"system_cpu-load": {
ATTR_DEVICE_CLASS: None,
@ -366,6 +369,11 @@ class MikrotikControllerSensor(SensorEntity):
self._device_class = None
self._state = None
if ATTR_CTGR in self._type:
self._entity_category = self._type[ATTR_CTGR]
else:
self._entity_category = None
if ATTR_ICON in self._type:
self._icon = self._type[ATTR_ICON]
else:
@ -401,6 +409,14 @@ class MikrotikControllerSensor(SensorEntity):
return None
@property
def entity_category(self) -> str:
"""Return entity category"""
if self._entity_category:
return self._entity_category
return None
@property
def device_class(self) -> Optional[str]:
"""Return the device class."""