Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github copilot
Browse files Browse the repository at this point in the history
Add first test ok for UnderlyingSwitch
Jean-Marc Collin committed Jan 29, 2025
1 parent 4390471 commit 22a3b64
Showing 3 changed files with 66 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -37,7 +37,9 @@
"yzhang.markdown-all-in-one",
"github.vscode-github-actions",
"azuretools.vscode-docker",
"huizhou.githd"
"huizhou.githd",
"github.copilot",
"github.copilot-chat"
],
"settings": {
"files.eol": "\n",
2 changes: 1 addition & 1 deletion custom_components/versatile_thermostat/underlyings.py
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ def initial_delay_sec(self):

@overrides
@property
def is_inversed(self):
def is_inversed(self) -> bool:
"""Tells if the switch command should be inversed"""
return self._thermostat.is_inversed

62 changes: 62 additions & 0 deletions tests/test_virtual_switch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
""" Test of virtual switch """

# pylint: disable=wildcard-import, unused-wildcard-import, protected-access

import pytest
from .commons import *
from unittest.mock import patch, call, MagicMock, PropertyMock

from homeassistant.const import STATE_ON, STATE_OFF

from custom_components.versatile_thermostat.underlyings import UnderlyingSwitch
from custom_components.versatile_thermostat.thermostat_switch import ThermostatOverSwitch


@pytest.mark.parametrize(
"is_inversed, vswitch_on_command, vswitch_off_command, expected_command_on, expected_data_on, expected_state_on, expected_command_off, expected_data_off, expected_state_off",
[
# Select
(
False,
"select_option/option:comfort",
"select_option/option:frost",
"select_option",
{"entity_id": "switch.test", "option": "comfort"},
PRESET_COMFORT,
"select_option",
{"entity_id": "switch.test", "option": "frost"},
PRESET_FROST_PROTECTION,
),
# switch
(False, "turn_on/:on", "turn_off/:off", "turn_on", {"entity_id": "switch.test", None: None}, STATE_ON, "turn_off", {"entity_id": "switch.test", None: None}, STATE_OFF),
],
)
def test_build_command(
hass,
is_inversed,
vswitch_on_command,
vswitch_off_command,
expected_command_on,
expected_data_on,
expected_state_on,
expected_command_off,
expected_data_off,
expected_state_off,
):
"""Test the initialisation of a UnderlyingSwitch with some personnalisations commands"""

vtherm = MagicMock(spec=ThermostatOverSwitch)
type(vtherm).is_inversed = PropertyMock(return_value=is_inversed)

assert vtherm.is_inversed == is_inversed
under = UnderlyingSwitch(hass, vtherm, "switch.test", 0, 0, vswitch_on_command, vswitch_off_command)

assert under.is_inversed == is_inversed

assert under._on_command.get("command") == expected_command_on
assert under._on_command.get("data") == expected_data_on
assert under._on_command.get("state") == expected_state_on

assert under._off_command.get("command") == expected_command_off
assert under._off_command.get("data") == expected_data_off
assert under._off_command.get("state") == expected_state_off

0 comments on commit 22a3b64

Please sign in to comment.