From b9959916fbc08ed48cf5961e51f0032182c85b7d Mon Sep 17 00:00:00 2001 From: David Miller Date: Mon, 18 May 2020 22:05:19 +0100 Subject: [PATCH] Version 1.1.14 --- codecs/json.js | 40 ++++++++++++++++++++++++++++++---------- docs/ReleaseNotes.md | 28 ++++++++++++++++------------ package.json | 2 +- test/config.json | 2 +- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/codecs/json.js b/codecs/json.js index d3ef5bc..9606d10 100644 --- a/codecs/json.js +++ b/codecs/json.js @@ -7,8 +7,17 @@ * "properties": { * "on": "state.power", * "RGB": "state.rgb" - * } + * }, + * "fixed": { fixed properties object (global/default) }, + * "fixedByTopic": { + * "topic1": { fixed properties object for topic1 }, + * "topic2": { fixed properties object for topic2 } + * }, + * "retain": true|false * } + * + * Set retain: true in order to retain the object published for each topic, so that unchanged properties are published. + * (Default is retain: false, recreating object from fixed properties on every publish.) */ 'use strict'; @@ -65,12 +74,15 @@ function init( params ) { } }; - let emptyMessage = function() { - if( jsonConfig && jsonConfig.fixed ) { - return JSON.parse( JSON.stringify( jsonConfig.fixed ) ); - } else { - return {}; + let emptyMessage = function( topic ) { + if( jsonConfig ) { + if( jsonConfig.fixedByTopic && jsonConfig.fixedByTopic[ topic ] ) { + return JSON.parse( JSON.stringify( jsonConfig.fixedByTopic[ topic ] ) ); + } else if( jsonConfig.fixed ) { + return JSON.parse( JSON.stringify( jsonConfig.fixed ) ); + } } + return {}; }; // pending messages/timers by MQTT topic @@ -80,16 +92,24 @@ function init( params ) { let publishMessage = function( topic, publish ) { let entry = pending[ topic ]; if( entry ) { - // existing entry - clear timer - clearTimeout( entry.tmr ); + // existing entry - clear any timer + if( entry.tmr ) { + clearTimeout( entry.tmr ); + } } else { // new entry - entry = pending[ topic ] = { msg: emptyMessage() }; + entry = pending[ topic ] = { msg: emptyMessage( topic ) }; } // publish later entry.tmr = setTimeout( () => { - pending[ topic ] = null; + if( jsonConfig && jsonConfig.retain ) { + // retain: just clear timer - keep the message + entry.tmr = null; + } else { + // no retain: remove entry + pending[ topic ] = null; + } publish( JSON.stringify( entry.msg ) ); }, 50 ); diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 1502851..4a88c4d 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -5,6 +5,10 @@ # Homebridge MQTT-Thing: Release Notes +### Version 1.1.14 ++ Added air purifier (implemented by @tobekas) ++ JSON codec: added per-topic fixed values and retain option + ### Version 1.1.13 + When using missing confirmation to set offline state, any message received after timeout sets state back to online + Added internal codec concept: specifying a codec with no .js suffix will load it from the mqttthing 'codecs' directory @@ -37,10 +41,10 @@ + Added config-ui-x support for historyOptions ### Version 1.1.6 -+ Added history support for switch (thanks, @tobekas) -+ Fixed #223 and #207 - history not working if getTotalConsumption used (thanks, @tobekas) -+ Fixed history last activation in motion and contact sensor (thanks, @tobekas) -+ Allowed config.url string without protocol, now defaulting to mqtt:// (thanks, @tobekas) ++ Added history support for switch (implemented by @tobekas) ++ Fixed #223 and #207 - history not working if getTotalConsumption used (implemented by @tobekas) ++ Fixed history last activation in motion and contact sensor (implemented by @tobekas) ++ Allowed config.url string without protocol, now defaulting to mqtt:// (implemented by @tobekas) ### Version 1.1.5 + Don't throw an exception at start-up if the configuration is invalid (as this stops Homebridge unnecessarily) @@ -88,7 +92,7 @@ ### Version 1.0.42 + Added publishing confirmation (`setOn` message must be echoed to `getOn` topic to confirm that it has been processed by the accessory), with automatic republishing -+ Added Television (thanks, tobekas) ++ Added Television (implemented by tobekas) + Fix to characteristics with multiple states (thanks, tobekas) ### Version 1.0.41 @@ -98,7 +102,7 @@ + Thermostat: Allow target heating/cooling states to be restricted ### Version 1.0.39 -+ Valve: Added duration timer (thanks, tobekas) ++ Valve: Added duration timer (implemented by tobekas) ### Version 1.0.38 + Thermostat: Allow minimum and maximum target temperature to be configured @@ -111,11 +115,11 @@ + Added experimental support for RGBWWCW lights (red, green, blue, warm_white and cold_white channels) ### Version 1.0.35 -+ Added Valve (for Sprinkler, Shower and Faucet) - thanks, tobekas ++ Added Valve (for Sprinkler, Shower and Faucet) - implemented by tobekas ### Version 1.0.34 -+ Added Air Pressure Sensor (thanks, tobekas) -+ Added Weather Station with custom Eve characteristics (thanks, tobekas) ++ Added Air Pressure Sensor (implemented by tobekas) ++ Added Weather Station with custom Eve characteristics (implemented by tobekas) + Fakegato-History fix ### Version 1.0.33 @@ -125,15 +129,15 @@ + Added resetStateAfterms option for contact sensor, leak sensor and smoke sensor ### Version 1.0.31 -+ Added Eve history support for outlet power consumption (thanks, tobekas) ++ Added Eve history support for outlet power consumption (implemented by tobekas) + Wrap exception handling around 'apply' functions (used for encoding/decoding MQTT messages), so that errors don't crash Homebridge and messages that can't be decoded are skipped ### Version 1.0.30 + Added Elgato history support for AirQuality (thanks, sieren) -+ Extended Eve history support (thanks, tobekas) ++ Extended Eve history support (implemented by tobekas) ### Version 1.0.29 -+ Added history support for Eve App (only) using fakegato-history. (Thanks, tobekas!) ++ Added history support for Eve App (only) using fakegato-history (implemented by tobekas) ### Version 1.0.28 + Improve behaviour of RGB, RGBW and HSV lightbulbs when not using a separate on/off topic diff --git a/package.json b/package.json index ef0a9a8..0863751 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-mqttthing", - "version": "1.1.13", + "version": "1.1.14", "description": "Homebridge plugin supporting various services over MQTT", "main": "index.js", "scripts": { diff --git a/test/config.json b/test/config.json index b650044..c8ac562 100644 --- a/test/config.json +++ b/test/config.json @@ -96,7 +96,7 @@ "integerValue": true, "codec": "keep-alive-codec.js", "keepAliveTopic": "keep/alive", - "keepAlivePeriod": 30, + "keepAlivePeriod": 120, "keepAliveMessage": "Keep-alive!" }, {