Skip to content

Commit

Permalink
Merge pull request #259 from PeteRager/RPM-sensors-no-units
Browse files Browse the repository at this point in the history
RPM diagnostics have no units
  • Loading branch information
PeteRager authored Oct 3, 2023
2 parents 83fae82 + 286f945 commit 295e287
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions custom_components/lennoxs30/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
UnitOfFrequency,
UnitOfElectricCurrent,
UnitOfElectricPotential,
REVOLUTIONS_PER_MINUTE,
)
from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 9 additions & 0 deletions tests/test_diag_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 295e287

Please sign in to comment.