Der Core von SmartHomeNG

Der Core von SmartHomeNG besteht aus einem Haupt-Objekt welches in bin/smarthome.py definiert ist und einer Reihe von Programm Modulen, die exklusiv für die Nutzung durch den Core Hilfs-Objekte implementieren. Die Programm Module sind in dem Ordner ../lib abgelegt und im Unterpunkt Programm Modulen beschrieben.

smarthome.py

Das Haupt-Objekt von SmartHomeNG ist im folgenden beschrieben:

class lib.smarthome.SmartHome(MODE, extern_conf_dir='')[Quellcode]

Bases: object

SmartHome ist the main class of SmartHomeNG. All other objects can be addressed relative to the main oject, which is an instance of this class. Mostly it is reffered to as sh, _sh or smarthome.

BASE = '/usr/local/shng_doc/work'
initialize_vars()[Quellcode]
initialize_dir_vars()[Quellcode]
create_directories()[Quellcode]

Create directories used by SmartHomeNG if they don’t exist

get_defaultlanguage()[Quellcode]

Returns the configured default language of SmartHomeNG

set_defaultlanguage(language)[Quellcode]

Returns the configured default language of SmartHomeNG

get_basedir()[Quellcode]

Function to return the base directory of the running SmartHomeNG installation

Rückgabe

Base directory as an absolute path

Rückgabetyp

str

get_confdir()[Quellcode]

Function to return the config directory (that contain ‚etc‘, ‚logics‘ and ‚items‘ subdirectories)

Rückgabe

Config directory as an absolute path

Rückgabetyp

str

get_etcdir()[Quellcode]

Function to return the etc config directory

Rückgabe

Config directory as an absolute path

Rückgabetyp

str

get_vardir()[Quellcode]

Function to return the var directory used by SmartHomeNG

Rückgabe

var directory as an absolute path

Rückgabetyp

str

getBaseDir()[Quellcode]

Function to return the base directory of the running SmartHomeNG installation

getBaseDir() is deprecated. Use method get_basedir() instead.

Rückgabe

Base directory as an absolute path

Rückgabetyp

str

checkConfigFiles()[Quellcode]

This function checks if the needed configuration files exist. It checks for CONF and YAML files. If they dont exist, it is checked if a default configuration exist. If so, the default configuration is copied to corresponding configuration file.

The check is done for the files that have to exist (with some content) or SmartHomeNG won’t start:

  • smarthome.yaml / smarthome.conf

  • logging.yaml

  • plugin.yaml / plugin.conf

  • module.yaml / module.conf

  • logic.yaml / logic.conf

init_logging(conf_basename='', MODE='default')[Quellcode]

This function initiates the logging for SmartHomeNG.

start()[Quellcode]

This function starts the threads of the main smarthome object.

The main thread that is beeing started is called Main

stop(signum=None, frame=None)[Quellcode]

This method is used to stop SmartHomeNG and all it’s threads

restart(source='')[Quellcode]

This method is used to restart the python interpreter and SmartHomeNG

If SmartHomeNG was started in one of the foreground modes (-f, -i, -d), just quit and let the user restart manually.

list_threads(txt)[Quellcode]
add_event_listener(events, method)[Quellcode]

This Function adds listeners for a list of events. This function is called from plugins interfacing with visus (e.g. visu_websocket)

Parameter
  • events (list) – List of events to add listeners for

  • method (object) – Method used by the visu-interface

return_event_listeners(event='all')[Quellcode]

This function returns the listeners for a specified event.

Parameter

event (str) – Name of the event or ‚all‘ to return all listeners

Rückgabe

List of listeners

Rückgabetyp

list

object_refcount()[Quellcode]

Function to return the number of defined objects in SmartHomeNG

Rückgabe

Number of objects

Rückgabetyp

int

string2bool(string)[Quellcode]

Returns the boolean value of a string

DEPRECATED - Use lib.utils.Utils.to_bool(string) instead

Parameter

string (str) – string to convert

Rückgabe

Parameter converted to bool

Rückgabetyp

bool

add_item(path, item)[Quellcode]

Function to to add an item to the dictionary of items. If the path does not exist, it is created

DEPRECATED - Use the Items-API instead

Parameter
  • path (str) – Path of the item

  • item (object) – The item itself

return_item(string)[Quellcode]

Function to return the item for a given path

DEPRECATED - Use the Items-API instead

Parameter

string (str) – Path of the item to return

Rückgabe

Item

Rückgabetyp

object

return_items()[Quellcode]

“ Function to return a list with all items

DEPRECATED - Use the Items-API instead

Rückgabe

List of all items

Rückgabetyp

list

match_items(regex)[Quellcode]

Function to match items against a regular expresseion

DEPRECATED - Use the Items-API instead

Parameter

regex (str) – Regular expression to match items against

Rückgabe

List of matching items

Rückgabetyp

list

find_items(conf)[Quellcode]

“ Function to find items that match the specified configuration

DEPRECATED - Use the Items-API instead

Parameter

conf (str) – Configuration to look for

Rückgabe

list of matching items

Rückgabetyp

list

find_children(parent, conf)[Quellcode]

Function to find children with the specified configuration

DEPRECATED - Use the Items-API instead

Parameter
  • parent (str) – parent item on which to start the search

  • conf (str) – Configuration to look for

Rückgabe

list or matching child-items

Rückgabetyp

list

return_modules()[Quellcode]

Returns a list with the names of all loaded modules

DEPRECATED - Use the Modules-API instead

Rückgabe

list of module names

Rückgabetyp

list

get_module(name)[Quellcode]

Returns the module object for the module named by the parameter or None, if the named module is not loaded

DEPRECATED - Use the Modules-API instead

Parameter

name (str) – Name of the module to return

Rückgabe

list of module names

Rückgabetyp

object

return_plugins()[Quellcode]

Returns a list with the instances of all loaded plugins

DEPRECATED - Use the Plugins-API instead

Rückgabe

list of plugin names

Rückgabetyp

list

reload_logics(signum=None, frame=None)[Quellcode]

Function to reload all logics

DEPRECATED - Use the Logics-API instead

return_logic(name)[Quellcode]

Returns (the object of) one loaded logic with given name

DEPRECATED - Use the Logics-API instead

Parameter

name (str) – name of the logic to get

Rückgabe

object of the logic

Rückgabetyp

object

return_logics()[Quellcode]

Returns a list with the names of all loaded logics

DEPRECATED - Use the Logics-API instead

Rückgabe

list of logic names

Rückgabetyp

list

now()[Quellcode]

Returns the actual time in a timezone aware format

DEPRECATED - Use the Shtime-API instead

Rückgabe

Actual time for the local timezone

Rückgabetyp

datetime

tzinfo()[Quellcode]

Returns the info about the actual local timezone

DEPRECATED - Use the Shtime-API instead

Rückgabe

Timezone info

Rückgabetyp

str

utcnow()[Quellcode]

Returns the actual time in GMT

DEPRECATED - Use the Shtime-API instead

Rückgabe

Actual time in GMT

Rückgabetyp

datetime

utcinfo()[Quellcode]

Returns the info about the GMT timezone

DEPRECATED - Use the Shtime-API instead

Rückgabe

Timezone info

Rückgabetyp

str

runtime()[Quellcode]

Returns the uptime of SmartHomeNG

DEPRECATED - Use the Shtime-API instead

Rückgabe

Uptime in days, hours, minutes and seconds

Rückgabetyp

str