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/smarthome.py are moved here.)

  • An instance is created during initialization by bin/smarthome.py

  • 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()):
items.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

Parameters
  • plugin_name

  • struct_name

  • struct

Returns

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

Merges an OrderedDict Tree into another one

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

  • destination (OrderedDict) – destination tree to merge into

Returns

Merged configuration tree

Return type

OrderedDict

Example

Run me with nosetests –with-doctest file.py

>>> 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' } } }
True
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

Parameters
  • 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

fill_nested_structs()[source]

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

Returns

return_struct_definitions()[source]

Return all loaded structure template definitions

Returns

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

Parameters
  • 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

Parameters
  • path (str) – Path of the item

  • item (object) – The item itself

get_toplevel_items()[source]

Returns a list with all items defined at the top level

Returns

items defined at the top level

Return type

list

return_item(string)[source]

Function to return the item for a given path

Parameters

string (str) – Path of the item to return

Returns

Item

Return type

object

return_items()[source]

Function to return a list with all defined items

Returns

List of all items

Return type

list

match_items(regex)[source]

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

find_items(conf)[source]

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

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

item_count()[source]

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