Licence
LGPL-3.0-or-later
Version
1.4.2
Deps
1
Size
12 kB
Vulns
0
Weekly
0
Abstract
This is the basic class holding MQTT message information The yaha home automation is based on messages . Nothing happens without a message . The message runs from creator to broker and then to the receiver . On every step , a reason will added to the mesage including a timestamp to get a full trace .
Contents
Meta
| File | message.js |
| Abstract | This is the basic class holding MQTT message information The yaha home automation is based on messages . Nothing happens without a message . The message runs from creator to broker and then to the receiver . On every step , a reason will added to the mesage including a timestamp to get a full trace . |
| Author | Volker Böhm |
| Copyright | Copyright ( c ) 2020 Volker Böhm |
| License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |
Type definitions
ReasonEntry {Object}
| Name | Type | Description |
|---|---|---|
timestamp |
string |
Timestamp of the event in ISO format |
message |
string |
Event message |
Reason {Array.}
| Name | Type | Description |
|---|---|---|
tst |
test |
Class Message
new Message(topic, value, reason, now)
Creates a message for MQTT
Example
const message = new Message('this/is/a/topic', 'a value', 'a reason')
Message Parameters
| Name | Type | Attribute | Default | Description |
|---|---|---|---|---|
topic |
string |
topic string | ||
value |
string, number |
optional | '' | value to set topic to |
reason |
string, Reason |
optional | null | explaining , why the topic will be set to value |
now |
Date |
optional | new Date ( ) | current time |
Message Members
| Name | Type | description |
|---|---|---|
qos |
integer |
Quality of service ( 0 , 1 or 2 ) the message shall be delivered |
retain |
boolean |
True , if the message shall be retained |
value |
string, bool, number |
Value of the message |
Message Methods
addReason
addReason (reason, now)
Adds a reason to the reason array
addReason Parameters
| Name | Type | Description |
|---|---|---|
reason |
string |
explaining , why the topic will be set to value |
now |
Date, undefined |
current time . If not provided , it will be calculated . usually only passed for debugging reasons . |
getDateOfNewestChange
getDateOfNewestChange () => {Date}
Gets the latest Date of the message by browsing the reasons
getDateOfNewestChange returns
| Type | Description |
|---|---|
Date |
isOn
readonly isOn ()
returns true , if the value is "on" ( 1 , 'on' , 'true' , true )
toJSON
toJSON ()
ensures that the JSON format is well formatted ( value instead of _value )
validate
static validate (object)
Checks the consistence of a message object
validate Parameters
| Name | Type | Description |
|---|---|---|
object |
Object |
object to check or this |
validate throws
| Type | Description |
|---|---|
error |