diff --git a/.vscode/launch.json b/.vscode/launch.json index 4bae663..42c6c32 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,8 +1,9 @@ { "configurations": [ + { "name": "Python: Debug Tests", - "type": "python", + "type": "", "request": "launch", "program": "${file}", "purpose": ["debug-test"], @@ -12,6 +13,17 @@ "hidden": true, // keep original launch order in 'run and debug' tab } }, + { + "name": "Debug Tests", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false, + "presentation": { + "hidden": true, // keep original launch order in 'run and debug' tab + } + } ], "version": "0.2.0" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 823b7af..7a2d01a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,6 +5,7 @@ "python.experiments.optOutFrom": ["pythonTestAdapter"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, + "debugpy.debugJustMyCode": false, "cSpell.words": [ "ASHRAE", "automations", diff --git a/custom_components/lennoxs30/number.py b/custom_components/lennoxs30/number.py index 144f7ab..91e7708 100644 --- a/custom_components/lennoxs30/number.py +++ b/custom_components/lennoxs30/number.py @@ -9,11 +9,12 @@ from typing import Any import voluptuous as vol -from homeassistant.components.number import NumberEntity +from homeassistant.components.number import NumberEntity, NumberDeviceClass from homeassistant.const import ( PERCENTAGE, UnitOfTemperature, UnitOfTime, + UnitOfVolumeFlowRate, ) from homeassistant.helpers import config_validation as cv from homeassistant.exceptions import HomeAssistantError @@ -437,6 +438,11 @@ def device_info(self) -> DeviceInfo: class EquipmentParameterNumber(S30BaseEntityMixin, NumberEntity): """Set timed ventilation.""" + absolute_temperature_pids: list[int] = [ + 202, 203, 105, 106, 128, 129, 55, 178, 194, + 195, 179, 297, 298, 299, 300, 301, 302, 326, 327, 328 + ] + def __init__( self, hass: HomeAssistant, @@ -508,7 +514,7 @@ def native_step(self) -> float: @property def native_value(self) -> float: - return self.parameter.value + return float(self.parameter.value) async def async_set_native_value(self, value: float) -> None: """Update the current value.""" @@ -529,6 +535,21 @@ async def async_set_native_value(self, value: float) -> None: @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 + 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 + @property def device_info(self) -> DeviceInfo: diff --git a/tests/test_manager.py b/tests/test_manager.py index 0df6c29..21d4f3d 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -38,7 +38,6 @@ DS_DISCONNECTED, DS_LOGIN_FAILED, DS_RETRY_WAIT, - PLATFORMS, RETRY_INTERVAL_SECONDS, Manager, ) diff --git a/tests/test_number_equipment_parameter_number.py b/tests/test_number_equipment_parameter_number.py index 99a903b..f88522b 100644 --- a/tests/test_number_equipment_parameter_number.py +++ b/tests/test_number_equipment_parameter_number.py @@ -54,8 +54,26 @@ async def test_equipment_parameter_number_unit_of_measure(hass, manager: Manager equipment = system.equipment[0] parameter = equipment.parameters[72] c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) + c.hass = hass + + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS + assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT + assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT + + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT + assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS + parameter = equipment.parameters[202] + c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) + c.hass = hass + assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT + assert c.unit_of_measurement == UnitOfTemperature.CELSIUS + + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT + assert c.native_unit_of_measurement == UnitOfTemperature.FAHRENHEIT + assert c.unit_of_measurement == UnitOfTemperature.FAHRENHEIT @pytest.mark.asyncio async def test_equipment_parameter_number_max_value(hass, manager: Manager): @@ -63,6 +81,8 @@ async def test_equipment_parameter_number_max_value(hass, manager: Manager): equipment = system.equipment[0] parameter = equipment.parameters[72] c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) + c.hass = hass + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT assert c.max_value == float(parameter.range_max) @@ -72,6 +92,9 @@ async def test_equipment_parameter_number_min_value(hass, manager: Manager): equipment = system.equipment[0] parameter = equipment.parameters[72] c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) + c.hass = hass + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT + assert c.min_value == float(parameter.range_min) @@ -90,7 +113,17 @@ async def test_equipment_parameter_number_value(hass, manager: Manager): equipment = system.equipment[0] parameter = equipment.parameters[72] c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) - assert c.value == parameter.value + c.hass = hass + hass.config.units.temperature_unit = UnitOfTemperature.FAHRENHEIT + assert c.value == float(parameter.value) + + hass.config.units.temperature_unit = UnitOfTemperature.CELSIUS + assert c.value == float(parameter.value) + + parameter = equipment.parameters[202] + c = EquipmentParameterNumber(hass, manager, system, equipment, parameter) + c.hass = hass + assert c.value == 21.1 @pytest.mark.asyncio