Scheduler-API
There are two ways to access the API
Directly
Use it the following way to access the api, if you have no access to the sh object in your method or function:
# to get access to the object instance: from lib.scheduler import Scheduler scheduler = Scheduler.get_instance() # to access a method (eg. to trigger a logic): scheduler.trigger(...)
Through the main SmartHome object
If you have access to the sh object in your method or function, you can use the following way:
# to access a method (eg. to trigger a logic): sh.scheduler.trigger(...)
The API is implemented through the following library:
lib.scheduler
- exception lib.scheduler.LeaveLogic[Quellcode]
Bases:
Exception
- class lib.scheduler.Scheduler(smarthome)[Quellcode]
Bases:
Thread
- static get_instance()[Quellcode]
Returns the instance of the scheduler class, to be used to access the scheduler-api
Use it the following way to access the api:
from lib.scheduler import Scheduler scheduler = Scheduler.get_instance() # to access a method (eg. to trigger a logic): scheduler.trigger(...)
- Rückgabe:
scheduler instance
- Rückgabetyp:
object or None
- set_worker_warn_count(count)[Quellcode]
- get_worker_count()[Quellcode]
Get number of worker threads initialized by scheduler
- Rückgabe:
number of worker threads
- get_idle_worker_count()[Quellcode]
Get number of idle worker threads
- Rückgabe:
number of worker threads
- get_worker_names()[Quellcode]
Get names on non-idle worker threads
- Rückgabe:
list with names of worker threads
- run()[Quellcode]
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- stop()[Quellcode]
- trigger(name, obj=None, by='Logic', source=None, value=None, dest=None, prio=3, dt=None, from_smartplugin=False)[Quellcode]
triggers the execution of a logic optional at a certain datetime given with dt
- Parameter:
name –
obj –
by –
source –
value –
dest –
prio –
dt – a certain datetime
- Rückgabe:
always None
- remove(name, from_smartplugin=False)[Quellcode]
Remove a scheduler entry with given name. If a call is made from a SmartPlugin with an instance configuration the instance name is added to the name to be able to distinguish scheduler entries from different instances
- Parameter:
name – scheduler entry name to remove
from_smartplugin –
- check_caller(name, from_smartplugin=False)[Quellcode]
Checks the calling stack if the calling function (one of get, change, remove, trigger) itself was called by a smartplugin instance. If there is an instance name of the calling smartplugin then the instance name of that calling smartplugin is appended to the name
- Parameter:
name – the name of a scheduler entry
from_smartplugin –
- Rückgabe:
returns either the name or name combined with instance name
- return_next(name, from_smartplugin=False)[Quellcode]
- add(name, obj, prio=3, cron=None, cycle=None, value=None, offset=None, next=None, from_smartplugin=False)[Quellcode]
Adds an entry to the scheduler.
- Parameter:
name – Name of the scheduler
obj – Method to call by the scheduler
prio – a priority with default of 3 having 1 as most important and higher numbers less important
cron – a crontab entry of type string or a list of entries
cycle – a time given as integer in seconds or a string with a time given in seconds and a value after an equal sign
value – Value that an item should be set to or to be handed to a logic, otherwise: None
offset – an optional offset for cycle. If not given, cycle start point will be varied between 10..15 seconds to prevent too many scheduler entries with the same starting times
next –
from_smartplugin – Only to set to True, if called from the internal method in SmartPlugin class
- get(name, from_smartplugin=False)[Quellcode]
takes a given name for a scheduler and returns either the matching scheduler or None
- change(name, from_smartplugin=False, **kwargs)[Quellcode]
changes a scheduler entry for a given name to settings given in kwargs