Module: base

Classes in the base module are only accessible from Python applications.

Application

class base.Application(run=True)

This is the main application object in the server. There can only be once instance of this object. The default constructor returns the instance of this object.

registerScheduledTask(fn, seconds=0, minutes=0, hours=0, days=0, runAtOnce=False, strictInterval=False, args=None, kwargs=None)

Register a semi regular scheduled task to run at a predefined interval. All calls will be made by the main thread.

Parameters:
  • fn (func) – The function to be called.
  • seconds (integer) – The interval in seconds. Optional.
  • minutes (integer) – The interval in minutes. Optional.
  • hours (integer) – The interval in hours. Optional.
  • days (integer) – The interval in days. Optional.
  • runAtOnce (bool) – If the function should be called right away or wait one interval?
  • strictInterval (bool) – Set this to True if the interval should be strict. That means if the interval is set to 60 seconds and it was run ater 65 seconds the next run will be in 55 seconds.
  • args (list) – Any args to be supplied to the function. Supplied as *args.
  • kwargs (dict) – Any keyworded args to be supplied to the function. Supplied as **kwargs.

Note

The interval in which this task is run is not exact and can be delayed one minute depending on the server load.

Note

Calls to this method are threadsafe.

static defaultContext()
Returns:the default context used by the application
queue(fn, *args, **kwargs)

Queue a function to be executed later. All tasks in this queue will be run by the main thread. This is a thread safe function and can safely be used to syncronize with the main thread

Returns:True if the task was queued
Returns:False if the server is shutting down
registerShutdown(fn)

Register shutdown method. The method fn will be called the the server shuts down. Use this to clean up resources on shutdown.

Parameters:fn (func) – A function callback to call when the server shuts down
static signal(msg, *args, **kwargs)

Send a global signal to registered slots. It is not recommended to call this method directly but instead use the signal decorator. Any extra parameters supplied will be forwarded to the slot.

Parameters:msg (str) – The signal name
@base.mainthread

This decorator forces a method to be run in the main thread regardless of which thread calls the method.

Configurations

@base.configuration

This decorator should be applied on the Plugin class to add configuration values. Configuration values will be exposed automatically to the user.

Example:

@configuration(
  companyName = ConfigurationString(
    defaultValue='Telldus Technologies',
    title='Company Name',
    description='Name of the Company'
  ),
)
class MyPlugin(Plugin):
  pass
class base.ConfigurationValue(valueType, defaultValue, writable=True, readable=True, hidden=False)

Base class for configuration values. Do not use this class directly but use one of the subclasses instead.

class base.ConfigurationDict(defaultValue={})

Configuration class used to store dictionaries

class base.ConfigurationNumber(defaultValue=0)

Configuration class used to store numbers

class base.ConfigurationList(defaultValue=[])

Configuration class used to store lists

class base.ConfigurationString(defaultValue='', minLength=0, maxLength=0)

Configuration class used to store strings

Signals & Slots

class base.ISignalObserver

Bases: base.Plugin.IInterface

Implement this IInterface to recieve signals using the decorator @slot

@base.signal

This is a decorator for sending signals. Decorate any of your Plugins methods with this decorator and whenever the method is called the signal will be fired.

Parameters:name (str) – The signal name. This can be omitted and then the function name will be used as the name of the signal.
@base.slot(message = '')

This is a decorator for receiveing signals. The class must implement base.ISignalObserver

Parameters:message (str) – This is the signal name to receive