Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
maximvelichko committed Oct 30, 2023
1 parent b632800 commit 5f9e417
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 33 deletions.
6 changes: 3 additions & 3 deletions pyvera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ def _has_double_setpoints(self) -> bool:

return False

def _is_heating_recommened(self) -> bool:
def _is_heating_recommended(self) -> bool:
mode = self.get_value("mode")
state = self.get_value("hvacstate")

Expand All @@ -1374,7 +1374,7 @@ def _is_heating_recommened(self) -> bool:
@property
def _setpoint_cache_value_name(self) -> str:
if self._has_double_setpoints():
if self._is_heating_recommened():
if self._is_heating_recommended():
return "heatsp"
else:
return "coolsp"
Expand All @@ -1384,7 +1384,7 @@ def _setpoint_cache_value_name(self) -> str:
@property
def _thermostat_setpoint(self) -> str:
if self._has_double_setpoints():
if self._is_heating_recommened():
if self._is_heating_recommended():
return self.thermostat_heat_setpoint
else:
return self.thermostat_cool_setpoint
Expand Down
34 changes: 34 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ def callback(req: requests.PreparedRequest) -> ResponsesResponse:
DEVICE_GARAGE_DOOR_ID = 47
DEVICE_LOCK_ID = 10
DEVICE_THERMOSTAT_ID = 11
DEVICE_THERMOSTAT2_ID = 18
DEVICE_CURTAIN_ID = 12
DEVICE_SCENE_CONTROLLER_ID = 13
DEVICE_LIGHT_SENSOR_ID = 14
Expand Down Expand Up @@ -566,6 +567,31 @@ def callback(req: requests.PreparedRequest) -> ResponsesResponse:
"watts": 23,
"comment": "",
},
{
"name": "Thermostat 2",
"altid": "5",
"id": DEVICE_THERMOSTAT2_ID,
"category": CATEGORY_THERMOSTAT,
"subcategory": 0,
"room": 0,
"parent": 1,
"configured": "1",
"commFailure": "0",
"armedtripped": "1",
"lasttrip": "1561049427",
"tripped": "1",
"armed": "0",
"status": "0",
"state": -1,
"mode": "Off",
"fanmode": "Off",
"hvacstate": "Off",
"heatsp": 7,
"coolsp": 17,
"temperature": 9,
"watts": 23,
"comment": "",
},
{
"name": "Curtain 1",
"altid": "5",
Expand Down Expand Up @@ -816,6 +842,14 @@ def callback(req: requests.PreparedRequest) -> ResponsesResponse:
"tooltip": {"display": 0},
"status": -1,
},
{
"id": DEVICE_THERMOSTAT2_ID,
"states": [],
"Jobs": [],
"PendingJobs": 0,
"tooltip": {"display": 0},
"status": -1,
},
{
"id": DEVICE_CURTAIN_ID,
"states": [],
Expand Down
98 changes: 68 additions & 30 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
DEVICE_SWITCH_ID,
DEVICE_TEMP_SENSOR_ID,
DEVICE_THERMOSTAT_ID,
DEVICE_THERMOSTAT2_ID,
DEVICE_UV_SENSOR_ID,
VeraControllerData,
update_device,
Expand Down Expand Up @@ -108,6 +109,14 @@ def test__event_device_for_vera_lock_status() -> None:
registry._event_device(mock_lock, device_json, [])
mock_lock.update.assert_called_once_with(device_json)

def test_refresh_data(vera_controller_data: VeraControllerData) -> None:
"""Test function."""
controller = vera_controller_data.controller
data = controller.refresh_data()
assert len(data) == 20

services = controller.map_services()
assert services == None

def test_polling(vera_controller_data: VeraControllerData) -> None:
"""Test function."""
Expand Down Expand Up @@ -257,48 +266,77 @@ def test_lock(vera_controller_data: VeraControllerData) -> None:
assert device.clear_slot_pin(slot=1).status_code == 200


# pylint: disable=protected-access
def test_thermostat(vera_controller_data: VeraControllerData) -> None:
"""Test function."""
controller = vera_controller_data.controller
device = cast(VeraThermostat, controller.get_device_by_id(DEVICE_THERMOSTAT_ID))
controller.register(device, lambda device: None)
device1 = cast(VeraThermostat, controller.get_device_by_id(DEVICE_THERMOSTAT_ID))
device2 = cast(VeraThermostat, controller.get_device_by_id(DEVICE_THERMOSTAT2_ID))
controller.register(device1, lambda device: None)
controller.register(device2, lambda device: None)

all_devices = (device1, device2)

assert device.get_current_goal_temperature(refresh=True) == 8.0
assert device.get_current_temperature(refresh=True) == 9.0
assert device.get_hvac_mode(refresh=True) == "Off"
assert device.get_fan_mode(refresh=True) == "Off"
assert device.get_hvac_state(refresh=True) == "Off"
assert device1.get_current_goal_temperature(refresh=True) == 8.0
assert device2.get_current_goal_temperature(refresh=True) == 7.0

device.set_temperature(72)
assert device.get_current_goal_temperature() == 72
for device in all_devices:
assert device.get_current_temperature(refresh=True) == 9.0
assert device.get_hvac_mode(refresh=True) == "Off"
assert device.get_fan_mode(refresh=True) == "Off"
assert device.get_hvac_state(refresh=True) == "Off"

assert device1._has_double_setpoints() == False
assert device2._has_double_setpoints() == True

update_device(
controller_data=vera_controller_data,
device_id=DEVICE_THERMOSTAT_ID,
key="temperature",
value=65,
)
assert device.get_current_temperature() == 65

device.turn_auto_on()
assert device.get_hvac_mode() == "AutoChangeOver"
device.turn_heat_on()
assert device.get_hvac_mode() == "HeatOn"
device.turn_cool_on()
assert device.get_hvac_mode() == "CoolOn"

device.fan_on()
assert device.get_fan_mode() == "ContinuousOn"
device.fan_auto()
assert device.get_fan_mode() == "Auto"
device.fan_cycle()
assert device.get_fan_mode() == "PeriodicOn"
device.fan_off()
assert device.get_fan_mode() == "Off"

device.turn_off()
assert device.get_hvac_mode() == "Off"

assert device1.get_current_temperature() == 65

for device in all_devices:
device.set_temperature(72)
assert device.get_current_goal_temperature() == 72

device.turn_auto_on()
assert device.get_hvac_mode() == "AutoChangeOver"
device.turn_heat_on()
assert device.get_hvac_mode() == "HeatOn"
device.turn_cool_on()
assert device.get_hvac_mode() == "CoolOn"

device.fan_on()
assert device.get_fan_mode() == "ContinuousOn"
device.fan_auto()
assert device.get_fan_mode() == "Auto"
device.fan_cycle()
assert device.get_fan_mode() == "PeriodicOn"
device.fan_off()
assert device.get_fan_mode() == "Off"

device.turn_off()
assert device.get_hvac_mode() == "Off"

device2.turn_heat_on()
device2.set_temperature(75)
assert device2.get_current_goal_temperature() == 75
assert device2.get_value("heatsp") == '75'

device2.turn_cool_on()
device2.set_temperature(60)
assert device2.get_current_goal_temperature() == 60
assert device2.get_value("coolsp") == '60'

device2.turn_heat_on()
assert device2.get_current_goal_temperature() == 75
assert device2.get_value("heatsp") == '75'

device2.turn_cool_on()
assert device2.get_current_goal_temperature() == 60
assert device2.get_value("coolsp") == '60'

def test_curtain(vera_controller_data: VeraControllerData) -> None:
"""Test function."""
Expand Down

0 comments on commit 5f9e417

Please sign in to comment.