mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 12:47:53 +00:00
Migrate Emonitor to has entity name (#107153)
This commit is contained in:
parent
eb320b69bc
commit
bf229be7bb
@ -27,10 +27,12 @@ from .const import DOMAIN
|
|||||||
SENSORS = (
|
SENSORS = (
|
||||||
SensorEntityDescription(key="inst_power"),
|
SensorEntityDescription(key="inst_power"),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="avg_power", name="Average", entity_registry_enabled_default=False
|
key="avg_power",
|
||||||
|
translation_key="average",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
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_device_class = SensorDeviceClass.POWER
|
||||||
_attr_native_unit_of_measurement = UnitOfPower.WATT
|
_attr_native_unit_of_measurement = UnitOfPower.WATT
|
||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -79,9 +82,9 @@ class EmonitorPowerSensor(CoordinatorEntity, SensorEntity):
|
|||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
mac_address = self.emonitor_status.network.mac_address
|
mac_address = self.emonitor_status.network.mac_address
|
||||||
device_name = name_short_mac(mac_address[-6:])
|
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:
|
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}"
|
self._attr_unique_id = f"{mac_address}_{channel_number}_{description.key}"
|
||||||
else:
|
else:
|
||||||
self._attr_name = label
|
self._attr_name = label
|
||||||
|
@ -22,5 +22,15 @@
|
|||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"sensor": {
|
||||||
|
"average": {
|
||||||
|
"name": "{label} average"
|
||||||
|
},
|
||||||
|
"max": {
|
||||||
|
"name": "{label} max"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user