From 9747e0091f99a92e8a9c6c9d79b1318ab8ddd7d6 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Sat, 16 Sep 2023 10:13:27 +0200 Subject: [PATCH] Use shorthand attrs for device_class zwave_js sensor (#100414) * Use shorthand attrs zwave_js sensor * Simplify --- homeassistant/components/zwave_js/sensor.py | 32 ++------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index 3c22288a1d6..8d42bcfb366 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -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."""