Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to force alarm command #47

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ from zoneminder.zm import ZoneMinder
SERVER_HOST = "{{host}}:{{port}}"
USER = "{{user}}"
PASS = "{{pass}}"
SERVER_PATH = "{{path}}"
SERVER_PATH = "{{path}}" # example: /zm/
SERVER_ZMS_PATH = "{{zms_path}}" # example: /zm/cgi-bin/nph-zms

zm_client = ZoneMinder(
server_host=SERVER_HOST, server_path=SERVER_PATH, username=USER, password=PASS, verify_ssl=False
server_host=SERVER_HOST,
server_path=SERVER_PATH,
zms_path=SERVER_ZMS_PATH,
username=USER,
password=PASS,
verify_ssl=False
)

#Zoneminder authentication
# Zoneminder authentication
zm_client.login()


#Get all monitors
# Get all monitors
monitors = zm_client.get_monitors()

for monitor in monitors:
Expand All @@ -52,7 +58,7 @@ for monitor in monitors:
>>> Monitor(id='monitor_id', name='monitor_name', controllable='is_controllable')


#Move camera down
# Move camera down
controllable_monitors = [m for m in monitors if m.controllable]

for monitor in controllable_monitors:
Expand Down
17 changes: 14 additions & 3 deletions zoneminder/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,16 @@ def still_image_url(self) -> str:
"""Get the still jpeg image url of this Monitor."""
return self._still_image_url

def __alarm_control_command(self, command) -> dict:
"""Send alarm command to monitor."""
return self._client.get_state("api/monitors/alarm/id:{mid}/command:{command}.json".format(
mid=self._monitor_id, command=command)
)

@property
def is_recording(self) -> Optional[bool]:
"""Indicate if this Monitor is currently recording."""
status_response = self._client.get_state(
"api/monitors/alarm/id:{}/command:status.json".format(self._monitor_id)
)
status_response = self.__alarm_control_command("status")

if not status_response:
_LOGGER.warning("Could not get status for monitor %s.", self._monitor_id)
Expand All @@ -168,6 +172,13 @@ def is_recording(self) -> Optional[bool]:
return False
return int(status) == STATE_ALARM

def set_force_alarm_state(self, state):
"""Set the monitor force alarm state."""
status_response = self.__alarm_control_command("on" if state is True else "off")

if not status_response:
_LOGGER.warning("Could not get status for monitor %s.", self._monitor_id)

@property
def is_available(self) -> bool:
"""Indicate if this Monitor is currently available."""
Expand Down