Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PeteRager committed Oct 23, 2024
1 parent aff8c88 commit 5347ad0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
14 changes: 13 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"configurations": [

{
"name": "Python: Debug Tests",
"type": "python",
"type": "",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
Expand All @@ -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"
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"python.experiments.optOutFrom": ["pythonTestAdapter"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"debugpy.debugJustMyCode": false,
"cSpell.words": [
"ASHRAE",
"automations",
Expand Down
25 changes: 23 additions & 2 deletions custom_components/lennoxs30/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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."""
Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
DS_DISCONNECTED,
DS_LOGIN_FAILED,
DS_RETRY_WAIT,
PLATFORMS,
RETRY_INTERVAL_SECONDS,
Manager,
)
Expand Down
35 changes: 34 additions & 1 deletion tests/test_number_equipment_parameter_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,35 @@ 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):
system: lennox_system = manager.api.system_list[0]
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)


Expand All @@ -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)


Expand All @@ -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
Expand Down

0 comments on commit 5347ad0

Please sign in to comment.