Class Items

This class implements the following methods and properties:

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

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

Parameter:

smarthome (object) – Instance of the smarthome master-object

plugin_attributes = {}
plugin_attribute_prefixes = {}
plugin_prefixes_tuple = None
structs = None
static get_instance()[Quellcode]

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()
Rückgabe:

items instance

Rückgabetyp:

object

add_struct_definition(plugin_name, struct_name, struct, from_dir='plugins')[Quellcode]
return_struct_definitions(all=True)[Quellcode]

Return all loaded structure template definitions

Rückgabe:

Rückgabetyp:

dict

load_itemdefinitions(env_dir, items_dir, etc_dir, plugins_dir)[Quellcode]

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

Parameter:
  • 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)[Quellcode]

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

Parameter:
  • path (str) – Path of the item

  • item (object) – The item itself

remove_item(item)[Quellcode]

Function to remove an item from the dictionary of items and delete the item object.

Parameter:

item (object) – The item to delete

get_toplevel_items()[Quellcode]

Returns a list with all items defined at the top level

Rückgabe:

items defined at the top level

Rückgabetyp:

list

return_item(string)[Quellcode]

Function to return the item for a given path

Parameter:

string (str) – Path of the item to return

Rückgabe:

Item

Rückgabetyp:

object

return_items(ordered=False)[Quellcode]

Function to return a list with all defined items

Parameter:

ordered (bool) – return list sorted alphabetically, defaults to False

Rückgabe:

List of all items

Rückgabetyp:

list

match_items(regex)[Quellcode]

Function to match items against a regular expression

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

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

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

item_count()[Quellcode]

Return the number of defined items

Rückgabe:

number of items

Rückgabetyp:

int

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

Stop what all items are doing

At the moment, it stops fading of all items

add_plugin_attribute(plugin_name, attribute_name, attribute)[Quellcode]

Add an attribute definition to the dict of plugin specific item-attributes

Parameter:
  • plugin_name – Name of the plugin that defines the attribute

  • attribute_name – Name of the attribute

  • attribute – Metadata that defines the attribute

Rückgabe:

add_plugin_attribute_prefix(plugin_name, prefix_name, prefix)[Quellcode]

Add an attribute-prefix definition to the dict of plugin specific item-attribute prefixes

Parameter:
  • plugin_name – Name of the plugin that defines the attribute

  • prefix_name – Name of the attribute-prefix

  • prefix – Metadata that defines the attribute-prefix

Rückgabe:

plugin_attribute_exists(attribute_name)[Quellcode]

Returns the type of the attribute’s value

Parameter:

attribute_name – Name of the attribute

Rückgabe:

Type of the attribute’s value or None

get_plugin_attribute_type(attribute_name)[Quellcode]

Returns the type of the attribute’s value

Parameter:

attribute_name – Name of the attribute

Rückgabe:

Type of the attribute’s value or None