The Atoms library manages the atoms feature to provide non-changing information about the environment the gateway is running in.
For information that about current states of things, such as if it's light or dark outside, see the States Library.
Atom values can be one of:
When possible, it's preferred to not use a list or dictionary.
- Web interface - Atoms - Show atoms within the web interface.
- States Library - Handle items that change states during run time.
- Python code for atoms @ Yombo Python API - For detailed python interactions, more examples.
- _atoms_set_ - Called just after the atom value is set.
The Atoms library can act as both a dictionary and an object, both support reading and writing atoms. The atoms library can be accessed from any module through a pre-defined variable called self._Atoms.
It's simple to read or get an atom value, there are two ways to access:
- the_value = self._Atoms['cpu.count'] # More pythonic
- the_value = self._Atoms.get("cpu.count") # For those that are used to other programming languages.
Note: When reading an Atom If an atom doesn't exist, a 'KeyError' exception will be thrown. To update or write a value is just as easy:
- self._Atoms['cpu.count'] = new_value # More pythonic
- self._Atoms.set("cpu.count", new_value) # For those that are used to other programming languages.
For complete list of functions and additional examples,see: Atoms @ Yombo Python API
- get('atom_name') (source) (doc) - Get the value of an atom. It's better to use self._Atoms['atom_name']
- set('atom_name', 'new value') (source) (doc) - Set the value of an atom. It's better to use