-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Implement optional External trigger for ZoneMinder switch #6836
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| DEFAULT_PATH_ZMS = '/zm/cgi-bin/nph-zms' | ||
| DEFAULT_SSL = False | ||
| DEFAULT_TIMEOUT = 10 | ||
| DEFAULT_TRIGGER_PORT = 6802 | ||
| DOMAIN = 'zoneminder' | ||
|
|
||
| LOGIN_RETRIES = 2 | ||
|
|
@@ -32,6 +33,7 @@ | |
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, | ||
| vol.Optional(CONF_PATH, default=DEFAULT_PATH): cv.string, | ||
| vol.Optional('trigger_port', default=DEFAULT_TRIGGER_PORT): cv.port, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a constant. |
||
| # This should match PATH_ZMS in ZoneMinder settings. | ||
| vol.Optional(CONF_PATH_ZMS, default=DEFAULT_PATH_ZMS): cv.string, | ||
| vol.Optional(CONF_USERNAME): cv.string, | ||
|
|
@@ -61,6 +63,8 @@ def setup(hass, config): | |
| ZM['username'] = username | ||
| ZM['password'] = password | ||
| ZM['path_zms'] = conf.get(CONF_PATH_ZMS) | ||
| ZM['host'] = conf[CONF_HOST] | ||
| ZM['trigger_port'] = conf['trigger_port'] | ||
|
|
||
| hass.data[DOMAIN] = ZM | ||
|
|
||
|
|
@@ -118,6 +122,22 @@ def _zm_request(method, api_url, data=None): | |
| 'decode "%s"', req.text) | ||
|
|
||
|
|
||
| def zm_trigger(monitor, state, cause, duration): | ||
| """Attempt to connect over TCP socket and trigger recording.""" | ||
| import socket | ||
| sock = socket.socket() | ||
| try: | ||
| sock.connect((ZM['host'], ZM['trigger_port'])) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is crossing the boundary of protocol specific code that is allowed to be in Home Assistant. Please extract the Zoneminder logic into it's own Python library.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean to shove all that into PyPi package?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
| command = '{:d}|{:s}'.format(monitor, state) | ||
| if state in 'on': | ||
| command += "+{:d}|1|{:s}|{:s}".format(duration, cause, cause) | ||
| sock.sendall(command.encode()) | ||
| except socket.error as sock_err: | ||
| _LOGGER.exception('Connect failed (%s), check OPT_TRIGGERS', sock_err) | ||
| finally: | ||
| sock.close() | ||
|
|
||
|
|
||
| # pylint: disable=no-member | ||
| def get_state(api_url): | ||
| """Get a state from the ZoneMinder API service.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use constants.