For some reason my battery sensor is setup with name “none” instead of “battery”, like “tablet_none” instead of “tablet_battery”. The SensorEntityDescription
instance defines the device_class
as SensorDeviceClass.BATTERY
. I was told that this should automatically assign the device a name based on the device_class
. However, the device ends up returning none
for name
.
SensorEntityDescription(
key="batteryLevel",
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
)
I see that Entity
depends on platform.component_translations
to get the name off the device class, but in my case platform.component_translations
is an empty dictionary and therefore returns None
when calling get
on it with the translation key. Thus the device receives the name “none”.
I wonder if perhaps this is due to the local language being English, which doesn’t any translation. But still, why isn’t the name being set from the device class? Or are both properties not related actually?