Class Items

This class implements the following methods and properties:

class lib.item.Items(smarthome)[source]

Bases: object

Items loader class. (Item-methods from bin/ are moved here.)

  • An instance is created during initialization by bin/
  • There should be only one instance of this class. So: Don’t create another instance
Parameters:smarthome (object) – Instance of the smarthome master-object
static get_instance()[source]

Returns the instance of the Items class, to be used to access the items-api

Use it the following way to access the api:

from lib.item import Items
items = Items.get_instance()

# to access a method (eg. return_items()):
Returns:items instance
Return type:object
struct_merge_lists = True
merge_structlists(l1, l2, key='')[source]
add_struct_definition(plugin_name, struct_name, struct)[source]

Add a struct definition

called when reading in item structs from ../etc/struct.yaml or from lib.plugin when reading in plugin-metadata

  • plugin_name
  • struct_name
  • struct

merge(source, destination, source_name='', dest_name='')[source]

Merges an OrderedDict Tree into another one

  • source (OrderedDict) – source tree to merge into another one
  • destination (OrderedDict) – destination tree to merge into

Merged configuration tree

Return type:



Run me with nosetests –with-doctest

>>> a = { 'first' : { 'all_rows' : { 'pass' : 'dog', 'number' : '1' } } }
>>> b = { 'first' : { 'all_rows' : { 'fail' : 'cat', 'number' : '5' } } }
>>> merge(b, a) == { 'first' : { 'all_rows' : { 'pass' : 'dog', 'fail' : 'cat', 'number' : '5' } } }
resolve_structs(struct, struct_name, substruct_names)[source]

Resolve a struct reference

if the struct definition that is to be inserted contains a struct reference, it is resolved first

  • struct – struct that contains a struct reference
  • substruct – sub-struct definition that shall be inserted
  • struct_name – name of the struct that contains a struct reference
  • substruct_name – name of the sub-struct definition that shall be inserted

Resolve struct references in structs and fill in the content of the struct


Return all loaded structure template definitions

Return type:dict
load_itemdefinitions(env_dir, items_dir, etc_dir, plugins_dir)[source]

Load item definitions

This method is called during initialization of SmartHomeNG to initialize the item tree. For that, it loads the item definitions from ../items directory through calling the function parse_itemsdir() from lib.config

  • env_dir (str) – path to the directory containing the core’s environment item definition files
  • items_dir (str) – path to the directory containing the user’s item definition files
  • etc_dir (str) – path to the directory containing the user’s configuration files (only used for ‘struct’ support)
  • plugins_dir (str) – path to the directory containing the plugins (only used for ‘struct’ support)
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

  • path (str) – Path of the item
  • item (object) – The item itself

Returns a list with all items defined at the top level

Returns:items defined at the top level
Return type:list

Function to return the item for a given path

Parameters:string (str) – Path of the item to return
Return type:object

Function to return a list with all defined items

Returns:List of all items
Return type:list

Function to match items against a regular expression

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

Function to find items that match the specified configuration

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

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

list or matching child-items

Return type:



Return the number of defined items

Returns:number of items
Return type:int
stop(signum=None, frame=None)[source]

Stop what all items are doing

At the moment, it stops fading of all items