Skip to content

Commit

Permalink
#507 Add send-door-command argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-th committed Dec 3, 2023
1 parent 276ac40 commit d01becc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
23 changes: 22 additions & 1 deletion hmip_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ def main():
"--toggle-garage-door",
action="store_true",
dest="toggle_garage_door",
help="HmIP WGC Toggle Garage Door",
help="Toggle Garage Door for devices with IMPULSE_OUTPUT_CHANNEL channel like HmIP-WGC ",
default=None,
)
group.add_argument(
"--send-door-command",
nargs="?",
dest="device_send_door_command",
help="Control door for all devices, which has a channel called Door_Channel like Hmip-MOD-HO. Allowed parameters are OPEN, CLOSE, STOP and PARTIAL_OPEN.",
default=None,
)

group.add_argument(
"--turn-on",
action="store_true",
Expand Down Expand Up @@ -459,6 +467,9 @@ def main():

command_entered = False
if args.server_config:
print(
f"Running homematicip-rest-api with fake server configuration {args.server_config}"
)
global server_config
server_config = args.server_config
home.download_configuration = fake_download_configuration
Expand Down Expand Up @@ -646,6 +657,16 @@ def main():
)
command_entered = True

if args.device_send_door_command is not None:
_execute_action_for_device(
device,
args,
CliActions.SEND_DOOR_COMMAND,
"send_door_command",
args.device_send_door_command,
)
command_entered = True

if args.device_shutter_level is not None:
_execute_action_for_device(
device,
Expand Down
1 change: 1 addition & 0 deletions homematicip/base/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,4 @@ class CliActions(AutoNameEnum):
TOGGLE_GARAGE_DOOR = auto()
SET_SWITCH_STATE = auto()
RESET_ENERGY_COUNTER = auto()
SEND_DOOR_COMMAND = auto()
3 changes: 3 additions & 0 deletions homematicip/base/functionalChannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,9 @@ def from_json(self, js, groups: Iterable[Group]):
self.ventilationPositionSupported = js["ventilationPositionSupported"]

def send_door_command(self, doorCommand=DoorCommand.STOP):
print(
f"Device: {self.device.id}; Channel: {self.index}; Command: {doorCommand}"
)
data = {
"channelIndex": self.index,
"deviceId": self.device.id,
Expand Down
1 change: 1 addition & 0 deletions homematicip/class_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
FunctionalChannelType.NOTIFICATION_LIGHT_CHANNEL: [CliActions.SET_DIM_LEVEL],
FunctionalChannelType.DOOR_LOCK_CHANNEL: [CliActions.SET_LOCK_STATE],
FunctionalChannelType.IMPULSE_OUTPUT_CHANNEL: [CliActions.TOGGLE_GARAGE_DOOR],
FunctionalChannelType.DOOR_CHANNEL: [CliActions.SEND_DOOR_COMMAND],
FunctionalChannelType.BLIND_CHANNEL: [
CliActions.SET_SHUTTER_LEVEL,
CliActions.SET_SLATS_LEVEL,
Expand Down
10 changes: 10 additions & 0 deletions homematicip/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,16 @@ def set_security_zones_activation(self, internal=True, external=True):
data = {"zonesActivation": {"EXTERNAL": external, "INTERNAL": internal}}
return self._restCall("home/security/setZonesActivation", json.dumps(data))

def set_silent_alarm(self, internal=True, external=True):
"""this function will set the silent alarm for interal or external
Args:
internal(bool): activates/deactivates the silent alarm for internal zone
external(bool): activates/deactivates the silent alarm for the external zone
"""
data = {"zonesSilentAlarm": {"EXTERNAL": external, "INTERNAL": internal}}
return self._restCall("home/security/setZonesSilentAlarm", json.dumps(data))

def set_location(self, city, latitude, longitude):
data = {"city": city, "latitude": latitude, "longitude": longitude}
return self._restCall("home/setLocation", json.dumps(data))
Expand Down
19 changes: 18 additions & 1 deletion tests/test_hmip_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_execute_action_for_device,
_execute_cli_action,
)
from homematicip.base.enums import CliActions
from homematicip.base.enums import CliActions, DoorState
from homematicip.base.helpers import anonymizeConfig, handle_config
from homematicip.home import Home
from homematicip_demo.helper import (
Expand Down Expand Up @@ -126,6 +126,23 @@ def __init__(self) -> None:
assert d.functionalChannels[3].slatsLevel == 0.5


def test_execute_action_for_device_send_door_command(fake_home: Home):
class Args:
def __init__(self) -> None:
self.channels = None

args = Args()
d = fake_home.search_device_by_id("3014F0000000000000FAF9B4")

with no_ssl_verification():
_execute_action_for_device(
d, args, CliActions.SEND_DOOR_COMMAND, "send_door_command", "OPEN"
)
fake_home.get_current_state()
d = fake_home.search_device_by_id("3014F0000000000000FAF9B4")
assert d.functionalChannels[1].doorState == DoorState.OPEN


def test_channel_supports_action(fake_home: Home):
d = fake_home.search_device_by_id("3014F71100000000000DRBL4")
assert False == _channel_supports_action(
Expand Down

0 comments on commit d01becc

Please sign in to comment.