Core of SmartHomeNG

The core of SmartHomeNG is made of a main object which is defined in bin/smarthome.py and a couple of libraries which are for exclusive use by the core and implement helping objects. They are located in lib and are listed in the navigation directly under this page.

smarthome.py

The main object of SmartHomeNG is described below:

class bin.smarthome.SmartHome(extern_conf_dir='/usr/local/shng_doc/work')[source]

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_dir = '/usr/local/shng_doc/work'

base_dir is deprecated. Use method get_basedir() instead.

items = None
plugins = None
logics = None
scheduler = None
modules = []
plugin_load_complete = False
item_load_complete = False
plugin_start_complete = False
shtime = None
get_defaultlanguage()[source]

Returns the configured default language of SmartHomeNG

set_defaultlanguage(language)[source]

Returns the configured default language of SmartHomeNG

get_basedir()[source]

Function to return the base directory of the running SmartHomeNG installation

Returns:Base directory as an absolute path
Return type:str
get_confdir()[source]

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

Returns:Config directory as an absolute path
Return type:str
getBaseDir()[source]

Function to return the base directory of the running SmartHomeNG installation

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

Returns:Base directory as an absolute path
Return type:str
checkConfigFiles()[source]

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')[source]

This function initiates the logging for SmartHomeNG.

initMemLog()[source]

This function initializes all needed datastructures to use the (old) memlog plugin

start()[source]

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)[source]

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

list_threads(txt)[source]
add_log(name, log)[source]

Function to add a log to the list of logs (deprecated? -> old logging!)

Parameters:
  • name (str) – Name of log
  • log (object) – Log object
return_logs()[source]

Function to the list of logs (deprecated? -> old logging!)

Returns:List of logs
Return type:list
add_event_listener(events, method)[source]

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

Parameters:
  • events (list) – List of events to add listeners for
  • method (object) – Method used by the visu-interface
return_event_listeners(event='all')[source]

This function returns the listeners for a specified event.

Parameters:event (str) – Name of the event or ‘all’ to return all listeners
Returns:List of listeners
Return type:list
object_refcount()[source]

Function to return the number of defined objects in SmartHomeNG

Returns:Number of objects
Return type:int
string2bool(string)[source]

Returns the boolean value of a string

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

Parameters:string (str) – string to convert
Returns:Parameter converted to bool
Return type:bool
add_item(path, item)[source]

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

Parameters:
  • path (str) – Path of the item
  • item (object) – The item itself
return_item(string)[source]

Function to return the item for a given path

DEPRECATED - Use the Items-API instead

Parameters:string (str) – Path of the item to return
Returns:Item
Return type:object
return_items()[source]

” Function to return a list with all items

DEPRECATED - Use the Items-API instead

Returns:List of all items
Return type:list
match_items(regex)[source]

Function to match items against a regular expresseion

DEPRECATED - Use the Items-API instead

Parameters:regex (str) – Regular expression to match items against
Returns:List of matching items
Return type:list
find_items(conf)[source]

” Function to find items that match the specified configuration

DEPRECATED - Use the Items-API instead

Parameters:conf (str) – Configuration to look for
Returns:list of matching items
Return type:list
find_children(parent, conf)[source]

Function to find children with the specified configuration

DEPRECATED - Use the Items-API instead

Parameters:
  • parent (str) – parent item on which to start the search
  • conf (str) – Configuration to look for
Returns:

list or matching child-items

Return type:

list

return_modules()[source]

Returns a list with the names of all loaded modules

DEPRECATED - Use the Modules-API instead

Returns:list of module names
Return type:list
get_module(name)[source]

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

Parameters:name (str) – Name of the module to return
Returns:list of module names
Return type:object
return_plugins()[source]

Returns a list with the instances of all loaded plugins

DEPRECATED - Use the Plugins-API instead

Returns:list of plugin names
Return type:list
reload_logics(signum=None, frame=None)[source]

Function to reload all logics

DEPRECATED - Use the Logics-API instead

return_logic(name)[source]

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

DEPRECATED - Use the Logics-API instead

Parameters:name (str) – name of the logic to get
Returns:object of the logic
Return type:object
return_logics()[source]

Returns a list with the names of all loaded logics

DEPRECATED - Use the Logics-API instead

Returns:list of logic names
Return type:list
now()[source]

Returns the actual time in a timezone aware format

DEPRECATED - Use the Shtime-API instead

Returns:Actual time for the local timezone
Return type:datetime
tzinfo()[source]

Returns the info about the actual local timezone

DEPRECATED - Use the Shtime-API instead

Returns:Timezone info
Return type:str
utcnow()[source]

Returns the actual time in GMT

DEPRECATED - Use the Shtime-API instead

Returns:Actual time in GMT
Return type:datetime
utcinfo()[source]

Returns the info about the GMT timezone

DEPRECATED - Use the Shtime-API instead

Returns:Timezone info
Return type:str
runtime()[source]

Returns the uptime of SmartHomeNG

DEPRECATED - Use the Shtime-API instead

Returns:Uptime in days, hours, minutes and seconds
Return type:str