From 286f9455f91465132db3490d36ae305d33809b56 Mon Sep 17 00:00:00 2001 From: PeteRager <76050312+PeteRager@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:13:19 -0400 Subject: [PATCH] RPM diagnostics have no units --- custom_components/lennoxs30/sensor.py | 11 +++++++++-- tests/test_diag_sensor.py | 9 +++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/custom_components/lennoxs30/sensor.py b/custom_components/lennoxs30/sensor.py index f5794e7..6ad8d56 100644 --- a/custom_components/lennoxs30/sensor.py +++ b/custom_components/lennoxs30/sensor.py @@ -14,6 +14,7 @@ UnitOfFrequency, UnitOfElectricCurrent, UnitOfElectricPotential, + REVOLUTIONS_PER_MINUTE, ) from homeassistant.core import HomeAssistant from homeassistant.config_entries import ConfigEntry @@ -182,7 +183,13 @@ def __init__( self._equipment: lennox_equipment = equipment self._diagnostic: lennox_equipment_diagnostic = diagnostic - if diagnostic.unit.strip() == "": + self.uom = diagnostic.unit.strip() + if self.uom == "": + # Lennox does not provide a unit for RPM + if self._diagnostic.name.endswith("RPM"): + self.uom = REVOLUTIONS_PER_MINUTE + + if self.uom == "": self._state_class = None else: self._state_class = SensorStateClass.MEASUREMENT @@ -255,7 +262,7 @@ def name(self): @property def native_unit_of_measurement(self): - return lennox_uom_to_ha_uom(self._diagnostic.unit) + return lennox_uom_to_ha_uom(self.uom) @property def device_class(self): diff --git a/tests/test_diag_sensor.py b/tests/test_diag_sensor.py index 4d5c0c5..7281be5 100644 --- a/tests/test_diag_sensor.py +++ b/tests/test_diag_sensor.py @@ -17,6 +17,7 @@ VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE, ELECTRIC_POTENTIAL_VOLT, TIME_MINUTES, + REVOLUTIONS_PER_MINUTE, ) from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass from homeassistant.helpers.entity import EntityCategory @@ -157,6 +158,14 @@ async def test_diag_sensor_unit_of_measure_device_class(hass, manager: Manager): assert s.unit_of_measurement == PERCENTAGE assert s.device_class is None + equipment = system.equipment[2] + diagnostic = equipment.diagnostics[4] + assert diagnostic.name.endswith("RPM") + assert diagnostic.unit.strip() == "" + s = S30DiagSensor(hass, manager, system, equipment, diagnostic) + assert s.native_unit_of_measurement == REVOLUTIONS_PER_MINUTE + assert s.device_class is None + equipment = system.equipment[1] diagnostic = equipment.diagnostics[9] s = S30DiagSensor(hass, manager, system, equipment, diagnostic)