@tritter/homebridge-shelly
Advanced tools
Comparing version 0.19.6 to 0.20.0
@@ -55,2 +55,3 @@ | ||
Shelly2WindowCoveringAccessory, | ||
ShellyUniWindowCoveringAccessory | ||
} = require('./window-coverings')(homebridge) | ||
@@ -575,4 +576,16 @@ | ||
get numberOfAccessories() { | ||
if (this.config.type === 'windowCovering') { | ||
return 1 | ||
} | ||
return 2 | ||
} | ||
_createAccessory(accessoryType, index, config, log) { | ||
if (this.config.type === 'windowCovering') { | ||
return new ShellyUniWindowCoveringAccessory( | ||
this.device, config, log) | ||
} | ||
return super._createAccessory(accessoryType, index, config, log) | ||
} | ||
} | ||
@@ -579,0 +592,0 @@ FACTORIES.set('SHUNI-1', ShellyUniFactory) |
@@ -6,3 +6,6 @@ | ||
require('../abilities/window-covering')(homebridge) | ||
const { ShellyAccessory } = require('./base')(homebridge) | ||
const StatelessWindowCoveringAbility = | ||
require('../abilities/stateless-window-covering')(homebridge) | ||
const { ShellyAccessory } = | ||
require('./base')(homebridge) | ||
@@ -34,5 +37,44 @@ class Shelly2WindowCoveringAccessory extends ShellyAccessory { | ||
class ShellyUniWindowCoveringAccessory extends ShellyAccessory { | ||
constructor(device, config, log) { | ||
super('windowCovering', device, null, config, log) | ||
this._relayDownIndex = 0 | ||
this._relayUpIndex = 1 | ||
const clearTimeout = config.clearTimeout || 60 | ||
this.abilities.push(new StatelessWindowCoveringAbility( | ||
'relay' + this._relayDownIndex, | ||
'relay' + this._relayUpIndex, | ||
this.setPosition.bind(this), | ||
clearTimeout | ||
)) | ||
} | ||
get category() { | ||
return Accessory.Categories.WINDOW_COVERING | ||
} | ||
/** | ||
* Sets the current position to the new value. | ||
* @returns {Promise} A Promise that resolves when the position has been | ||
* updated. | ||
*/ | ||
setPosition(newValue) { | ||
if (newValue < 50) { | ||
return Promise.all([this.device.setRelay(this._relayUpIndex, false), | ||
this.device.setRelay(this._relayDownIndex, true)]) | ||
} else if (newValue > 50) { | ||
return Promise.all([this.device.setRelay(this._relayDownIndex, false), | ||
this.device.setRelay(this._relayUpIndex, true)]) | ||
} else { | ||
return Promise.all([this.device.setRelay(this._relayUpIndex, false), | ||
this.device.setRelay(this._relayDownIndex, false)]) | ||
} | ||
} | ||
} | ||
return { | ||
Shelly2WindowCoveringAccessory, | ||
ShellyUniWindowCoveringAccessory | ||
} | ||
} |
@@ -146,2 +146,8 @@ { | ||
}, | ||
"clearTimeout": { | ||
"title": "Stateless Clear Timeout", | ||
"type": "number", | ||
"default": 60, | ||
"description": "Sets a timeout at which the position of stateless windowCovering will be resetted to 50% (only windowCovering with Shelly Uni)." | ||
}, | ||
"username": { | ||
@@ -229,2 +235,6 @@ "title": "Username", | ||
{ | ||
"key": "devices[].clearTimeout", | ||
"condition": { "functionBody": "return model.devices && model.devices[arrayIndices[0]].type === 'windowCovering'" } | ||
}, | ||
{ | ||
"key": "devices[]", | ||
@@ -231,0 +241,0 @@ "type": "section", |
{ | ||
"name": "@tritter/homebridge-shelly", | ||
"version": "0.19.6", | ||
"version": "0.20.0", | ||
"description": "Shelly plugin for Homebridge", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
378013
71
6688