Skip to content

Commit

Permalink
Add set_cooling for home
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed Jul 13, 2024
1 parent b691b2b commit 8224021
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/homematicip/action/home_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,13 @@ async def action_start_inclusion(rest_connection: RestConnection, deviceId):
"""
data = {"deviceId": deviceId}
return await rest_connection.async_post("home/startInclusionModeForDevice", data)


async def async_set_cooling_home(rest_connection: RestConnection, cooling: bool):
"""set the cooling mode for the home
Args:
cooling(bool): True if cooling should be activated
"""
data = {"cooling": cooling}
return await rest_connection.async_post("home/heating/setCooling", data)
13 changes: 12 additions & 1 deletion src/homematicip/cli/hmip.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
from alive_progress import alive_bar

from homematicip.action.functional_channel_actions import async_set_slats_level_fc, async_set_shutter_level_fc, \
async_set_switch_state_fc, async_set_dim_level_fc, async_start_impulse_fc, async_set_shutter_stop_fc, async_set_display_fc
async_set_switch_state_fc, async_set_dim_level_fc, async_start_impulse_fc, async_set_shutter_stop_fc, \
async_set_display_fc
from homematicip.action.group_actions import async_set_boost_group, async_set_boost_duration_group, \
async_set_shutter_level_group, async_set_slats_level_group, \
async_set_shutter_stop_group, async_set_switch_state_group, async_set_point_temperature_group, \
async_set_active_profile_group, async_set_control_mode_group, async_set_on_time_group
from homematicip.action.home_actions import async_set_cooling_home
from homematicip.action.registry import Registry, ActionTarget
from homematicip.auth import Auth
from homematicip.cli.helper import get_channel_by_index_of_first, get_initialized_runner, setup_basic_logging, \
Expand Down Expand Up @@ -711,6 +713,15 @@ def toggle_garage_door(id: str, channel: int = None):
f"Run toggle_garage_door for device {get_device_name(device)} with result: {result.status_text} ({result.status})")


@run.command
def set_cooling(cooling: bool):
"""Set the cooling mode for the HmIP Access Point."""
runner = asyncio.run(get_initialized_runner())

result = asyncio.run(async_set_cooling_home(runner.rest_connection, cooling))
click.echo(f"Run set_cooling with result: {result.status_text} ({result.status})")


@cli.command
@click.argument("count", type=int, nargs=1)
def test(count: int):
Expand Down
16 changes: 15 additions & 1 deletion tests/actions/test_home_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
action_set_location, action_set_intrusion_alert_through_smoke_detectors, action_activate_absence_with_period, \
action_activate_absence_permanent, action_activate_absence_with_duration, action_deactivate_absence, \
action_activate_vacation, action_deactivate_vacation, action_set_zone_activation_delay, action_set_timezone, \
action_set_powermeter_unit_price, action_start_inclusion, get_security_zones_activation
action_set_powermeter_unit_price, action_start_inclusion, get_security_zones_activation, async_set_cooling_home
from homematicip.connection.rest_connection import RestResult, RestConnection
from homematicip.runner import Runner

Expand Down Expand Up @@ -128,3 +128,17 @@ async def test_action_start_inclusion(runner):
await action_start_inclusion(runner.rest_connection, device_id)
runner.rest_connection.async_post.assert_called_once_with("home/startInclusionModeForDevice",
{"deviceId": device_id})


@pytest.mark.asyncio
async def test_action_set_cooling_true(runner):
await async_set_cooling_home(runner.rest_connection, True)
runner.rest_connection.async_post.assert_called_once_with("home/heating/setCooling",
{"cooling": True})


@pytest.mark.asyncio
async def test_action_set_cooling_false(runner):
await async_set_cooling_home(runner.rest_connection, False)
runner.rest_connection.async_post.assert_called_once_with("home/heating/setCooling",
{"cooling": False})

0 comments on commit 8224021

Please sign in to comment.