Use shorthand attrs for device_class zwave_js sensor (#100414)
* Use shorthand attrs zwave_js sensor * Simplify
This commit is contained in:
parent
d25f45a957
commit
9747e0091f
1 changed files with 3 additions and 29 deletions
|
@ -17,7 +17,7 @@ from zwave_js_server.model.controller.statistics import ControllerStatisticsData
|
|||
from zwave_js_server.model.driver import Driver
|
||||
from zwave_js_server.model.node import Node as ZwaveNode
|
||||
from zwave_js_server.model.node.statistics import NodeStatisticsDataType
|
||||
from zwave_js_server.model.value import ConfigurationValue, ConfigurationValueType
|
||||
from zwave_js_server.model.value import ConfigurationValue
|
||||
from zwave_js_server.util.command_class.meter import get_meter_type
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
|
@ -729,22 +729,9 @@ class ZWaveListSensor(ZwaveSensor):
|
|||
alternate_value_name=self.info.primary_value.property_name,
|
||||
additional_info=[self.info.primary_value.property_key_name],
|
||||
)
|
||||
|
||||
@property
|
||||
def options(self) -> list[str] | None:
|
||||
"""Return options for enum sensor."""
|
||||
if self.device_class == SensorDeviceClass.ENUM:
|
||||
return list(self.info.primary_value.metadata.states.values())
|
||||
return None
|
||||
|
||||
@property
|
||||
def device_class(self) -> SensorDeviceClass | None:
|
||||
"""Return sensor device class."""
|
||||
if (device_class := super().device_class) is not None:
|
||||
return device_class
|
||||
if self.info.primary_value.metadata.states:
|
||||
return SensorDeviceClass.ENUM
|
||||
return None
|
||||
self._attr_device_class = SensorDeviceClass.ENUM
|
||||
self._attr_options = list(info.primary_value.metadata.states.values())
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, str] | None:
|
||||
|
@ -781,19 +768,6 @@ class ZWaveConfigParameterSensor(ZWaveListSensor):
|
|||
additional_info=[property_key_name] if property_key_name else None,
|
||||
)
|
||||
|
||||
@property
|
||||
def device_class(self) -> SensorDeviceClass | None:
|
||||
"""Return sensor device class."""
|
||||
# mypy doesn't know about fget: https://github.com/python/mypy/issues/6185
|
||||
if (device_class := ZwaveSensor.device_class.fget(self)) is not None: # type: ignore[attr-defined]
|
||||
return device_class # type: ignore[no-any-return]
|
||||
if (
|
||||
self._primary_value.configuration_value_type
|
||||
== ConfigurationValueType.ENUMERATED
|
||||
):
|
||||
return SensorDeviceClass.ENUM
|
||||
return None
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, str] | None:
|
||||
"""Return the device specific state attributes."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue