Node Server Development

Background

Node servers in Polyglot are nothing more than stand alone processes that are managed by Polyglot. Polyglot communicates with the node servers by reading the STDOUT and STDERR streams as well as writing to the STDIN stream. STDIN and STDOUT messages are JSON formatted commands that are documented in Polyglot Node Server API.

As of Polyglot 0.0.6 MQTT is available as a communication mechanism as well. See MQTT.

File Structure

Node servers are defined in self contained folders. The name given to this folder will be the node server ID and must be unique form all other node servers. New node servers can be stored in Polyglot’s configuration directory in the folder titled node_servers. Inside of this folder, at least the following three files must exist.

  • profile.zip is the profile that must be uploaded to the ISY describing the node server. This file is documented in the ISY Node Server API documentation.
  • instructions.txt should be a file containing instructions on the use of the node server documented using markdown. The contents of this file will be formatted and displayed on the frontend.
  • server.json is the metadata used by Polyglot to identify the node server. This file is documented in the next section.

The rest of the node server’s folder should contain the code required to execute the node server and all necessary libraries with the exception of those explicitly included as part of the Polyglot distribution.

Node servers are executed in special directories in the user’s configuration directory. Each node server type is assigned its own directory. Any required inforation may be written to this directory. Keep in mind, that all running node servers of the same type will share the same directory.

Server Metadata

The server.json file in the node server source directory is a JSON formatted file that informs Polyglot of how the node server is executed as well as other important details about the node server. The file contains a dictionary formatted object with specific fields. A sample server.json is included below. It has been extracted from the Philips Hue node server.

{
    "name": "Phillips Hue",
    "docs": "https://www.universal-devices.com/",
    "type": "python",
    "executable": "hue.py",
            "configfile": "config.yaml",
            "interface": "Default",
    "description": "Connect Phillips Hue Personal Wireless Lighting system to the ISY994.",
    "notice": "\"Hue Personal Wireless Lighting\" is a trademark owned by Koninklijke Philips Electronics N.V., see www.meethue.com for more information. This Node Server is neither developed by nor endorsed by the Philips organization.",
    "credits": [
        {
            "title": "phue: A Python library for Philips Hue",
            "author": "Nathanaël Lécaudé (studioimaginaire)",
            "version": "0.9",
            "date": "May 18, 2015",
            "source": "https://github.com/studioimaginaire/phue/tree/c48845992b476f4b1de9549ea5b5277399f56581",
            "license": "https://raw.githubusercontent.com/studioimaginaire/phue/c48845992b476f4b1de9549ea5b5277399f56581/LICENSE"
        }
    ]
}

Below is a description of the required fields:

  • name is the name of the node server type as it will be displayed to the user.
  • docs is a link to an appropriate website about the node server. This value is not currently displayed anywhere.
  • type is the node server executable type. This instructs Polyglot as to how the node server should be launched. Currently, only python is accepted.
  • executable is the file that Polyglot should execute to start the node server process.
  • description is a short description of the node server that will be displayed to the user on the frontend.
  • notice contains any important notices the user might need to know.
  • credits is a list of dictionaries indicating all third party library used in the node server. Some open source projects require that they be credited some where in the project. Others do not. Either way, it is nice to give credit here. When including a third party library in your node server, ensure that it is licensed for commercial use.

In the credits list:

  • title is the title of the third party library.
  • author is the author of the third party library.
  • version is the appropriate versioning tag used to identify the third party library.
  • date is the date the third party library was either released or obtained.
  • source is a link to the library’s source code.
  • license is a link to the library’s license file. Ensure that this is a static link whose contents cannot be changed. Linking to a specific GitHub commit is handy for this.

It can be a good idea to check the formatting of this file with a JSON linter before attempting to load the node server in Polyglot. If this file cannot be read, for whatever reason, the node server will not appear in the Polyglot frontend and an error will be logged.

Python Development

A Python 2.7 compatible implimentation of the API is provided with Polyglot to assist in Node Server development. It may be easily imported as shown below. In the future, more libraries may be made available and more languages may be supported.

from polyglot import nodeserver_api

The provided Node Server Library exposes all of the ISY controller’s Node Server RESTful API as is. Data recieved by Polyglot’s web server is parsed and directed immediately to the node server process via this library. The library will also send messages back up to Polyglot to be transmitted directly to the ISY. The only exception to this rule is that node ID’s will not have the node server ID prefix prepended to them. It will also be expected that the node server will not prepend these prefixes. Polyglot will handle the node ID prefixes on behalf of the node servers.

There also exists, in the Python library, some abstract classes that may be used to ease the development of a new node server. Except in rare cases where it may not be appropriate, it is recomended that these be used.

When Python is used to develop node server, the Polyglot environment is loaded into the Python path. This environment includes the Requests library.

Python Polyglot Library

Summary

This library consists of four classes and one function to assist with node server development. The classes polyglot.nodeserver_api.NodeServer and polyglot.nodeserver_api.SimpleNodeServer and basic structures for creating a node server. The class polyglot.nodeserver_api.Node is used as an abstract class to crate custom nodes for node servers. The class polyglot.nodeserver_api.PolyglotConnector is a bottom level implementation of the API used to communicate between Polyglot and your node server. Finally, included in this library is a method decorator, polyglot.nodeserver_api.auto_request_report(), that wraps functions and methods to automatically handle report requests from the ISY.

Custom Node Types

When creating a new node server, each node type that will be controlled by the server must be defined. This abstract class may be used as a skeleton for each node type. When inheriting this class, a new method should be defined for each command that the node can perform. Additionally, the _drivers and _commands attributes should be overwritten to define the drivers and commands relevant to the node.

class polyglot.nodeserver_api.Node(parent, address, name, primary=True, manifest=None)[source]

Abstract class for representing a node in a node server.

Parameters:
  • parent (polyglot.nodeserver_api.NodeServer) – The node server that controls the node
  • address (str) – The address of the node in the ISY without the node server ID prefix
  • name (str) – The name of the node
  • primary (polyglot.nodeserver_api.Node or True if this node is the primary.) – The primary node for the device this node belongs to, or True if it’s the primary.
  • manifest (dict or None) – The node manifest saved by the node server
_drivers = {}

The drivers controlled by this node. This is a dictionary of lists. The key’s are the driver names as defined by the ISY documentation. Each list contains at least three values: the initial value, the UOM identifier, and a function that will properly format the value before assignment. The fourth value is optional – if provided, and set to “False”, the driver’s value will not be recorded in the manifest (this is useful to reduce I/O when there is no benefit to restoring the driver’s value on restart).

Insteon Dimmer Example:

_drivers = {
    'ST': [0, 51, int],
    'OL': [100, 51, int],
    'RR': [0, 32, int]
}

Pulse Time Example:

_drivers = {
    'ST': [0, 56, int, False],
}
_commands = {}

A dictionary of the commands that the node can perform. The keys of this dictionary are the names of the command. The values are functions that must be defined in the node object that perform the necessary actions and return a boolean indicating the success or failure of the command.

_report_driver_cb(driver, status_code, **kwargs)[source]

Private method - updates ISY syncronization flag based on the success/fail of the status update API call to the ISY.

add_node()[source]

Adds node to the ISY

Returns boolean:
 Indicates success or failure of node addition
get_driver(driver=None)[source]

Gets a driver’s value

Parameters:driver (str or None) – The driver to return the value for
Returns:The current value of the driver
manifest

The node’s manifest entry. Indicates the current value of each of the drivers. This is called by the node server to create the full manifest.

Type:dict
node_def_id = ''

The node’s definition ID defined in the node server’s profile

query()[source]

Abstractly queries the node. This method should generally be overwritten in development.

Returns boolean:
 Indicates success or failure of node query
report_driver(driver=None)[source]

Reports a driver’s current value to ISY

Parameters:driver (str or None) – The name of the driver to report. If None, all drivers are reported.
Returns boolean:
 Indicates success or failure to report driver value
report_isycmd(isycommand, value=None, uom=None, timeout=None, **kwargs)[source]

Sends a single command from the node server to the ISY, optionally passing in a value.

No formatting, and little validation, of the isy cmd, value, or uom is done by this simple low-level API. It is up to the caller to ensure correctness.

Parameters:
  • isycommand (str) – Name of the ISY command to send (e.g. ‘DON’)
  • value (string, float, int, or None) – (optional) The value to be sent for the command
  • uom (int or None) – (optional) - The value’s unit of measurement. If provided, overrides the uom defined for this command
  • timeout (int or None) – (optional) - the number of seconds before this command expires and is discarded
Returns boolean:
 

Indicates success or failure to queue for sending (Note: does NOT indicate if actually delivered)

run_cmd(command, **kwargs)[source]

Runs one of the node’s commands.

Parameters:
  • command (str) – The name of the command
  • kwargs (dict) – The parameters specified by the ISY in the incoming request. See the ISY Node Server documentation for more information.
Returns boolean:
 

Indicates success or failure of command

set_driver(driver, value, uom=None, report=True)[source]

Updates the value of one of the node’s drivers. This will pass the given value through the driver’s formatter before assignment.

Parameters:
  • driver (str) – The name of the driver
  • value – The new value for the driver
  • uom (int or None) – The given values unit of measurement. This should correspond to the UOM IDs used by the ISY. Refer to the ISY documentation for more information.
  • report (boolean) – Indicates if the value change should be reported to the ISY. If False, the value is changed silently.
Returns boolean:
 

Indicates success or failure to set new value

smsg(strng)[source]

Logs/sends a diagnostic/debug, informative, or error message. Individual node servers can override this method if they desire to redirect or filter these messages.

Polyglot API Implimentation

This class impliments the Polyglot API and calls registered functions when the API is invoked. This class is a singleton and will not allow itself to be initiated more than once. This class binds itself to the STDIN stream to accept commands from Polyglot.

To create a connection in your node server to Polyglot, use something similar to the following. This creates the connection, connect to Polyglot, and then waits for the Node Server’s configuration to be received. The configuration will be the first command received from Polyglot and will never be sent again after the first transmission.:

poly = PolyglotConnector()
poly.connect()
poly.wait_for_config()

Then, commands can be sent upstream to Polyglot or to the ISY by using the connector’s methods.:

poly.send_error('This is an error message. It will be in Polyglot\'s log.')
poly.add_node('node_id_1', 'NODE_DEFINITION', 'node_id_0', 'New Node')
poly.report_status('node_id_1', 'ST', value=55, uom=51)
poly.remove_node('node_id_1')

To respond to commands received from Polyglot and the ISY, handlers must be registered for events. The handlers arguments will be the parameters specified in the API for that event. This will look something like the following.:

def status_handler(node_address, request_id=None):
    print('Status Event Handler Called')

poly.listen('status', status_handler)

Now, when the ISY requests a status update from Polyglot, this function will be called. Handlers will not be called in the node server’s main thread.

class polyglot.nodeserver_api.PolyglotConnector[source]

Polyglot API implementation. Connects to Polyglot and handles node server IO.

Raises:RuntimeError
add_node(node_address, node_def_id, primary, name, timeout=None, seq=None)[source]

Adds a node to the ISY. To make this node the primary, set primary to the same value as node_address.

Parameters:
  • node_address (str) – The full address of the node (e.g. ‘dimmer_1’)
  • node_def_id (str) – The id of the node definition to use for this node
  • primary (str) – The primary node for the device this node belongs to
  • name (str) – The name of the node
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
change_node(node_address, node_def_id, timeout=None, seq=None)[source]

Changes the node definition to use for an existing node. An example of this is may be to change a thermostat node from Fahrenheit to Celsius.

Parameters:
  • node_address (str) – The full address of the node (e.g. ‘dimmer_1’)
  • node_def_id (str) – The id of the node definition to use for this node
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
commands = ['config', 'install', 'query', 'status', 'add_all', 'added', 'removed', 'renamed', 'enabled', 'disabled', 'cmd', 'ping', 'exit', 'params', 'result', 'statistics']

Commands that may be invoked by Polyglot

connect()[source]

Connects to Polyglot if not currently connected

connected

Indicates if the object is connected to Polyglot. Can be set to control connection with Polyglot.

Type:boolean
disconnect()[source]

Disconnects from Polyglot. Blocks the thread until IO stream is clear

exit(*args, **kwargs)[source]

Tells Polyglot that this Node Server is done.

get_params(**kwargs)[source]

Get the params from nodeserver and makes them available to the nodeserver api

install(*args, **kwargs)[source]

Abstract method to install the node server in the ISY. This has not been implemented yet and running it will raise an error.

Raises:NotImplementedError
listen(event, handler)[source]

Register an event handler. Returns True on success. Event names are defined in commands. Handlers must be callable.

Parameters:
  • event (str) – Then event name to listen for.
  • handler (callable) – The callable event handler.
logger = None

logger is initialized after the node server wait_for_config completes by the setup_log method and the log file is located in the node servers sandbox. Once wait_for_config is complete, you can call poly.logger.info(‘This variable is set to %s’, variable)

pong(*args, **kwargs)[source]

Sends pong reply to Polyglot’s ping request. This verifies that the communication between the Node Server and Polyglot is functioning.

remove_node(node_address, timeout=None, seq=None)[source]

Removes a node from the ISY. A node cannot be removed if it is the primary node for at least one other node.

Parameters:
  • node_address (str) – The full address of the node (e.g. ‘dimmer_1’)
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
report_command(node_address, command, value=None, uom=None, timeout=None, seq=None, **kwargs)[source]

Sends a command to the ISY that may be used in programs and/or scenes. A common use of this is a physical switch that somebody turns on or off. Each time the switch is used, a command should be reported to the ISY. These are used for scenes and control conditions in ISY programs.

Parameters:
  • node_address (str) – The full address of the node (e.g. ‘switch_1)
  • command (str) – The command to perform (e.g. ‘DON’, ‘CLISPH’, etc.)
  • value (str, int, or float) – Optional unnamed value the command used
  • uom (int or str) – Optional units of measurement of value
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
  • <pN>.<uomN> (optional) – Nth Parameter name (e.g. ‘level’) . Unit of measure of the Nth parameter (e.g. ‘seconds’, ‘uom58’)
report_request_status(request_id, success, timeout=None, seq=None)[source]

When the ISY sends a request to the node server, the request may contain a ‘requestId’ field. This indicates to the node server that when the request is completed, it must send a fail or success report for that request. This allows the ISY to in effect, have the node server synchronously perform tasks. This message must be sent after all other messages related to the task have been sent.

For example, if the ISY sends a request to query a node, all the results of the query must be sent to the ISY before a fail/success report is sent.

Parameters:
  • request_id (str) – The request ID the ISY supplied on a request to the node server.
  • success (bool) – Indicates if the request was sucessful
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
report_status(node_address, driver_control, value, uom, timeout=None, seq=None)[source]

Updates the ISY with the current value of a driver control (e.g. the current temperature, light level, etc.)

Parameters:
  • node_address (str) – The full address of the node (e.g. ‘dimmer_1’)
  • driver_control (str) – The name of the status value (e.g. ‘ST’, ‘CLIHUM’, etc.)
  • value (str, float, or int) – The numeric status value (e.g. ‘80.5’)
  • uom (int or str) – Unit of measure of the status value
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
request_stats(*args, **kwargs)[source]

Sends a command to Polyglot to request a statistics message.

restcall(api, timeout=None, seq=None)[source]

Calls a RESTful api on the ISY. The api is the portion of the url after the “https://isy/rest/” prefix.

Parameters:
  • api (str) – The url for the api to call
  • timeout (str, float, or int) – (optional) timeout (seconds) for REST call to ISY
  • seq (str or int) – (optional) set to unique id if result callback desired
send_config(config_data)[source]

Update the configuration in Polyglot.

Parameters:config_data (dict) – Dictionary of updated configuration
Raises:ValueError
send_error(err_str)[source]

Enqueue an error to be sent back to Polyglot.

Parameters:err_str (str) – Error text to be sent to Polyglot log
smsg(str)[source]

Logs/sends a diagnostic/debug, informative, or error message. Individual node servers can override this method if they desire to redirect or filter these messages.

uptime

The number of sections the connection with Polyglot has been alive

Type:float
wait_for_config()[source]

Blocks the thread until the configuration is received

write_nodeserver_config(default_flow_style=False, indent=4)[source]

Writes any changes to the nodeserver custom configuration file. self.nodeserver_config should be a dictionary. Refrain from calling this in a poll of any kind. Typically you won’t even have to write this unless you are storing custom data you want retrieved on the next run. Saved automatically during normal Polyglot shutdown. Returns True for success, False for failure.

Parameters:
  • default_flow_style (boolean) – YAML’s default flow style formatting. Default False
  • indent (int) – Override the default indent spaces for YAML. Default 4

Node Server Classes

class polyglot.nodeserver_api.NodeServer(poly, shortpoll=1, longpoll=30)[source]

It is generally desireable to not be required to bind to each event. For this reason, the NodeServer abstract class is available. This class should be abstracted. It binds appropriate handlers to the API events and contains a suitable run loop. It should serve as a basic structure for any node server.

Parameters:
  • poly (polyglot.nodeserver_api.PolyglotConnector) – The connected Polyglot connection
  • optional shortpoll (int) – The seconds between poll events
  • optional longpoll (int) – The second between longpoll events
add_node(node_address, node_def_id, node_primary_addr, node_name, callback=None, timeout=None, **kwargs)[source]

Add this node to the polyglot

Returns bool:True on success
long_poll()[source]

Called every longpoll seconds for less important polling.

on_add_all(request_id=None)[source]

Received add all command from ISY

Parameters:optional request_id (str) – Status request id
Returns bool:True on success
on_added(node_address, node_def_id, primary_node_address, name)[source]

Received node added report from ISY

Parameters:
  • node_address (str) – The address of the node to act on
  • node_def_id (str) – The node definition id
  • primary_node_address (str) – The node server’s primary node address
  • name (str) – The node’s friendly name
  • optional request_id (str) – Status request id
Returns bool:

True on success

on_cmd(node_address, command, value=None, uom=None, request_id=None, **kwargs)[source]

Received run command from ISY

Parameters:
  • node_address (str) – The address of the node to act on
  • command (str) – The command to run
  • value (optional) – The value of the command’s unnamed parameter
  • uom (optional) – The units of measurement for the unnamed parameter
  • optional request_id (str) – Status request id
  • <pN>.<uomN> (optional) – The value of parameter pN with units uomN
Returns bool:

True on success

on_config(**data)[source]

Received configuration data from Polyglot

Parameters:data (dict) – Configuration data
Returns bool:True on success
on_disabled(node_address)[source]

Received node disabled report from ISY

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_enabled(node_address)[source]

Received node enabled report from ISY

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_exit(*args, **kwargs)[source]

Polyglot has triggered a clean shutdown. Generally, this method does not need to be orwritten.

Returns bool:True on success
on_install(profile_number)[source]

Received install command from ISY

Parameters:profile_number (int) – Noder Server’s profile number
Returns bool:True on success
on_query(node_address, request_id=None)[source]

Received query command from ISY

Parameters:
  • node_address (str) – The address of the node to act on
  • optional request_id (str) – Status request id
Returns bool:

True on success

on_removed(node_address)[source]

Received node removed report from ISY

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_renamed(node_address, name)[source]

Received node renamed report from ISY

Parameters:
  • node_address (str) – The address of the node to act on
  • name (str) – The node’s friendly name
Returns bool:

True on success

on_result(seq, status_code, elapsed, text, retries, reason_code, **kwargs)[source]

Handles a result message, which contains the result from a REST API call to the ISY. The result message is uniquely identified by the seq id, and will always contain at least the numeric status.

on_statistics(**kwargs)[source]

Handles a statistics message, which contains various statistics on the operation of the Polyglot server and the network communications.

on_status(node_address, request_id=None)[source]

Received status command from ISY

Parameters:
  • node_address (str) – The address of the node to act on
  • optional request_id (str) – Status request id
Returns bool:

True on success

poll()[source]

Called every shortpoll seconds to allow for updating nodes.

poly = None

The Polyglot Connection

Type:polyglot.nodeserver_api.PolyglotConnector
register_result_cb(func, **kwargs)[source]

Registers a callback function to handle a result. Returns the unique sequence ID to be passed to the function whose result is to be handled by the registered callback.

report_status(node_address, driver_control, value, uom, callback=None, timeout=None, **kwargs)[source]

Report a node status to the ISY

Returns bool:True on success
restcall(api, callback=None, timeout=None, **kwargs)[source]

Sends an asynchronous REST API call to the ISY. Returns the unique seq id (that can be used to match up the result later on after the REST call completes).

run()[source]

Run the Node Server. Exit when triggered. Generally, this method should not be overwritten.

setup()[source]

Setup the node server. All node servers must override this method and call it thru super. Currently it only sets up the reference for the logger.

smsg(strng)[source]

Logs/sends a diagnostic/debug, informative, or error message. Individual node servers can override this method if they desire to redirect or filter these messages.

tock()[source]

Called every few seconds for internal housekeeping.

class polyglot.nodeserver_api.SimpleNodeServer(poly, shortpoll=1, longpoll=30)[source]

Simple Node Server with basic functionality built-in. This class inherits from polyglot.nodeserver_api.NodeServer and is the best starting point when developing a new node server. This class implements the idea of manifests which are dictionaries that contain the relevant information about all of the nodes. The manifest gets sent to Polyglot to be saved as part of the configuration. This allows the node server to automatically recall its last known values when it is restarted.

add_node(*args, **kwargs)[source]

Add node to the Polyglot and the nodes dictionary.

Parameters:node (polyglot.nodeserver_api.Node) – The node to add
Returns boolean:
 Indicates success or failure of node addition
exist_node(address)[source]

Check if a node exists by its address.

Parameters:address (str) – The node address
Returns bool:True if the node exists
get_node(address)[source]

Get a node by its address.

Parameters:address (str) – The node address
Returns polyglot.nodeserver_api.Node:
 If found, otherwise False
nodes = OrderedDict()

Nodes registered with this node server. All nodes are automatically added by the add_node method. The keys are the node IDs while the values are instances of polyglot.nodeserver_api.Node. Classes inheriting can access this directly, but the prefered method is by using get_node or exist_node methods.

on_add_all(*args, **kwargs)[source]

Adds all nodes to the ISY. Also sends requests reponses when necessary.

Parameters:optional request_id (str) – Status request id
Returns bool:True on success
on_added(node_address, node_def_id, primary_node_address, name)[source]

Internally indicates that the specified node has been added to the ISY.

Parameters:
  • node_address (str) – The address of the node to act on
  • node_def_id (str) – The node definition id
  • primary_node_address (str) – The node server’s primary node address
  • name (str) – The node’s friendly name
  • optional request_id (str) – Status request id
Returns bool:

True on success

on_cmd(*args, **kwargs)[source]

Runs the specified command on the specified node. Also sends requests reponses when necessary.

Parameters:
  • node_address (str) – The address of the node to act on
  • command (str) – The command to run
  • value (optional) – The value of the command’s unnamed parameter
  • uom (optional) – The units of measurement for the unnamed parameter
  • optional request_id (str) – Status request id
  • <pN>.<uomN> (optional) – The value of parameter pN with units uomN
Returns bool:

True on success

on_disabled(node_address)[source]

Received node disabled report from ISY

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_enabled(node_address)[source]

Received node enabled report from ISY

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_exit(*args, **kwargs)[source]

Triggers a clean shut down of the node server by saving the manifest, clearing the IO, and stopping.

Returns bool:True on success
on_query(*args, **kwargs)[source]

Queries each node and reports all control values to the ISY. Also responds to report requests if necessary.

Parameters:
  • node_address (str) – The address of the node to act on
  • optional request_id (str) – Status request id
Returns bool:

True on success

on_removed(node_address)[source]

Internally indicates that a node has been removed from the ISY.

Parameters:node_address (str) – The address of the node to act on
Returns bool:True on success
on_renamed(node_address, name)[source]

Changes the node name internally to match the ISY.

Parameters:
  • node_address (str) – The address of the node to act on
  • name (str) – The node’s friendly name
Returns bool:

True on success

on_status(*args, **kwargs)[source]

Reports the requested node’s control values to the ISY without forcing a query. Also sends requests reponses when necessary.

Parameters:
  • node_address (str) – The address of the node to act on
  • optional request_id (str) – Status request id
Returns bool:

True on success

update_config(replace_manifest=False)[source]

Updates the configuration with new node manifests and sends the configuration to Polyglot to be saved.

Parameters:replace_manifest (boolean) – replace or merge existing manifest

Helper Functions

polyglot.nodeserver_api.auto_request_report(fun)[source]

Python decorator to automate request reporting. Decorated functions must return a boolean value indicating their success or failure. It the argument request_id is passed to the decorated function, a response will be sent to the ISY. This decorator is implemented in the SimpleNodeServer.

MQTT

MQTT communication mechanism has been developed for communications between Polyglot and the nodeservers. This becomes useful so that you can connected many different nodes to your nodeserver without having the distributed code running directly on the same platform Polyglot resides on. For example, I have a system of nodes that all communicates over MQTT to keep updated, and I don’t want to wrap that entire system into Polyglot. I can develop a simple nodeserver that runs and listens to your existing MQTT to allow communications without having to completely redevelop the system as a polyglot nodeserver. This lays the framework of allowing for completly distributed nodeservers.

Usage

To use the MQTT Subsystem for communications you must include the following into your server.json of your nodeserver:

"interface": "mqtt",
"mqtt_server": "192.168.1.20",
"mqtt_port": "1883",

When Polyglot reads the server.json file and see’s the MQTT interface command it enables the MQTT subsystem for that particular nodeserver. It then sends these params along with the normal params and config to the nodeserver over STDIN, which allows for dynamic passing of the mqtt_server and mqtt_port information to the nodeserver. This is done to avoid having to set the connection information on both server.json AND your nodeserver. If the “interface” setting is missing or anything other than “mqtt” case insensitive, then the standard STDIN/STDOUT mechansims will be used, regardless of if mqtt_server and mqtt_port are provided.

When the Polyglot nodeserver manager enables the MQTT interface, it automatically connects to the MQTT broker and subscribes to the topic:

udi/polyglot/<nodeserver name>/poly

This topic is where your nodeserver will publish any commands destined for Polyglot for example the pong keepalive messages. These messages are formatted in JSON exactly like the exisiting STDOUT messages.

When creating a nodeserver that uses MQTT, you should listen on both STDIN and MQTT and respond based on which mechanism was used. MQTT is a network resource, therefore inherently it is possible to have network disruption or connection issues. When using MQTT in your nodeserver you will subscribe to the topic:

udi/polyglot/<nodeserver name>/node

There is a retianed message that you will get upon subscription to the topic above reflecting the current connection state of the Polyglot side. The json messages are listed below.:

{"connected": {}}
or
{"disconnected": {}}

This state is how you should respond to Polyglot. Using STDOUT if disconnected or MQTT if connected. A “Last Will and Testament” message is configured on the Polyglot side to always make sure the state is accurate even on catastrophic failure. The nodeserver should be configured with this same feature. An example is provided in the Node Server example section of the documentation.

MQTT Subsystem Class

class polyglot.nodeserver_manager.mqttSubsystem(parent)[source]

mqttSubsystem class instantiated if interface is mqtt in server.json

Parameters:parent (polyglot.nodeserver_manager.NodeServer) – The NodeServer object that called this function
start()[source]

The client start method. Starts the thread for the MQTT Client and publishes the connected message.

stop()[source]

The client stop method. If the client is currently connected stop the thread and disconnect. Publish the disconnected message if clean shutdown.