Items-API

There are two ways to access the API

  1. Directly

    Use it the following way to access the api, if you have no access to the sh object in your method or function:

    # to get access to the object instance:
    from lib.item import Items
    items = Items.get_instance()
    
    # to access a method (eg. to get the list of Items):
    items.return_items()
    
  2. Through the main SmartHome object

    If you have access to the sh object in your method or function, you can use the following way:

    # to access a method (eg. to get the list of Items):
    sh.items.return_items()
    

The API is implemented through the following library:

lib.item

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

Bases: object

Items loader class. Item-methods from bin/smarthome.py are moved here.

Parameters:
  • smarthome – Instance of the smarthome master-object
  • configxxx (str) – Basename of the xxx configuration file
load_itemdefinitions(env_dir, items_dir)[source]
get_toplevel_items()[source]
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 of None
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
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 items

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

Function to match items against a regular expresseion

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 items

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

Stop fading of all items

class lib.item.Item(smarthome, parent, path, config)[source]

Bases: object

expand_relativepathes(attr, begintag, endtag)[source]

converts a configuration attribute containing relative item pathes to absolute pathes

The item’s attribute can be of type str or list (of strings)

The begintag and the endtag remain in the result string!

Parameters:
  • attr – Name of the attribute
  • begintag – string that signals the beginning of a relative path is following
  • endtag – string that signals the end of a relative path
get_stringwithabsolutepathes(evalstr, begintag, endtag, attribute='')[source]

converts a string containing relative item pathes to a string with absolute item pathes

The begintag and the endtag remain in the result string!

Parameters:
  • evalstr – string with the statement that may contain relative item pathes
  • begintag – string that signals the beginning of a relative path is following
  • endtag – string that signals the end of a relative path
  • attribute – string with the name of the item’s attribute, which contains the relative path
Returns:

string with the statement containing absolute item pathes

get_absolutepath(relativepath, attribute='')[source]

Builds an absolute item path relative to the current item

Parameters:
  • relativepath – string with the relative item path
  • attribute – string with the name of the item’s attribute, which contains the relative path (for log entries)
Returns:

string with the absolute item path

add_logic_trigger(logic)[source]
remove_logic_trigger(logic)[source]
get_logic_triggers()[source]
add_method_trigger(method)[source]
remove_method_trigger(method)[source]
get_method_triggers()[source]
age()[source]
update_age()[source]
autotimer(time=None, value=None, compat='compat_1.2')[source]
changed_by()[source]
updated_by()[source]
fade(dest, step=1, delta=1)[source]
id()[source]
last_change()[source]
last_update()[source]
prev_age()[source]
prev_update_age()[source]
prev_change()[source]
prev_update()[source]
prev_value()[source]
remove_timer()[source]
return_children()[source]
return_parent()[source]
set(value, caller='Logic', source=None, dest=None, prev_change=None, last_change=None)[source]
timer(time, value, auto=False, compat='')[source]
type()[source]
get_children_path()[source]
jsonvars()[source]

Translation method from object members to json :return: Key / Value pairs from object members

to_json()[source]
lib.item.json_serialize(obj)[source]

helper method to convert values to json serializable formats

lib.item.json_obj_hook(json_dict)[source]

helper method for json deserialization