Skip to content

Commit

Permalink
Add set_switch_state action for group
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed Jun 5, 2024
1 parent 954a587 commit d5aaae7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/homematicip/action/group_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from homematicip.connection.rest_connection import RestConnection
from homematicip.model.enums import ProfileMode, ClimateControlMode
from homematicip.model.hmip_base import HmipBaseModel
from homematicip.model.model_components import Group
from homematicip.runner import Runner

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,6 +69,17 @@ async def action_set_control_mode(rest_connection: RestConnection, group: HmipBa
return await rest_connection.async_post("group/heating/setControlMode", data)


@Action.allowed_types("EXTENDED_LINKED_SWITCHING", "SWITCHING")
async def group_action_set_switch_state(rest_connection: RestConnection, group: Group, on):
"""Set switching state of group
:param rest_connection: RestConnection
:param group: The group to set the state
:param on: True switches on, False switches off
"""
data = {"groupId": group.id, "on": on}
return await rest_connection.async_post("group/switching/setState", data)

#
# @Action.allowed_types("SWITCHING_PROFILE")
# async def set_profile_mode(rest_connection: RestConnection, group: HmipBaseModel, profile_mode: ProfileMode):
Expand All @@ -83,4 +95,3 @@ async def action_set_control_mode(rest_connection: RestConnection, group: HmipBa
# }
# return await rest_connection.async_post(
# "group/switching/profile/setProfileMode", data)

36 changes: 34 additions & 2 deletions tests/actions/test_group_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# import pytest
# from homematicip.base.enums import ClimateControlMode
import pytest

from homematicip.action.group_actions import group_action_set_switch_state
from homematicip.connection.rest_connection import RestConnection, RestResult
from homematicip.model.model_components import Group
from homematicip.runner import Runner


@pytest.fixture
def runner(mocker, filled_model):
conn = mocker.Mock(spec=RestConnection)
conn.async_post.return_value = RestResult(status=200)
runner = Runner(_rest_connection=conn, model=filled_model)
return runner


@pytest.fixture
def sample_group() -> Group:
return Group(id="00000000-0000-0000-0000-000000000001", type="", channels=[])


@pytest.mark.asyncio
async def test_wrong_group_type(runner, sample_group):
sample_group.type = "ASDF"
with pytest.raises(ValueError):
await group_action_set_switch_state(runner.rest_connection, sample_group, True)

@pytest.mark.asyncio
async def test_group_set_switch_state(runner, sample_group):
sample_group.type = "SWITCHING"
await group_action_set_switch_state(runner.rest_connection, sample_group, True)
runner.rest_connection.async_post.assert_called_once_with("group/switching/setState",
{"groupId": sample_group.id, "on": True})

#
# from homematicip.action.group_actions import SetPointTemperatureGroupAction, SetBoostGroupAction, \
# SetBoostDurationGroupAction, SetActiveProfileGroupAction, SetControlModeGroupAction, \
Expand Down

0 comments on commit d5aaae7

Please sign in to comment.