Skip to content

Commit

Permalink
Fix SetDuration initialValue
Browse files Browse the repository at this point in the history
  • Loading branch information
arachnetech committed Nov 27, 2021
1 parent ad7826c commit dcb243d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2488,13 +2488,21 @@ function makeThing( log, accessoryConfig, api ) {
topic_getDuration = subConfig.topics.getDuration;
}
}

let initialValue = 1200;
if( config.minDuration !== undefined && initialValue < config.minDuration ) {
initialValue = config.minDuration;
} else if( config.maxDuration !== undefined && initialValue > config.maxDuration ) {
initialValue = config.maxDuration;
}

if( !topic_setDuration ) {
/* no topic specified, but propery is still created internally */
addCharacteristic( service, property_setDuration, Characteristic.SetDuration, 1200, function() {
addCharacteristic( service, property_setDuration, Characteristic.SetDuration, initialValue, function() {
log.debug( 'set "' + property_setDuration + '" to ' + state[ property_setDuration ] + 's.' );
} );
} else {
integerCharacteristic( service, property_setDuration, Characteristic.SetDuration, topic_setDuration, topic_getDuration, { initialValue: 1200 } );
integerCharacteristic( service, property_setDuration, Characteristic.SetDuration, topic_setDuration, topic_getDuration, { initialValue } );
}
// minimum/maximum duration
if( config.minDuration !== undefined || config.maxDuration !== undefined ) {
Expand Down

0 comments on commit dcb243d

Please sign in to comment.