1.4.2 • Published 3 years ago

@mangar2/message v1.4.2

Weekly downloads
17
License
LGPL-3.0-or-later
Repository
github
Last release
3 years ago

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

Filemessage.js
AbstractThis 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 .
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis 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}

NameTypeDescription
timestampstringTimestamp of the event in ISO format
messagestringEvent message

Reason {Array.}

NameTypeDescription
tsttest

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

NameTypeAttributeDefaultDescription
topicstringtopic string
valuestring, numberoptional''value to set topic to
reasonstring, Reasonoptionalnullexplaining , why the topic will be set to value
nowDateoptionalnew Date ( )current time

Message Members

NameTypedescription
qosintegerQuality of service ( 0 , 1 or 2 ) the message shall be delivered
retainbooleanTrue , if the message shall be retained
valuestring, bool, numberValue of the message

Message Methods

addReason

addReason (reason, now)

Adds a reason to the reason array

addReason Parameters
NameTypeDescription
reasonstringexplaining , why the topic will be set to value
nowDate, undefinedcurrent 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
TypeDescription
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
NameTypeDescription
objectObjectobject to check or this
validate throws
TypeDescription
error