diff --git a/custom_components/lennoxs30/number.py b/custom_components/lennoxs30/number.py index 6954751..142359f 100644 --- a/custom_components/lennoxs30/number.py +++ b/custom_components/lennoxs30/number.py @@ -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.""" @@ -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 diff --git a/tests/test_number_equipment_parameter_number.py b/tests/test_number_equipment_parameter_number.py index 19a1197..bb63d2c 100644 --- a/tests/test_number_equipment_parameter_number.py +++ b/tests/test_number_equipment_parameter_number.py @@ -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 @@ -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] @@ -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 @@ -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]