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()
    

    This is the preferred method.

  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 module:

lib.item

This library implements items in SmartHomeNG.

Note:

This library is part of the core of SmartHomeNG. Regular plugins should not need to use this API. It is manily implemented for plugins near to the core like backend and the core itself!

The API consists of two classes.

class Item

This class implements the item itself:

class lib.item.item.Item(smarthome, parent, path, config, items_instance=None)[Quellcode]

Class from which item objects are created

The class Item implements the methods and attributes of an item. Each item is represented by an instance of the class Item. For an item to be valid and usable, it has to be part of the item tree, which is maintained by an object of class Items.

This class is used by the method `load_itemdefinitions() of the Items object.

class Item

class Items

This class implements the loading and management of the items in form of the item-tree.

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

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

class Items