Twin class

A Device Twin is document describing the state of a device that is stored by an Azure IoT hub and is available even if the device is offline. It is built around 3 sections:

  • Tags: key/value pairs only accessible from the service side
  • Desired Properties: updated by a service and received by the device
  • Reported Properties: updated by the device and received by the service. Note that although it is a possibility, desired and reported properties do not have to match and that the logic to sync these two collections, if necessary, is left to the user of the SDK.

For more information see Understanding Device Twins.

@fires Twin#properties.desired[.path]

Extends
EventEmitter

Properties

defaultMaxListeners
desiredPath
desiredPropertiesUpdatesEnabled
errorEvent
properties

The desired and reported properties dictionaries (respectively in properties.desired and properties.reported).

Methods

addListener(string | symbol, (args: any[]) => void)
emit(string | symbol, any[])
eventNames()
get()
get(Callback<Twin>)

Gets the whole twin from the service.

getMaxListeners()
listenerCount(string | symbol)
listenerCount(string | symbol)
listeners(string | symbol)
off(string | symbol, (args: any[]) => void)
on(string | symbol, (args: any[]) => void)
once(string | symbol, (args: any[]) => void)
prependListener(string | symbol, (args: any[]) => void)
prependOnceListener(string | symbol, (args: any[]) => void)
rawListeners(string | symbol)
removeAllListeners(string | symbol)
removeListener(string | symbol, (args: any[]) => void)
setMaxListeners(number)

Property Details

defaultMaxListeners

static defaultMaxListeners: number

Property Value

number

desiredPath

static desiredPath: string

Property Value

string

desiredPropertiesUpdatesEnabled

desiredPropertiesUpdatesEnabled: boolean

Property Value

boolean

errorEvent

static errorEvent: string

Property Value

string

properties

The desired and reported properties dictionaries (respectively in properties.desired and properties.reported).

properties: TwinProperties

Property Value

Method Details

addListener(string | symbol, (args: any[]) => void)

function addListener(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

emit(string | symbol, any[])

function emit(event: string | symbol, args: any[])

Parameters

event
string | symbol
args
any[]

Returns

boolean

eventNames()

function eventNames()

Returns

Array<string | symbol>

get()

function get()

Returns

Promise<Twin>

get(Callback<Twin>)

Gets the whole twin from the service.

function get(callback: Callback<Twin>)

Parameters

callback
Callback<Twin>

getMaxListeners()

function getMaxListeners()

Returns

number

listenerCount(string | symbol)

function listenerCount(type: string | symbol)

Parameters

type
string | symbol

Returns

number

listenerCount(string | symbol)

function listenerCount(type: string | symbol)

Parameters

type
string | symbol

Returns

number

listeners(string | symbol)

function listeners(event: string | symbol)

Parameters

event
string | symbol

Returns

Function[]

off(string | symbol, (args: any[]) => void)

function off(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

on(string | symbol, (args: any[]) => void)

function on(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

once(string | symbol, (args: any[]) => void)

function once(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

prependListener(string | symbol, (args: any[]) => void)

function prependListener(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

prependOnceListener(string | symbol, (args: any[]) => void)

function prependOnceListener(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

rawListeners(string | symbol)

function rawListeners(event: string | symbol)

Parameters

event
string | symbol

Returns

Function[]

removeAllListeners(string | symbol)

function removeAllListeners(event?: string | symbol)

Parameters

event
string | symbol

Returns

this

removeListener(string | symbol, (args: any[]) => void)

function removeListener(event: string | symbol, listener: (args: any[]) => void)

Parameters

event
string | symbol
listener
(args: any) => void[]

Returns

this

setMaxListeners(number)

function setMaxListeners(n: number)

Parameters

n
number

Returns

this