iobroker.shelly
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"common": { | ||
"name": "shelly", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"news": { | ||
"0.2.0": { | ||
"en": "Roller/shutter modus supported", | ||
"de": "Rollädenmodus wird unterstützt" | ||
}, | ||
"0.1.1": { | ||
"en": "Bug fixing", | ||
"de": "Fehlerbehebung" | ||
}, | ||
"0.1.0": { | ||
@@ -55,3 +63,3 @@ "en": "Initiale Shelly Adapter Version", | ||
"loglevel": "info", | ||
"type": "switch", | ||
"type": "iot-systems", | ||
"restartAdapters": [] | ||
@@ -58,0 +66,0 @@ }, |
@@ -8,2 +8,3 @@ /* jshint -W097 */ | ||
// ******************************************************************************* | ||
@@ -97,2 +98,49 @@ // Devicelist | ||
}, | ||
'SwitchTimer': { | ||
type: 'number', | ||
role: 'level.timer', | ||
name: 'Timer', | ||
read: true, | ||
write: true, | ||
unit: 's', | ||
def: 0 | ||
}, | ||
'Shutter': { | ||
type: 'number', | ||
role: 'value.direction', | ||
name: 'Shutter', | ||
read: true, | ||
write: true, | ||
states: '0:pause;1:up;2:down' | ||
}, | ||
'ShutterUp': { | ||
type: 'boolean', | ||
role: 'button', | ||
name: 'Open', | ||
read: false, | ||
write: true | ||
}, | ||
'ShutterDown': { | ||
type: 'boolean', | ||
role: 'button', | ||
name: 'Close', | ||
read: false, | ||
write: true | ||
}, | ||
'ShutterStop': { | ||
type: 'boolean', | ||
role: 'button.stop', | ||
name: 'Pause', | ||
read: false, | ||
write: true | ||
}, | ||
'ShutterDuration': { | ||
type: 'number', | ||
role: 'level.timer', | ||
name: 'Duration', | ||
read: true, | ||
write: true, | ||
unit: 's', | ||
def: 0 | ||
}, | ||
'VSwitch': { | ||
@@ -148,2 +196,3 @@ type: 'boolean', | ||
}, | ||
}; | ||
@@ -150,0 +199,0 @@ |
@@ -17,4 +17,10 @@ /* jshint -W097 */ | ||
const adapterObjects = {}; | ||
function setOrUpdateObject(id, obj, value, stateChangeCallback, createNow) { | ||
function setOrUpdateObject(id, obj, obtainCustomFields, value, stateChangeCallback, createNow) { | ||
let callback = null; | ||
if (!Array.isArray(obtainCustomFields)) { | ||
createNow = stateChangeCallback; | ||
stateChangeCallback = value; | ||
value = obtainCustomFields; | ||
obtainCustomFields = []; | ||
} | ||
if (typeof value === 'function') { | ||
@@ -88,3 +94,4 @@ createNow = stateChangeCallback; | ||
obj: obj, | ||
stateChangeCallback: stateChangeCallback | ||
stateChangeCallback: stateChangeCallback, | ||
obtainCustomFields: obtainCustomFields | ||
}); | ||
@@ -183,2 +190,7 @@ adapterObjects[id] = JSON.parse(JSON.stringify(obj)); | ||
if (!err && obj) { | ||
if (Array.isArray(queueEntry.obtainCustomFields)) { | ||
queueEntry.obtainCustomFields.forEach(name => { | ||
if (queueEntry.obj.common && queueEntry.obj.common[name]) delete queueEntry.obj.common[name]; | ||
}); | ||
} | ||
adapter.extendObject(queueEntry.id, queueEntry.obj, () => { | ||
@@ -185,0 +197,0 @@ handleValue(queueEntry, () => { |
{ | ||
"name": "iobroker.shelly", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Shelly", | ||
@@ -34,3 +34,3 @@ "author": { | ||
"request": "^2.79.0", | ||
"shelly-iot": "^0.1.0" | ||
"shelly-iot": "^0.1.1" | ||
}, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
@@ -6,2 +6,4 @@ ![Logo](admin/shelly.png) | ||
[![Build Status](https://travis-ci.org/schmupu/ioBroker.shelly.svg?branch=master)](https://travis-ci.org/schmupu/ioBroker.shelly) | ||
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/schmupu/ioBroker.shelly?branch=master&svg=true)](https://ci.appveyor.com/project/schmupu/ioBroker-shelly/) | ||
[![NPM version](http://img.shields.io/npm/v/iobroker.shelly.svg)](https://www.npmjs.com/package/iobroker.shelly) | ||
@@ -39,2 +41,8 @@ [![Downloads](https://img.shields.io/npm/dm/iobroker.shelly.svg)](https://www.npmjs.com/package/iobroker.shelly) | ||
### 0.2.0 (28.09.2018) | ||
* Roller / Shutter for Shelly2 supported | ||
### 0.1.1 (21.09.2018) | ||
* Bugfixing | ||
### 0.1.0 (20.09.2018) | ||
@@ -41,0 +49,0 @@ * First Version. Supports all Shelly switches like Shelly 1, Shelly 2, Shelly 4 and the power sockets. |
259
shelly.js
@@ -23,2 +23,3 @@ /* jshint -W097 */ | ||
// is called when adapter shuts down - callback has to be called under any circumstances! | ||
@@ -65,4 +66,4 @@ adapter.on('unload', function(callback) { | ||
adapter.log.debug('stateChange ' + id + ' ' + JSON.stringify(state)); | ||
objectHelper.handleStateChange(id, state); | ||
objectHelper.handleStateChange(id, state); | ||
}); | ||
@@ -188,9 +189,22 @@ | ||
function isObject(item) { | ||
return (typeof item === "object" && !Array.isArray(item) && item !== null); | ||
} | ||
// create sensor | ||
function createSensorStates(deviceId, b, s, data) { | ||
let dp = datapoints.getSensor(s); | ||
if (dp) { | ||
let tmpId = b ? deviceId + '.' + b.D + '.' + dp.name : deviceId + '.' + dp.name; // Status ID in ioBroker | ||
let value = getStateBySenId(s.I, data); // Status for Sensor ID | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, s.I)] = tmpId; // remember the link Shelly ID -> ioBroker ID | ||
if (!sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, s.I)]) { | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, s.I)] = { | ||
id: tmpId, | ||
param: {}, | ||
value: value | ||
}; // remember the link Shelly ID -> ioBroker ID | ||
} | ||
// SHSW-44#06231A#1.Relay0.W -> State | ||
@@ -202,8 +216,87 @@ let controlFunction; | ||
controlFunction = function(value) { | ||
const params = { | ||
'turn': (value === true || value === 1) ? 'on' : 'off' | ||
}; | ||
let params; | ||
let timer = 0; | ||
if (sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'switchtimer' + s.I)] && | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'switchtimer' + s.I)].param) { | ||
timer = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'switchtimer' + s.I)].param.timer; | ||
} | ||
// if timer > 0 sec. call rest with timer paramater | ||
if (timer > 0) { | ||
params = { | ||
'turn': (value === true || value === 1) ? 'on' : 'off', | ||
'timer': timer | ||
}; | ||
} else { | ||
params = { | ||
'turn': (value === true || value === 1) ? 'on' : 'off' | ||
}; | ||
} | ||
adapter.log.debug("Relay: " + JSON.stringify(params)); | ||
shelly.callDevice(deviceId, '/relay/' + relayId, params); // send REST call to devices IP with the given path and parameters | ||
}; | ||
} | ||
if (b && b.D.startsWith('Relay') && s.T === 'SwitchTimer') { | ||
controlFunction = function(value) { | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, s.I)].param.timer = value || 0; | ||
}; | ||
} | ||
if (b && b.D.startsWith('Shutter') && s.T === 'ShutterUp') { | ||
controlFunction = function(value) { | ||
let params = {}; | ||
let duration = 0; | ||
if (sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')] && | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')].param) { | ||
duration = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')].param.duration; | ||
} | ||
if (duration > 0) { | ||
params = { | ||
'go': (value === true || value === 1) ? 'open' : 'stop', | ||
'duration': duration | ||
}; | ||
} else { | ||
params = { | ||
'go': (value === true || value === 1) ? 'open' : 'stop' | ||
}; | ||
} | ||
adapter.log.debug("RollerUp: " + JSON.stringify(params)); | ||
shelly.callDevice(deviceId, '/roller/0', params); | ||
}; | ||
} | ||
if (b && b.D.startsWith('Shutter') && s.T === 'ShutterDown') { | ||
controlFunction = function(value) { | ||
let params = {}; | ||
let duration = 0; | ||
if (sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')] && | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')].param) { | ||
duration = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, 'rollerduration')].param.duration; | ||
} | ||
if (duration > 0) { | ||
params = { | ||
'go': (value === true || value === 1) ? 'close' : 'stop', | ||
'duration': duration | ||
}; | ||
} else { | ||
params = { | ||
'go': (value === true || value === 1) ? 'close' : 'stop' | ||
}; | ||
} | ||
adapter.log.debug("RollerDown: " + JSON.stringify(params)); | ||
shelly.callDevice(deviceId, '/roller/0', params); | ||
}; | ||
} | ||
if (b && b.D.startsWith('Shutter') && s.T === 'ShutterStop') { | ||
controlFunction = function(value) { | ||
let params = { | ||
'go': 'stop' | ||
}; | ||
adapter.log.debug("RollerStop: " + JSON.stringify(params)); | ||
shelly.callDevice(deviceId, '/roller/0', params); | ||
}; | ||
} | ||
if (b && b.D.startsWith('Shutter') && s.T === 'ShutterDuration') { | ||
controlFunction = function(value) { | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, s.I)].param.duration = value || 0; | ||
}; | ||
} | ||
} | ||
@@ -241,3 +334,3 @@ if (dp.type === 'boolean') { | ||
} | ||
}); | ||
}, ['name']); | ||
adapter.log.debug('Create state object for ' + deviceId + '.online' + ' if not exist'); | ||
@@ -266,3 +359,3 @@ objectHelper.setOrUpdateObject(deviceId + '.online', { | ||
if (description && description) { | ||
if (description) { | ||
let blk = description.blk || []; | ||
@@ -275,2 +368,3 @@ // Loop over block | ||
let act = getActByBlkID(b.I, description.act); // Actions for this Block | ||
// Create Channel SHSW-44#06231A#1.Relay0 -> Channel | ||
@@ -283,5 +377,19 @@ objectHelper.setOrUpdateObject(deviceId + '.' + b.D, { | ||
}); | ||
// Loop over sensor for a block device | ||
sen.forEach(function(s) { | ||
createSensorStates(deviceId, b, s, data); | ||
// Create Timer for Switch | ||
if (b && b.D.startsWith('Relay') && s.T === 'Switch') { | ||
s = { | ||
'I': 'switchtimer' + s.I, | ||
'T': 'SwitchTimer', | ||
'D': 'Timer', | ||
'L': b.I | ||
}; | ||
createSensorStates(deviceId, b, s, data); | ||
} | ||
}); | ||
@@ -297,2 +405,49 @@ // loop over action for block device | ||
}); | ||
// for shelly2 the roller/shuter pseudo states will be added | ||
if (deviceId.startsWith('SHSW-2')) { | ||
let b, s; | ||
shelly.callDevice(deviceId, '/roller/0', (error,data) => { | ||
// let str = error && Buffer.isBuffer(error) ? error.toString('utf8') : error; | ||
if (!error && data) { | ||
b = { | ||
'I': 'roller', // Pseudo ID | ||
'D': 'Shutter' | ||
}; | ||
// Dummy Sensor for roller/shuter way up | ||
s = { | ||
'I': 'rollerup', //id | ||
'T': 'ShutterUp', | ||
'D': 'Shutter', | ||
'L': 'roller' // link to b.I | ||
}; | ||
createSensorStates(deviceId, b, s, data); | ||
// Dummy Sensor for roller/shuter way down | ||
s = { | ||
'I': 'rollerdown', | ||
'T': 'ShutterDown', | ||
'D': 'Shutter', | ||
'L': 'roller' | ||
}; | ||
createSensorStates(deviceId, b, s, data); | ||
// Stop shutter | ||
s = { | ||
'I': 'rollerstop', | ||
'T': 'ShutterStop', | ||
'D': 'Shutter', | ||
'L': 'roller' | ||
}; | ||
createSensorStates(deviceId, b, s, data); | ||
// duration, how long up and down is on | ||
s = { | ||
'I': 'rollerduration', | ||
'T': 'ShutterDuration', | ||
'D': 'Duration', | ||
'L': 'roller' | ||
}; | ||
createSensorStates(deviceId, b, s, data); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -312,2 +467,55 @@ } | ||
// update Shuter | ||
function updateShutter(deviceId) { | ||
let valRelay0, valRelay1, valSwitch, senSwitch, value; | ||
let valSwitchDown, senSwitchDown, valSwitchUp, senSwitchUp; | ||
for (let prop in sensorIoBrokerIDs) { | ||
if (prop.startsWith(deviceId)) { | ||
let ioBrokerId = sensorIoBrokerIDs[prop].id; // get ioBroker Id | ||
if (ioBrokerId.endsWith('Relay0.Switch')) { | ||
valRelay0 = sensorIoBrokerIDs[prop].value; | ||
} | ||
if (ioBrokerId.endsWith('Relay1.Switch')) { | ||
valRelay1 = sensorIoBrokerIDs[prop].value; | ||
} | ||
if (ioBrokerId.endsWith('Shutter.Close')) { | ||
valSwitchDown = sensorIoBrokerIDs[prop].value; | ||
senSwitchDown = sensorIoBrokerIDs[prop]; | ||
} | ||
if (ioBrokerId.endsWith('Shutter.Open')) { | ||
valSwitchUp = sensorIoBrokerIDs[prop].value; | ||
senSwitchUp = sensorIoBrokerIDs[prop]; | ||
} | ||
if (ioBrokerId.endsWith('Shutter.Pause')) { | ||
/* | ||
valSwitchUp = sensorIoBrokerIDs[prop].value; | ||
senSwitchUp = sensorIoBrokerIDs[prop]; | ||
valSwitchDown = sensorIoBrokerIDs[prop].value; | ||
senSwitchDown = sensorIoBrokerIDs[prop]; | ||
*/ | ||
} | ||
} | ||
} | ||
if (senSwitchUp && senSwitchDown) { | ||
value = (valRelay0 === true || valRelay0 === 1) ? true : false; | ||
if (value != valSwitchUp) { | ||
adapter.setState(senSwitchUp.id, { | ||
val: value, | ||
ack: true | ||
}); | ||
senSwitchUp.value = value; | ||
} | ||
value = (valRelay1 === true || valRelay1 === 1) ? true : false; | ||
if (value != valSwitchDown) { | ||
adapter.setState(senSwitchDown.id, { | ||
val: value, | ||
ack: true | ||
}); | ||
senSwitchDown.value = value; | ||
} | ||
} | ||
} | ||
// Update Status | ||
@@ -319,16 +527,27 @@ function updateDeviceStates(deviceId, data) { | ||
let value = dataObj[id]; | ||
let ioBrokerId = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, id)]; // get ioBroker Id | ||
const obj = objectHelper.getObject(ioBrokerId); | ||
if (ioBrokerId) { | ||
if ( | ||
obj.common && | ||
obj.common.type && | ||
obj.common.type === 'boolean' | ||
) { | ||
value = !!value; // convert to boolean | ||
if (sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, id)]) { | ||
let ioBrokerId = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, id)].id; // get ioBroker Id | ||
let oldValue = sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, id)].value; | ||
const obj = objectHelper.getObject(ioBrokerId); | ||
if (ioBrokerId) { | ||
if ( | ||
obj.common && | ||
obj.common.type && | ||
obj.common.type === 'boolean' | ||
) { | ||
value = !!value; // convert to boolean | ||
} | ||
if (value != oldValue) { | ||
adapter.setState(ioBrokerId, { | ||
val: value, | ||
ack: true | ||
}); | ||
sensorIoBrokerIDs[getIoBrokerIdfromDeviceIdSenId(deviceId, id)].value = value; | ||
// enter only if device == Shelly2 | ||
if (deviceId.startsWith('SHSW-2')) { | ||
// updateShutter(deviceId); | ||
} | ||
} | ||
} | ||
adapter.setState(ioBrokerId, { | ||
val: value, | ||
ack: true | ||
}); | ||
} | ||
@@ -335,0 +554,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
220209
1165
72
0
11
Updatedshelly-iot@^0.1.1