Migrate Emonitor to has entity name (#107153)
parent
eb320b69bc
commit
bf229be7bb
|
@ -27,10 +27,12 @@ from .const import DOMAIN
|
|||
SENSORS = (
|
||||
SensorEntityDescription(key="inst_power"),
|
||||
SensorEntityDescription(
|
||||
key="avg_power", name="Average", entity_registry_enabled_default=False
|
||||
key="avg_power",
|
||||
translation_key="average",
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="max_power", name="Max", entity_registry_enabled_default=False
|
||||
key="max_power", translation_key="max", entity_registry_enabled_default=False
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -66,6 +68,7 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
|
|||
_attr_device_class = SensorDeviceClass.POWER
|
||||
_attr_native_unit_of_measurement = UnitOfPower.WATT
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -79,9 +82,9 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
|
|||
super().__init__(coordinator)
|
||||
mac_address = self.emonitor_status.network.mac_address
|
||||
device_name = name_short_mac(mac_address[-6:])
|
||||
label = self.channel_data.label or f"{device_name} {channel_number}"
|
||||
label = self.channel_data.label or str(channel_number)
|
||||
if description.name is not UNDEFINED:
|
||||
self._attr_name = f"{label} {description.name}"
|
||||
self._attr_translation_placeholders = {"label": label}
|
||||
self._attr_unique_id = f"{mac_address}_{channel_number}_{description.key}"
|
||||
else:
|
||||
self._attr_name = label
|
||||
|
|
|
@ -22,5 +22,15 @@
|
|||
"abort": {
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"sensor": {
|
||||
"average": {
|
||||
"name": "{label} average"
|
||||
},
|
||||
"max": {
|
||||
"name": "{label} max"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue