Skip to content

Commit

Permalink
fixes to suspend function
Browse files Browse the repository at this point in the history
  • Loading branch information
Morg42 committed Aug 1, 2023
1 parent 90c071d commit 2850bc1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions lib/model/sdp/examples/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ parameters:
description:
de: 'Pause zwischen Durchgängen von Verbindungsversuchen (rounds)'
en: 'wait time between connect rounds'
retry_standby:
retry_suspend:
type: num
default: 0
description:
de: 'Anzahl von Durchgängen vor Standby-Modus'
en: 'number of connect rounds before entering standby mode'
de: 'Anzahl von Durchgängen vor Suspend-Modus'
en: 'number of connect rounds before entering suspend mode'
message_timeout:
type: num
default: 2
Expand Down Expand Up @@ -170,14 +170,14 @@ parameters:
de: 'Anzahl Stopbits'
en: 'number of stop bits'

# standby mode configuration
# suspend mode configuration
# mute plugin on setting associated item to True
standby_item_path:
suspend_item_path:
type: str
default: ''
description:
de: 'Item-Pfad für das Standby-Item'
en: 'item path for standby switch item'
de: 'Item-Pfad für das Suspend-Item'
en: 'item path for suspend switch item'

# more fundamental connection settings
# !! plugin defaults can be set here (add default:) or in code
Expand Down
2 changes: 1 addition & 1 deletion lib/model/sdp/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
PLUGIN_ATTR_CB_SUSPEND = 'suspend_callback' # callback function, called if connection attempts are aborted

PLUGIN_ATTRS = (PLUGIN_ATTR_MODEL, PLUGIN_ATTR_CMD_CLASS, PLUGIN_ATTR_RECURSIVE,
PLUGIN_ATTR_STANDBY_ITEM, PLUGIN_ATTR_CONNECTION,
PLUGIN_ATTR_SUSPEND_ITEM, PLUGIN_ATTR_CONNECTION,
PLUGIN_ATTR_CONN_TIMEOUT, PLUGIN_ATTR_CONN_TERMINATOR, PLUGIN_ATTR_CONN_BINARY,
PLUGIN_ATTR_CONN_RETRIES, PLUGIN_ATTR_CONN_CYCLE, PLUGIN_ATTR_CONN_AUTO_RECONN, PLUGIN_ATTR_CONN_AUTO_CONN,
PLUGIN_ATTR_CONN_RETRY_CYCLE, PLUGIN_ATTR_CONN_RETRY_SUSPD, PLUGIN_ATTR_NET_HOST, PLUGIN_ATTR_NET_PORT,
Expand Down
11 changes: 8 additions & 3 deletions lib/model/smartdeviceplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,29 @@ def set_suspend(self, suspend_active=None, by=None):
"""
enable / disable suspend mode: open/close connections, schedulers
"""

if suspend_active is None:
if self._suspend_item:
# if no parameter set, try to use item setting
suspend_active = bool(self._suspend_item())
else:
# if not available, default to "resume"
suspend_active = False

# print debug logging
if suspend_active:
msg = 'Suspend mode enabled'
else:
msg = 'Suspend mode disabled'
if by:
msg += f' (set by {by})'
self.logger.debug(msg)

self.logger.info(msg)
# activate selected mode, use smartplugin methods
if suspend_active:
self.suspend()
self.suspend(by)
else:
self.resume()
self.resume(by)

if suspend_active:
if self.scheduler_get(self.get_shortname() + '_cyclic'):
Expand Down
5 changes: 5 additions & 0 deletions lib/model/smartplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ def __init__(self, **kwargs):
self._plg_item_dict = {} # make sure, that the dict is local to the plugin
self._item_lookup_dict = {} # make sure, that the dict is local to the plugin

# set parameter value
# TODO: need to check for this item in parse_item and set self._suspend_item
# for suspend item functionality to work
self._suspend_item_path = self.get_parameter_value('suspend_item')

def suspend(self, by=None):
"""
sets plugin into suspended mode, no network/serial activity and no item changed
Expand Down

0 comments on commit 2850bc1

Please sign in to comment.