Library: commands

From Yombo
Jump to: navigation, search
commands
Commonly Used No
Status Active

Summary
Manages commands within the Yombo gateway. Not much to do here, use the device object to actually send commands.

Introduction

The commands library tracks commands that are sent to devices and is accessed through any module with self._Commands.

This library isn't typically used much by modules. To send commands to modules, use the Device library. Here's an example:

 1 def some_function(self):
 2         """
 3         Called by any method within a modules, such as a timer, loop,
 4         or other event.
 5 
 6         This example turns on a device and then turns it off one hour later.
 7         """ 
 8         # Example 1 - create a local reference to the device and then send the command
 9         a_device = self._Devices['table lamp']
10         a_device.do_command('on')
11         # This example uses extra memory and CPU cycles, but is easier to read.
12 
13         # Example 2 - just send the command, but with a 3600 second delete
14         self._Devices['table lamp'].do_command('off', delay=3600)
15         # This example uses less memory and CPU cycles.

See also

Hooks

Usage

Here are some examples of searching for commands through a pre-defined variable called self._Commands.

Getting Commands

To find a command, you can use either method below, both will search for a command by its id, label, or machine_label.

  • the_value = self._Commands['on']  # More pythonic
  • the_value = self._Commands.get("off") # For those that are used to other programming languages.

Note: If a command cannot be found, a 'KeyError' exception will be thrown.

Common Functions

For complete list of functions, parameters, exceptions raised, returns, and additional examples, see:  Commands @ Yombo Python API Docs

  • get('atom_name') [doc] [source] - Get an object representing a command.

Examples

Get to get details about a command:

a_command = self._Commands['on']  # Returns a command object
a_command.dump()  # show all the details about the command.

Get a list of all publicly available commands:

1 a_dict = self._Commands.get_public_commands()
2 for cmd_id, command in a_dict.iteritems():
3     logger.debug("{command_details}", command_details=command.dump()

 


This page was last edited on 9 December 2017.