Skip to content

Commit

Permalink
Version 1.1.40, configurable voltage range
Browse files Browse the repository at this point in the history
  • Loading branch information
arachnetech committed Mar 18, 2022
1 parent 6f14245 commit 1723060
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
4 changes: 3 additions & 1 deletion docs/Accessories.md
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ Set `confirmationPeriodms` to enable publishing confirmation for `setOn`/`getOn`
"onValue": "<value representing on (optional)>",
"offValue": "<value representing off (optional)>",
"turnOffAfterms": "<milliseconds after which to turn off automatically (optional)>",
"history": "<true to enable History service for Eve App (optional)>"
"history": "<true to enable History service for Eve App (optional)>",
"minVolts": "<minumum voltage (optional)>",
"maxVolts": "<maximum voltage (optional)>"
}
```

Expand Down
3 changes: 3 additions & 0 deletions docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
36 changes: 32 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
} );
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
39 changes: 27 additions & 12 deletions test2/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
]
}

0 comments on commit 1723060

Please sign in to comment.