There are two ways to access the API
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.
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:
This library implements items in SmartHomeNG.
The main class
Items implements the handling for all items. This class has a static method to get a handle to the
instance of the Items class, that is created during initialization of SmartHomeNG. This method implements a way to
access the API for handling items without having to juggle through the object hirarchy of the running SmartHomeNG.
This API enables plugins and logics to access the details of the items initialized in SmartHomeNG.
Each item is represented by an instance of the class
The methods of the class Items implement the API for items. They can be used the following way: To call eg. get_toplevel_items(), use the following syntax:
from lib.item import Items sh_items = Items.get_instance() # to access a method (eg. get_toplevel_items()): tl_items = sh_items.get_toplevel_items()
|Note:||Do not use the functions or variables of the main smarthome object any more. They are deprecated. Use the methods of the class Items instead.|
|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.
This class implements the item itself:
Item(smarthome, parent, path, config)
Class from which item objects are created
Itemimplements 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
This class is used by the method
`load_itendefinitions()of the Items object.
This class implements the loading and management of the items in form of the item-tree.
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 anther instance
Parameters: smarthome – Instance of the smarthome master-object