Library: atoms

From Yombo
Jump to: navigation, search
atoms
Commonly Used Yes
Status Active

Summary
System information collected at startup and is typically immutable. This includes, system operating system information and Yombo Gateway software details.

Introduction

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.

Value Types

Atom values can be one of:

  • string
  • int
  • float
  • decimal
  • dictionary
  • list

When possible, it's preferred to not use a list or dictionary.

See also

Hooks

Usage

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.

Reading Values

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.

Common Functions

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


This page was last edited on 10 November 2019.