Adapter

Adapter

new Adapter(opts, bridge)

Source:
Parameters:
Name Type Description
opts Object

Adapter settings (e.g. file, plugins)

Properties
Name Type Attributes Description
file String

The relative path to your adapter file

sequencer Object <optional>

Request an optional Sequencer plugin

queue Object <optional>

Request an optional Queue plugin

nodeStateMonitor Object <optional>

Request an optional NodeStateMonitor plugin

configurator Object <optional>

Request an optional Configurator plugin

pollingManager Object <optional>

Request an optional PollingManager plugin

pairer Object <optional>

Request an optional Pairer plugin

bridge Bridge

The Bridge instance associated with this adapter

Members

bridge :Bridge

Source:

The bridge instance

Type:

classes :adapterClassesObj

Source:

The adapter's classes

Type:

emitter :EventEmitter

Source:

This Adapter's Event Emitter

Type:
  • EventEmitter

k4 :Object

Source:

The K4Model instance

Type:
  • Object

mapping :Object

Source:

The adapters mapping object

Type:
  • Object

opts :Object

Source:

The opts object of this adapter

Type:
  • Object

plugins :Object

Source:

The instances of the adapter plugins (queue, sequencer, etc.)

Type:
  • Object

Methods

close()

Source:

Called to tear down the adapter

extractMappingObjForDevice(devicePath) → {Object}

Source:

Gets the current mapping for a given device, with the raw command class names as opposed to the classes themselves.

Parameters:
Name Type Description
devicePath String
Throws:
Error
Returns:
Type
Object

findBridgeDeviceByNode(node) → {Device}

Source:

Returns the device object associated with a K4Model node, or fails with an exception.

Parameters:
Name Type Description
node String | K4.Child
Throws:
Error
Returns:
Type
Device

(abstract) getAddress(device, command) → {Promise}

Source:

Resolves the transport address for a device

Parameters:
Name Type Description
device Device

The device the command was sent to

command Command

The command being sent

Returns:
Type
Promise

getBridgeDevicePathById(nodeId) → {String}

Source:

Obtain the bridge device path based on the supplied nodeId

Parameters:
Name Type Description
nodeId String | Integer
Returns:

The device path

Type
String

getBridgeDevicesList() → {Array.<Device>}

Source:

Obtain the current list of bridge devices

Returns:
Type
Array.<Device>

(abstract) getId(address, data, response) → {Promise}

Source:

Resolves the device id from received data. Resolve with the id or 'bridge'

Parameters:
Name Type Description
address Object

The address the data was received from

data Buffer

The data received

response Response

The response matching the data

Returns:
Type
Promise

(async, private) getResponse(address, data, item) → {Promise}

Source:

Tests an individual response for non-null return from fromData() method

Parameters:
Name Type Description
address String | Object

The address the data was received from

data Buffer

The data received

item Response

The response to compare

Returns:
Type
Promise

(private) getResponses(address, data) → {Array.<Promise>}

Source:

Generates a list of responses that returned non-null from fromData() method

Parameters:
Name Type Description
address String | Object

The address the data was received from

data Buffer

The data received

Returns:

List of promises

Type
Array.<Promise>

(abstract) getSequence(data) → {String|null}

Source:

Resolves any matching sequence id from incoming data. Returns null if no sequence id found. Not required if a sequencer is not used.

Parameters:
Name Type Description
data Buffer

The data received

Returns:
Type
String | null

identifyReinitializablePlugins() → {Array}

Source:

Check to see which plugins are indicated for reinitialization.

Returns:

List of plugin names that are marked for reinitialization.

Type
Array

init()

Source:

Called to initialize the adapter

initializePlugins(pluginNames) → {Promise.<Array>}

Source:

Initialize the plugins that are specified, if said plugins support being initialized.

Parameters:
Name Type Description
pluginNames Array
Returns:

Responses from the plugin initialization routines that were executed.

Type
Promise.<Array>

(private) load()

Source:

Loads the adapter classes

(private) loadDir(type)

Source:

Loads classes from directory (may involve recursive call)

Parameters:
Name Type Description
type String

The directory to load: "commands" or "responses"

loadMapping() → {Object}

Source:

Makes the ingested mapping available to the bridge.

Throws:
Error
Returns:

The usable, bridge-compatible mapping

Type
Object

loadMappingCommandClasses(rawMappingObj)

Source:

Inserts the appropriate actual command classes themselves to replace the command class names in original mapping

Parameters:
Name Type Description
rawMappingObj Object

The mapping object directly parsed from a JSON file.

(private) readMapping() → {Object}

Source:

Ingests the mapping JSON file

Throws:
Error
Returns:

The object form of the mapping JSON file

Type
Object

(private) received(address, data)

Source:

Processes received data. Attempts sequencer first, then iterates across all adapter response classes

Parameters:
Name Type Description
address Object

The address the data was received from

data Buffer

The data received

(private) removeDeviceNodesWatcher()

Source:

Tears down the EventListener to monitor changes to the device nodes list

(private) removeMappingChangeWatcher()

Source:

Unregisters the file watcher for the mapping JSON file if the file watcher exists. If yes, the Adapter emits an event to all subscribers indicating that the watcher is closed.

(abstract) send(address, command) → {Promise}

Source:

Sends a command through the adapter

Parameters:
Name Type Description
address Object

The destination device

command Command

The command being sent

Returns:
Type
Promise

(async) sendCommand(command, device, argsopt) → {Promise}

Source:

Build a command by name and call adapter send

Parameters:
Name Type Attributes Description
command String | function

The name of the command or the command class

device Device

The destination device for this command

args Object | Array <optional>

The command args

Returns:
Type
Promise

(private) setupDeviceNodesWatcher()

Source:

Creates an EventListener to monitor changes to the device nodes list

(private) setupMappingChangeWatcher()

Source:

Creates a file watcher for the mapping JSON file. If that file changes, the watcher will check if the actual contents have changed. If yes, then the bridge devices list is refreshed and the Adapter emits an event to all subscribers indicating a mapping change.

tearDownPlugins(pluginNames) → {Promise.<Array>}

Source:

Tear down the plugins that are specified, if said plugins support being torn-down.

Parameters:
Name Type Description
pluginNames Array
Returns:

Responses from the plugin tear-down routines that were executed.

Type
Promise.<Array>