Skip to content

Commit

Permalink
Add get_security_zones_activation
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed Jun 3, 2024
1 parent 12d6e4a commit 954a587
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/homematicip/action/home_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime

from homematicip.connection.rest_connection import RestConnection
from homematicip.model.model import Model


async def action_set_security_zones_activation(rest_connection: RestConnection, internal: bool = True,
Expand All @@ -26,15 +27,15 @@ async def action_set_security_zones_activation(rest_connection: RestConnection,
return await rest_connection.async_post("home/security/setZonesActivation", data)


def get_security_zones_activation(self) -> (bool, bool):
def get_security_zones_activation(model: Model) -> (bool, bool):
"""returns the value of the security zones if they are armed or not.
:return: internal, external - True if the zone is armed
"""
internal_active = False
external_active = False
internal_active: bool = False
external_active: bool = False

security_zones = [zone for zone in self.groups if zone.groupType == "SECURITY_ZONE"]
security_zones = [g for g in model.groups.values() if g.type == "SECURITY_ZONE"]
for g in security_zones:
if g.label == "EXTERNAL":
external_active = g.active
Expand Down
43 changes: 33 additions & 10 deletions 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
action_set_powermeter_unit_price, action_start_inclusion, get_security_zones_activation
from homematicip.connection.rest_connection import RestResult, RestConnection
from homematicip.runner import Runner

Expand All @@ -26,6 +26,22 @@ async def test_action_set_security_zones_activation(runner):
{"zonesActivation": {"EXTERNAL": True, "INTERNAL": True}})


def test_get_security_zones_activation(filled_model):
internal, external = get_security_zones_activation(filled_model)
assert internal is False
assert external is False

filled_model.groups["00000000-0000-0000-0000-000000000005"].active = True # External
internal, external = get_security_zones_activation(filled_model)
assert internal is False
assert external is True

filled_model.groups["00000000-0000-0000-0000-000000000016"].active = True # Internal
internal, external = get_security_zones_activation(filled_model)
assert internal is True
assert external is True


@pytest.mark.asyncio
async def test_action_set_silent_alarm(runner):
await action_set_silent_alarm(runner.rest_connection, internal=True, external=True)
Expand All @@ -36,19 +52,22 @@ async def test_action_set_silent_alarm(runner):
@pytest.mark.asyncio
async def test_action_set_location(runner):
await action_set_location(runner.rest_connection, "city", 1.0, 2.0)
runner.rest_connection.async_post.assert_called_once_with("home/setLocation", {"city": "city", "latitude": 1.0, "longitude": 2.0})
runner.rest_connection.async_post.assert_called_once_with("home/setLocation",
{"city": "city", "latitude": 1.0, "longitude": 2.0})


@pytest.mark.asyncio
async def test_action_set_intrusion_alert_through_smoke_detectors(runner):
await action_set_intrusion_alert_through_smoke_detectors(runner.rest_connection, activate=True)
runner.rest_connection.async_post.assert_called_once_with("home/security/setIntrusionAlertThroughSmokeDetectors", {"intrusionAlertThroughSmokeDetectors": True})
runner.rest_connection.async_post.assert_called_once_with("home/security/setIntrusionAlertThroughSmokeDetectors",
{"intrusionAlertThroughSmokeDetectors": True})


@pytest.mark.asyncio
async def test_action_activate_absence_with_period(runner):
await action_activate_absence_with_period(runner.rest_connection, datetime(2020, 1, 1, 0, 0))
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateAbsenceWithPeriod", {"endTime": "2020_01_01 00:00"})
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateAbsenceWithPeriod",
{"endTime": "2020_01_01 00:00"})


@pytest.mark.asyncio
Expand All @@ -60,7 +79,8 @@ async def test_action_activate_absence_permanent(runner):
@pytest.mark.asyncio
async def test_action_activate_absence_with_duration(runner):
await action_activate_absence_with_duration(runner.rest_connection, 30)
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateAbsenceWithDuration", {"duration": 30})
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateAbsenceWithDuration",
{"duration": 30})


@pytest.mark.asyncio
Expand All @@ -72,7 +92,8 @@ async def test_action_deactivate_absence(runner):
@pytest.mark.asyncio
async def test_action_activate_vacation(runner):
await action_activate_vacation(runner.rest_connection, datetime(2020, 1, 1, 0, 0), 12.0)
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateVacation", {"endTime": "2020_01_01 00:00", "temperature": 12.0})
runner.rest_connection.async_post.assert_called_once_with("home/heating/activateVacation",
{"endTime": "2020_01_01 00:00", "temperature": 12.0})


@pytest.mark.asyncio
Expand All @@ -84,7 +105,8 @@ async def test_action_deactivate_vacation(runner):
@pytest.mark.asyncio
async def test_action_set_zone_activation_delay(runner):
await action_set_zone_activation_delay(runner.rest_connection, 10)
runner.rest_connection.async_post.assert_called_once_with("home/security/setZoneActivationDelay", {"zoneActivationDelay": 10})
runner.rest_connection.async_post.assert_called_once_with("home/security/setZoneActivationDelay",
{"zoneActivationDelay": 10})


@pytest.mark.asyncio
Expand All @@ -96,12 +118,13 @@ async def test_action_set_timezone(runner):
@pytest.mark.asyncio
async def test_action_set_powermeter_unit_price(runner):
await action_set_powermeter_unit_price(runner.rest_connection, 0.25)
runner.rest_connection.async_post.assert_called_once_with("home/setPowerMeterUnitPrice", {"powerMeterUnitPrice": 0.25})
runner.rest_connection.async_post.assert_called_once_with("home/setPowerMeterUnitPrice",
{"powerMeterUnitPrice": 0.25})


@pytest.mark.asyncio
async def test_action_start_inclusion(runner):
device_id = "1234"
await action_start_inclusion(runner.rest_connection, device_id)
runner.rest_connection.async_post.assert_called_once_with("home/startInclusionModeForDevice", {"deviceId": device_id})

runner.rest_connection.async_post.assert_called_once_with("home/startInclusionModeForDevice",
{"deviceId": device_id})

0 comments on commit 954a587

Please sign in to comment.