Items-API
There are two ways to access the API
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.
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 classItem
. For an item to be valid and usable, it has to be part of the item tree, which is maintained by an object of classItems
.This class is used by the method
`load_itemdefinitions()
of the Items object.
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