Gets the container's communication manager.
Gets the container object of this controller.
Gets the controller's options as specified in the configuration options.
Gets the registered name of this controller.
The registered name is either defined by the corresponding key in the
Components.controllers
object in the container configuration, or by
invoking Container.registerController
method with this name.
Returns all the registered sensor containers in an array.
Returns all the registered Sensors in an array.
Gets the container's Runtime object.
Creates an Observation object for a Sensor.
Subclasses can override this method to provide their own logic.
Sensor container creating the observation.
Value of the observation.
The quality of the result. (optional)
The validity time of the observation. (optional)
Extra parameters for the observation. (optional)
UUID of associated feature of interest. (optional)
Whenever one of the controller's log methods (e.g. logDebug
, logInfo
,
logWarning
, logError
, logFatal
) is called by application code, the
controller creates a Log object with appropriate property values and
passes it to this method before advertising it.
You can override this method to additionally set certain properties (such
as LogHost.hostname
or Log.logLabels
). Ensure that
super.extendLogObject
is called in your override. The base method does
nothing.
log object to be extended before being advertised
Returns the first registered sensor where the given predicate is true,
undefined
otherwise.
findSensor calls predicate once in arbitrary order for each registered sensor, until it finds one where predicate returns true. If such a sensor is found, that sensor is returned immediately. Otherwise, undefined is returned
the first sensor matching the predicate; otherwise undefined
Returns the channelId associated with a sensor container.
By default, it is the objectId of the Sensor. Subclasses can override this method to provide their own logic.
Returns the Sensor associated with the given Sensor objectId.
If no such sensor exists then undefined
is returned.
Returns the sensor container associated with the given Sensor objectId.
If no such container exists then undefined
is returned.
Returns the sensor IO interface associated with the given Sensor objectId.
If no such sensor IO exists then undefined
is returned.
Returns an observable that emits values read from the sensor.
Only the values read with publishChanneledObservation or publishAdvertisedObservation will emit new values. Reading the sensor value manually with SensorIo.read will not emit any new value.
The observable is created lazily and cached. Once the Sensor associated with the observable is unregistered, all subscriptions to the observable are also unsubscribed.
If the Sensor is not registered, this method will throw an error.
Determines whether a Sensor with the given objectId is registered with this controller.
Advertise a Log object for debugging purposes.
a debug message
any number of log tags
Advertise a Log object for an error.
an error (object)
additional error message
any number of log tags
Advertise a Log object for an error with stacktrace information.
an error (object)
additional error message
any number of log tags
Advertise a Log object for a fatal error.
an error (object)
additional error message
any number of log tags
Advertise an informational Log object.
an informational message
any number of log tags
Advertise a Log object for a warning.
a warning message
any number of log tags
Called when the communication manager is about to start or restart.
Override this method to implement side effects here. Ensure that
super.onCommunicationManagerStarting
is called in your override. The
base implementation does nothing.
Called when the communication manager is about to stop.
Override this method to implement side effects here. Ensure that
super.onCommunicationManagerStopping
is called in your override. The
base implementation does nothing.
Called by the container when this instance should be disposed.
Implement cleanup side effects here. Ensure that super.onDispose
is
called in your override. The base implementation does nothing.
Called when the container has completely set up and injected all dependency components, including all its controllers.
Override this method to perform initializations in your custom controller
class instead of defining a constructor. Although the base implementation
does nothing it is good practice to call super.onInit()
in your
override method; especially if your custom controller class does not
extend from the base Controller
class directly.
Lifecycle method called immediately after an observation is published for a specific Sensor. Default implementation does nothing.
Lifecycle method called just before an observation is published for a specific Sensor.
Default implementation does nothing.
Publishes an observation for a registered Sensor.
If no such registered Sensor exists then an error is thrown. The publication is performed in the form of an advertise event.
The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.
ObjectId of the Sensor to publish the observation.
The quality of the result. (optional)
The validity time of the observation. (optional)
Extra parameters for the observation. (optional)
UUID of associated feature of interest. (optional)
Publishes an observation for a registered Sensor.
If no such registered Sensor exists then an error is thrown. The publication is performed in the form of a channel event. By default the channelId is the sensorId. However, subclasses can change it by overriding getChannelId method.
The observation value is read directly from the IO handler of the Sensor. The observation time is recorded as this method is called. Subclasses can change the final value of the observation object by overriding the createObservation method.
ObjectId of the Sensor to publish the observation.
The quality of the result. (optional)
The validity time of the observation. (optional)
Extra parameters for the observation. (optional)
UUID of associated feature of interest. (optional)
Registers a Sensor to this controller along with its IO handler interface.
You can call this function at runtime or register sensors automatically
at the beginning by passing them in the controller options under
sensors
as a SensorDefinition array.
If a Sensor with the given objectId already exists, this method is simply ignored.
When a sensor is registered, it is advertised to notify other listeners (unless ignoreSensorAdvertise option is set). The controller class also starts to listen on query and discover events for Sensors (unless skipSensorQueryEvents or skipSensorDiscoverEvents options are set).
If the observationPublicationType is not set to none, then the value of
the sensor is read every samplingInterval
milliseconds and published as
an observation automatically.
Sensor to register to the controller.
IO handler interface for the sensor. This could be an Aio
,
InputGpio
, OutputGpio
, MockSensorIo
or a custom handler.
Whether and how the observations of the sensor should be published.
If the observations are published automatically, defines how often the publications should be sent.
Unregisters a previously registered Sensor.
If no such Sensor is registered, then an error is thrown.
This also sends a disadvertise event to notify the listeners (unless ignoreSensorDeadvertise option is set). The query and discover events for this Sensor are ignored from this point on.
If a value observable for the Sensor exists, then all subscriptions to that observable are unsubscribed.
Generated using TypeDoc
Manages a set of registered Sensors and provides a source for both Sensors and Sensor-related objects.
This controller is designed to be used by a server as a counterpart of a SensorObserverController.
You can either register the Sensors manually by calling registerSensor method or do it automatically from the controller options by defining your Sensors in a SensorDefinition array given in the
sensors
option of the controller.SensorSourceController also takes some other options (they all default to false):