Add entity category to Shelly (#57705)
parent
4745e58a92
commit
3127074f76
|
@ -18,6 +18,7 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -41,16 +42,24 @@ from .utils import (
|
|||
|
||||
SENSORS: Final = {
|
||||
("device", "overtemp"): BlockAttributeDescription(
|
||||
name="Overheating", device_class=DEVICE_CLASS_PROBLEM
|
||||
name="Overheating",
|
||||
device_class=DEVICE_CLASS_PROBLEM,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("device", "overpower"): BlockAttributeDescription(
|
||||
name="Overpowering", device_class=DEVICE_CLASS_PROBLEM
|
||||
name="Overpowering",
|
||||
device_class=DEVICE_CLASS_PROBLEM,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("light", "overpower"): BlockAttributeDescription(
|
||||
name="Overpowering", device_class=DEVICE_CLASS_PROBLEM
|
||||
name="Overpowering",
|
||||
device_class=DEVICE_CLASS_PROBLEM,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("relay", "overpower"): BlockAttributeDescription(
|
||||
name="Overpowering", device_class=DEVICE_CLASS_PROBLEM
|
||||
name="Overpowering",
|
||||
device_class=DEVICE_CLASS_PROBLEM,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("sensor", "dwIsOpened"): BlockAttributeDescription(
|
||||
name="Door",
|
||||
|
@ -106,6 +115,7 @@ REST_SENSORS: Final = {
|
|||
value=lambda status, _: status["cloud"]["connected"],
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
"fwupdate": RestAttributeDescription(
|
||||
name="Firmware Update",
|
||||
|
@ -116,6 +126,7 @@ REST_SENSORS: Final = {
|
|||
"latest_stable_version": status["update"]["new_version"],
|
||||
"installed_version": status["update"]["old_version"],
|
||||
},
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -134,6 +145,7 @@ RPC_SENSORS: Final = {
|
|||
name="Cloud",
|
||||
device_class=DEVICE_CLASS_CONNECTIVITY,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
"fwupdate": RpcAttributeDescription(
|
||||
key="sys",
|
||||
|
@ -145,6 +157,7 @@ RPC_SENSORS: Final = {
|
|||
"latest_stable_version": status.get("stable", {"version": ""})["version"],
|
||||
"beta_version": status.get("beta", {"version": ""})["version"],
|
||||
},
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
@ -237,6 +237,7 @@ class BlockAttributeDescription:
|
|||
# Callable (settings, block), return true if entity should be removed
|
||||
removal_condition: Callable[[dict, Block], bool] | None = None
|
||||
extra_state_attributes: Callable[[Block], dict | None] | None = None
|
||||
entity_category: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -255,6 +256,7 @@ class RpcAttributeDescription:
|
|||
available: Callable[[dict], bool] | None = None
|
||||
removal_condition: Callable[[dict, str], bool] | None = None
|
||||
extra_state_attributes: Callable[[dict], dict | None] | None = None
|
||||
entity_category: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -269,6 +271,7 @@ class RestAttributeDescription:
|
|||
state_class: str | None = None
|
||||
default_enabled: bool = True
|
||||
extra_state_attributes: Callable[[dict], dict | None] | None = None
|
||||
entity_category: str | None = None
|
||||
|
||||
|
||||
class ShellyBlockEntity(entity.Entity):
|
||||
|
@ -469,6 +472,11 @@ class ShellyBlockAttributeEntity(ShellyBlockEntity, entity.Entity):
|
|||
|
||||
return self.description.extra_state_attributes(self.block)
|
||||
|
||||
@property
|
||||
def entity_category(self) -> str | None:
|
||||
"""Return category of entity."""
|
||||
return self.description.entity_category
|
||||
|
||||
|
||||
class ShellyRestAttributeEntity(update_coordinator.CoordinatorEntity):
|
||||
"""Class to load info from REST."""
|
||||
|
@ -541,6 +549,11 @@ class ShellyRestAttributeEntity(update_coordinator.CoordinatorEntity):
|
|||
|
||||
return self.description.extra_state_attributes(self.wrapper.device.status)
|
||||
|
||||
@property
|
||||
def entity_category(self) -> str | None:
|
||||
"""Return category of entity."""
|
||||
return self.description.entity_category
|
||||
|
||||
|
||||
class ShellyRpcAttributeEntity(ShellyRpcEntity, entity.Entity):
|
||||
"""Helper class to represent a rpc attribute."""
|
||||
|
@ -599,6 +612,11 @@ class ShellyRpcAttributeEntity(ShellyRpcEntity, entity.Entity):
|
|||
self.wrapper.device.status[self.key][self.sub_key]
|
||||
)
|
||||
|
||||
@property
|
||||
def entity_category(self) -> str | None:
|
||||
"""Return category of entity."""
|
||||
return self.description.entity_category
|
||||
|
||||
|
||||
class ShellySleepingBlockAttributeEntity(ShellyBlockAttributeEntity, RestoreEntity):
|
||||
"""Represent a shelly sleeping block attribute entity."""
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||
ELECTRIC_CURRENT_AMPERE,
|
||||
ELECTRIC_POTENTIAL_VOLT,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
|
@ -45,6 +46,7 @@ SENSORS: Final = {
|
|||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
removal_condition=lambda settings, _: settings.get("external_power") == 1,
|
||||
available=lambda block: cast(int, block.battery) != -1,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("device", "deviceTemp"): BlockAttributeDescription(
|
||||
name="Device Temperature",
|
||||
|
@ -53,6 +55,7 @@ SENSORS: Final = {
|
|||
device_class=sensor.DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("emeter", "current"): BlockAttributeDescription(
|
||||
name="Current",
|
||||
|
@ -205,6 +208,7 @@ SENSORS: Final = {
|
|||
extra_state_attributes=lambda block: {
|
||||
"Operational hours": round(cast(int, block.totalWorkTime) / 3600, 1)
|
||||
},
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
("adc", "adc"): BlockAttributeDescription(
|
||||
name="ADC",
|
||||
|
@ -229,12 +233,14 @@ REST_SENSORS: Final = {
|
|||
device_class=sensor.DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
"uptime": RestAttributeDescription(
|
||||
name="Uptime",
|
||||
value=lambda status, last: get_device_uptime(status["uptime"], last),
|
||||
device_class=sensor.DEVICE_CLASS_TIMESTAMP,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -286,6 +292,7 @@ RPC_SENSORS: Final = {
|
|||
device_class=sensor.DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
state_class=sensor.STATE_CLASS_MEASUREMENT,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
"uptime": RpcAttributeDescription(
|
||||
key="sys",
|
||||
|
@ -294,6 +301,7 @@ RPC_SENSORS: Final = {
|
|||
value=get_device_uptime,
|
||||
device_class=sensor.DEVICE_CLASS_TIMESTAMP,
|
||||
default_enabled=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue