diff --git a/docs/Accessories.md b/docs/Accessories.md index 86fa0cc..36b6744 100644 --- a/docs/Accessories.md +++ b/docs/Accessories.md @@ -787,7 +787,9 @@ Set `confirmationPeriodms` to enable publishing confirmation for `setOn`/`getOn` "onValue": "", "offValue": "", "turnOffAfterms": "", - "history": "" + "history": "", + "minVolts": "", + "maxVolts": "" } ``` diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 64b0184..1e348b6 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -5,6 +5,9 @@ # Homebridge MQTT-Thing: Release Notes +### Version 1.1.40 ++ Added configurable minimum and maximum voltage for outlet (minVolts, maxVolts) + ### Version 1.1.39 + Fix RGB light validation errors (issue #510) diff --git a/index.js b/index.js index c5919f5..6f25b3f 100644 --- a/index.js +++ b/index.js @@ -1168,12 +1168,38 @@ function makeThing( log, accessoryConfig, api ) { } } - function floatCharacteristic( service, property, characteristic, setTopic, getTopic, initialValue ) { - // default state - state[ property ] = initialValue; + function floatCharacteristic( service, property, characteristic, setTopic, getTopic, options ) { + + if( options === undefined ) { + options = {}; + } else if( typeof options === 'number' ) { + options = { initialValue: options }; + } + let initialValue = options.initialValue || 0; // set up characteristic var charac = service.getCharacteristic( characteristic ); + + if( options.minValue !== undefined ) { + charac.props.minValue = options.minValue; + } + + if( options.maxValue !== undefined ) { + charac.props.maxValue = options.maxValue; + } + + if( initialValue < charac.props.minValue ) { + initialValue = charac.props.minValue; + } + + if( initialValue > charac.props.maxValue ) { + initialValue = charac.props.maxValue; + } + + // default state + state[ property ] = initialValue; + + // get/set charac.on( 'get', function( callback ) { handleGetStateCallback( callback, state[ property ] ); } ); @@ -2315,7 +2341,9 @@ function makeThing( log, accessoryConfig, api ) { // Eve.Characteristics.Voltage [Volts] (Eve-only) function characteristic_Voltage( service ) { service.addOptionalCharacteristic( Eve.Characteristics.Voltage ); // to avoid warnings - floatCharacteristic( service, 'voltage', Eve.Characteristics.Voltage, null, config.topics.getVolts, 100 ); + floatCharacteristic( service, 'voltage', Eve.Characteristics.Voltage, null, config.topics.getVolts, { + minValue: config.minVolts, maxValue: config.maxVolts + } ); } // Eve.Characteristics.ElectricCurrent [Amperes] (Eve-only) diff --git a/package.json b/package.json index 1844fc6..949e806 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-mqttthing", - "version": "1.1.39", + "version": "1.1.40", "description": "Homebridge plugin supporting various services over MQTT", "main": "index.js", "scripts": { diff --git a/test2/config.json b/test2/config.json index f3ebdfa..12ec50a 100644 --- a/test2/config.json +++ b/test2/config.json @@ -14,18 +14,6 @@ } ], "disabledAccessories": [ - { - "type": "outlet", - "name": "Test Outlet", - "url": "homebridge2", - "topics": { - "setOn": "test/outlet/on", - "getWatts": "test/outlet/watts", - "getVolts": "test/outlet/voltage" - }, - "accessory": "mqttthing", - "logMqtt": true - }, { "type": "lightbulb-ColTemp", "name": "Light-Temp", @@ -599,6 +587,22 @@ } ], "accessories": [ + { + "type": "outlet", + "name": "Test Outlet", + "url": "homebridge2", + "topics": { + "setOn": "test/outlet/on", + "getInUse": "test/outlet/inuse", + "getWatts": "test/outlet/watts", + "getVolts": "test/outlet/voltage", + "getAmperes": "test/outlet/amps" + }, + "accessory": "mqttthing", + "logMqtt": true, + "minVolts": 0, + "maxVolts": 30 + }, { "accessory": "mqttthing", "type": "lightbulb", @@ -622,6 +626,17 @@ "turnOffAfterms": "120000", "onlineValue": "ON", "offlineValue": "OFF" + }, { + "accessory": "mqttthing", + "type": "lightbulb", + "url": "homebridge2", + "name": "Simple light", + "topics": { + "getOn": "fake/light/getOn", + "setOn": "fake/light/setOn" + }, + "integerValue": true, + "logMqtt": true } ] }