Constructor.
the URL helper to use
the auth builder to authenticate requests with; the required credentials must be set appropriately
the ID of the node with the control to manage
the ID of the control to manage
Optional queryApi: defaulta URL helper for accessing node datum via SolarQuery; if not provided one
                will be created using the environment from api. Useful in a development
                environment when the SolarUser and SolarQuery hosts are different.
Private Readonly #apiPrivate Readonly #authPrivate Optional #lastThe last known instruction status. The val property indicates the control value.
Private Optional #lastThe last known instruction object.
Private Readonly #queryPrivate Readonly #queryPrivate Optional #timerA timeout identifier.
Optional callbackA callback function, which is called after the state of the control changes.
The this reference will be set to this object. If an error has occurred,
the error will be passed as the first argument.
Readonly controlThe control ID to manage.
Readonly nodeThe node ID to manage the control on.
The refresh rate, in milliseconds, when a toggle instruction is queued. Defaults to 5 seconds.
The refresh rate, in milliseconds. Defaults to 20 seconds.
Test if a state change is pending confirmation.
true if a state change is pending (not complete)
Private #currentPrivate #fetchPrivate #getPrivate #lastPrivate Get the last known instruction value, e.g. the state of the control.
the last know value of the control (0 or 1), or undefined
Private #mostPrivate Return the value from either the controlStatus or the first parameter value of an instruction,
whichever is valid and more recent.
Optional controlDatum: ControlDatuma control status object
Optional instruction: defaultan instruction object
the control status value, or undefined if not known
Private #notifyRefresh the control state from SolarNetwork.
Once the ControlToggler#start method is called, this method is invoked periodically automatically. Only call this directly if you need to manually update the state of the control.
promise that resolves after getting the updated state
Get the desired control value.
the last known control value
Set the desired control value.
the control value to set
a promise that resolves to the enqueued instruction
Manage the state of a boolean control switch using SolarNetwork
SetControlParameterinstructions.Use an instance of this class to keep track of, and update the state of, a single switch-like control configured on a SolarNode. Because updating the state of a control is an asynchronous process involving multiple steps, this class simplifies this with a promise-based API that will be resolved when the control value changes.
If the ControlToggler#start method is called, the toggler will make periodic calls to SolarNetwork to get the most recent value for the configured control ID, which it treats as a ControlDatum
sourceIdvalue. Thus if some other process changes the control, the toggler will eventually pick up that change and invoke the callback function.Example