Skip to content

Commit

Permalink
Merge pull request #659 from Morg42/develop
Browse files Browse the repository at this point in the history
sdp: adjust to smartplugin changes
  • Loading branch information
Morg42 authored Jul 3, 2024
2 parents 65903b9 + 38437a2 commit cb26d35
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/model/smartdeviceplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def __init__(self, sh, logger=None, **kwargs):

# suspend mode properties
self._suspend_item_path = self.get_parameter_value(PLUGIN_ATTR_SUSPEND_ITEM)
self._suspend_item = None
self.suspended = False

# connection instance
self._connection = None
Expand Down Expand Up @@ -310,11 +312,34 @@ def update_plugin_config(self, **kwargs):

return True

def suspend(self, by=None):
"""
sets plugin into suspended mode, no network/serial activity and no item changed
"""
if self.alive:
self.logger.info(f'plugin suspended by {by if by else "unknown"}, connections will be closed')
self.suspended = True
if self._suspend_item is not None:
self._suspend_item(True, self.get_fullname())
if hasattr(self, 'disconnect'):
self.disconnect()

def resume(self, by=None):
"""
disabled suspended mode, network/serial connections are resumed
"""
if self.alive:
self.logger.info(f'plugin resumed by {by if by else "unknown"}, connections will be resumed')
self.suspended = False
if self._suspend_item is not None:
self._suspend_item(False, self.get_fullname())
if hasattr(self, 'connect'):
self.connect()

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 is not None:
# if no parameter set, try to use item setting
Expand Down

0 comments on commit cb26d35

Please sign in to comment.