Determine zwave_js sensor device class during initialization (#48304)
parent
6660fb7478
commit
058d232c57
|
@ -80,10 +80,15 @@ class ZwaveSensorBase(ZWaveBaseEntity, SensorEntity):
|
|||
"""Initialize a ZWaveSensorBase entity."""
|
||||
super().__init__(config_entry, client, info)
|
||||
self._name = self.generate_name(include_value_name=True)
|
||||
self._device_class = self._get_device_class()
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
"""Return the device class of the sensor."""
|
||||
def _get_device_class(self) -> str | None:
|
||||
"""
|
||||
Get the device class of the sensor.
|
||||
|
||||
This should be run once during initialization so we don't have to calculate
|
||||
this value on every state update.
|
||||
"""
|
||||
if self.info.primary_value.command_class == CommandClass.BATTERY:
|
||||
return DEVICE_CLASS_BATTERY
|
||||
if self.info.primary_value.command_class == CommandClass.METER:
|
||||
|
@ -102,6 +107,11 @@ class ZwaveSensorBase(ZWaveBaseEntity, SensorEntity):
|
|||
return DEVICE_CLASS_ILLUMINANCE
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_class(self) -> str | None:
|
||||
"""Return the device class of the sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
|
|
Loading…
Reference in New Issue