Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteRager committed Oct 25, 2024
1 parent b623be2 commit f42c171
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
16 changes: 6 additions & 10 deletions custom_components/lennoxs30/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,9 @@ def __init__(
parameter.pid,
self._myname,
)
self._attr_native_unit_of_measurement = lennox_uom_to_ha_uom(self.parameter.unit)
self._attr_device_class = self._get_device_class()


async def async_added_to_hass(self) -> None:
"""Run when entity about to be added to hass."""
Expand Down Expand Up @@ -533,22 +536,15 @@ async def async_set_native_value(self, value: float) -> None:
f"set_native_value unexpected exception, please log issue, [{self._myname}] exception [{ex}]"
) from ex

@property
def native_unit_of_measurement(self):
return lennox_uom_to_ha_uom(self.parameter.unit)

@property
def device_class(self):
uom = self.native_unit_of_measurement

def _get_device_class(self)->NumberDeviceClass|None:
uom = self._attr_native_unit_of_measurement
if uom in (UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT):
# Many of the parameters are temperature offsets, for now we only
# report absolute temperatures as having the device_class which allows
# then to be automatically translated to celsius
if self.parameter.pid in self.absolute_temperature_pids:
return NumberDeviceClass.TEMPERATURE
return None
if uom == UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE:
return NumberDeviceClass.VOLUME_FLOW_RATE
return None


Expand Down
17 changes: 15 additions & 2 deletions tests/test_number_equipment_parameter_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from unittest.mock import patch
import pytest

from homeassistant.const import UnitOfTemperature
from homeassistant.const import UnitOfTemperature, UnitOfVolumeFlowRate
from homeassistant.exceptions import HomeAssistantError
from homeassistant.components.number import NumberDeviceClass


from lennoxs30api.s30api_async import lennox_system

Expand Down Expand Up @@ -49,7 +51,7 @@ async def test_equipment_parameter_number_name(hass, manager: Manager):


@pytest.mark.asyncio
async def test_equipment_parameter_number_unit_of_measure(hass, manager: Manager):
async def test_equipment_parameter_number_uom_device_class(hass, manager: Manager):
system: lennox_system = manager.api.system_list[0]
equipment = system.equipment[0]
parameter = equipment.parameters[72]
Expand All @@ -61,6 +63,7 @@ async def test_equipment_parameter_number_unit_of_measure(hass, manager: Manager
hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS
assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT
assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT
assert c.device_class is None

hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT
assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT
Expand All @@ -74,11 +77,21 @@ async def test_equipment_parameter_number_unit_of_measure(hass, manager: Manager
c.hass = hass
assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT
assert c.unit_of_measurement == UnitOfTemperature.CELSIUS
assert c.device_class == NumberDeviceClass.TEMPERATURE

hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT
assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT
assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT

equipment = system.equipment[2]
parameter = equipment.parameters[19]
c = EquipmentParameterNumber(hass, manager, system, equipment, parameter)
c.hass = hass
assert c.native_unit_of_measurement == UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE
assert c.unit_of_measurement == UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE
assert c.device_class is None


@pytest.mark.asyncio
async def test_equipment_parameter_number_max_value(hass, manager: Manager):
system: lennox_system = manager.api.system_list[0]
Expand Down

0 comments on commit f42c171

Please sign in to comment.