Skip to content

Commit

Permalink
Merge pull request #1 from Koenkk/master
Browse files Browse the repository at this point in the history
Update to latest
  • Loading branch information
kimonm authored Jul 30, 2018
2 parents 4994eee + 1816f83 commit 2e57c6d
Show file tree
Hide file tree
Showing 6 changed files with 766 additions and 101 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js

node_js:
- "8"
- '8'

install:
- npm install
Expand All @@ -12,9 +12,9 @@ script:

deploy:
provider: npm
email: "koenkanters94@gmail.com"
email: koenkanters94@gmail.com
api_key:
secure: GUsmI/vpO8Gk90AgDZim2kXG5ZPN9fAUhJ2VMP1czDyYEC4M7y/Eg4irWsdA1mLeGzdCNVetyXt2X5JOkb/xuCbfodVk6fZvbTxJiqwt+OAf0QlrWGEpAjfJfwRhiWY8EfdrUViEEvjIGfqmJRQlp+gRD/5bB+VRD5k5zbLoFEdcp9Cd4EH0L8EnldG64ZFtE8hMRX6J2YVlO9VK98yTlAq4l9vEFEjLI+cNrWK8h9X8auju7giRCNnOItWLHMN6rsnF0PBTx0XCy2BoaRBVAsFewHQUTjcs8AeFGATCtf+rbQwRFLSq65BGmApYzoR5wINHz/T2JocJrjH7Pgoj0sdmL5apl5T2jLIfIzmhF2A/N8oiuotFaltj7zqYYVr4gR0N26UJg0jQQQnnufbTGXIQvm8ov2FBZp3i6mor3vCZhEe6eGfOriG7KkTSMsQKAYkLnTMCibSPYk6moD49eDLzwEUU9FYx/hEl/iHvEIWj4CaWrLBFvykAbwgb83tmYNOnsBD5OzDfj4BEYe8ygkIISkxKtdfCFX/ItpN/bBKDL7sYrHzerHNCxzb8+sXV1ioHo5HbLQQCAtaCpooErCexG/ptmTVAe4v6c0Y6WIIo32QfudBaUyYHzIcGFYBJwOa0A3ECAJkNA18kkmGso0KtverqjbY6vaTgCeeyMBk=
secure: ZXg4VSeWGUtqjXJ8zOSUmf+ETyV12QTXY4FUEMxHVT9V70WMXCcKX4LhfrYHSMy7LkPnG5E2b1GGj36CdqjbNwBCThr1luzS0VXA1wzvr3qzCTgaRpMQWSWNl67ygSUJrZ2q4jJj0UhkpVMluXPepXARTfO3UjS9ILch4U3T0iJ4WHjZMbXJl0LXBYEgdvjLXnQ91nekwTr7HGdTWNvA6u3r+uibZS7Yxu6HFJaJJWqdqtchXUbHrDrXdB6tIWDCYOIYFS0/dzYRikZlE8tZLcLeZKtIMxnc5Y44ncxmvjd58a57/atN+TNfV39vfS4IXkobFhR/KAnTUELgkrqmx8Md0k7d0WbqRmuDqzkY5b9toP6fCfW1UFSPuAygDBJeuWV33GT79IuAHczuMP17siYOVEBXTydu2K2yQEabucQxMIRqh1sEQCq8h0JwX2GtKGytK8lTnmh+b7Jh5u6huIlw2JjTjwAXgKaDyJzwyIQmlxOmwvyM9cNuiQFBWqdHe+0KK9dMv6h5jL/G/gpesNEPJeNUlXre2XktYVyVyiaqoxEYiDUzPTlzOhYbcTGDeLLglVYTV/BUILGDgRHX/Ug8JRk/LLOXtfAGM+r8O+MFguuqHcWOmoYi19ctt8yLHicJB3TVIUOydMRDSLsGQ7/krhzUssZ6Hd8zW6l7RAk=
on:
tags: true
branch: master
180 changes: 171 additions & 9 deletions converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const clickLookup = {
};

const battery3V = {
min: 2800,
max: 3300,
min: 2700,
max: 3000,
};

const occupancyTimeout = 60; // In seconds
Expand All @@ -32,6 +32,16 @@ const precisionRound = (number, precision) => {
return Math.round(number * factor) / factor;
};

const numberWithinRange = (number, min, max) => {
if (number > max) {
return max;
} else if (number < min) {
return min;
} else {
return number;
}
};

// get object property name (key) by it's value
const getKey = (object, value) => {
for (let key in object) {
Expand Down Expand Up @@ -76,8 +86,24 @@ const ictcg1 = (model, msg, publish, options, action) => {
s.publish({brightness: s.value});
};

const holdUpdateBrightness324131092621 = (deviceID) => {
if (store[deviceID] && store[deviceID].since && store[deviceID].direction) {
const duration = Date.now() - store[deviceID].since;
const delta = (duration / 10) * (store[deviceID].direction === 'up' ? 1 : -1);
const newValue = store[deviceID].value + delta;
store[deviceID].value = numberWithinRange(newValue, 0, 255);
}
};


const converters = {
smartthings_contact: {
cid: 'ssIasZone',
type: 'statusChange',
convert: (model, msg, publish, options) => {
return {contact: msg.data.zoneStatus === 48};
},
},
xiaomi_battery_3v: {
cid: 'genBasic',
type: 'attReport',
Expand Down Expand Up @@ -226,7 +252,8 @@ const converters = {
convert: (model, msg, publish, options) => {
// The occupancy sensor only sends a message when motion detected.
// Therefore we need to publish the no_motion detected by ourselves.
const timeout = (options && options.occupancy_timeout) ? options.occupancy_timeout : occupancyTimeout;
const useOptionsTimeout = options && options.hasOwnProperty('occupancy_timeout');
const timeout = useOptionsTimeout ? options.occupancy_timeout : occupancyTimeout;
const deviceID = msg.endpoints[0].device.ieeeAddr;

// Stop existing timer because motion is detected and set a new one.
Expand All @@ -235,10 +262,13 @@ const converters = {
store[deviceID] = null;
}

store[deviceID] = setTimeout(() => {
publish({occupancy: false});
store[deviceID] = null;
}, timeout * 1000);
if (timeout !== 0) {
store[deviceID] = setTimeout(() => {
publish({occupancy: false});
store[deviceID] = null;
}, timeout * 1000);
}

return {occupancy: true};
},
},
Expand All @@ -249,6 +279,13 @@ const converters = {
return {contact: msg.data.data['onOff'] === 0};
},
},
light_state: {
cid: 'genOnOff',
type: 'devChange',
convert: (model, msg, publish, options) => {
return {state: msg.data.data['onOff'] === 1 ? 'ON' : 'OFF'};
},
},
light_brightness: {
cid: 'genLevelCtrl',
type: 'devChange',
Expand Down Expand Up @@ -371,7 +408,35 @@ const converters = {
}
},
},
QBKG04LM_state: {
QBKG11LM_power: {
cid: 'genBasic',
type: 'attReport',
convert: (model, msg, publish, options) => {
if (msg.data.data['65281']) {
const data = msg.data.data['65281'];
return {
power: precisionRound(data['152'], 2),
consumption: precisionRound(data['149'], 2),
temperature: precisionRound(data['3'], 2),
};
}
},
},
QBKG12LM_power: {
cid: 'genBasic',
type: 'attReport',
convert: (model, msg, publish, options) => {
if (msg.data.data['65281']) {
const data = msg.data.data['65281'];
return {
power: precisionRound(data['152'], 2),
consumption: precisionRound(data['149'], 2),
temperature: precisionRound(data['3'], 2),
};
}
},
},
QBKG04LM_QBKG11LM_state: {
cid: 'genOnOff',
type: 'attReport',
convert: (model, msg, publish, options) => {
Expand All @@ -380,7 +445,7 @@ const converters = {
}
},
},
QBKG03LM_state: {
QBKG03LM_QBKG12LM_state: {
cid: 'genOnOff',
type: 'attReport',
convert: (model, msg, publish, options) => {
Expand Down Expand Up @@ -438,6 +503,83 @@ const converters = {
};
},
},
Z809A_power: {
cid: 'haElectricalMeasurement',
type: 'attReport',
convert: (model, msg, publish, options) => {
return {
power: msg.data.data['activePower'],
current: msg.data.data['rmsCurrent'],
voltage: msg.data.data['rmsVoltage'],
power_factor: msg.data.data['powerFactor'],
};
},
},
_324131092621_on: {
cid: 'genOnOff',
type: 'cmdOn',
convert: (model, msg, publish, options) => {
return {action: 'on'};
},
},
_324131092621_off: {
cid: 'genOnOff',
type: 'cmdOffWithEffect',
convert: (model, msg, publish, options) => {
return {action: 'off'};
},
},
_324131092621_step: {
cid: 'genLevelCtrl',
type: 'cmdStep',
convert: (model, msg, publish, options) => {
const deviceID = msg.endpoints[0].device.ieeeAddr;
const direction = msg.data.data.stepmode === 0 ? 'up' : 'down';
const mode = msg.data.data.stepsize === 30 ? 'press' : 'hold';

// Initialize store
if (!store[deviceID]) {
store[deviceID] = {value: 255, since: null, direction: null};
}

if (mode === 'press') {
const newValue = store[deviceID].value + (direction === 'up' ? 50 : -50);
store[deviceID].value = numberWithinRange(newValue, 0, 255);
} else if (mode === 'hold') {
holdUpdateBrightness324131092621(deviceID);
store[deviceID].since = Date.now();
store[deviceID].direction = direction;
}

return {action: `${direction}-${mode}`, brightness: store[deviceID].value};
},
},
_324131092621_stop: {
cid: 'genLevelCtrl',
type: 'cmdStop',
convert: (model, msg, publish, options) => {
const deviceID = msg.endpoints[0].device.ieeeAddr;

if (store[deviceID]) {
holdUpdateBrightness324131092621(deviceID);
const payload = {
brightness: store[deviceID].value,
action: `${store[deviceID].direction}-hold-release`,
};

store[deviceID].since = null;
store[deviceID].direction = null;
return payload;
}
},
},
_324131092621_power: {
cid: 'genPowerCfg',
type: 'attReport',
convert: (model, msg, publish, options) => {
return {battery: precisionRound(msg.data.data['batteryPercentageRemaining'], 2) / 2};
},
},
ICTC_G_1_move: {
cmd: 'move',
convert: (model, msg, publish, options) => ictcg1(model, msg, publish, options, 'move'),
Expand Down Expand Up @@ -500,16 +642,36 @@ const converters = {
type: 'devChange',
convert: (model, msg, publish, options) => null,
},
ignore_analog_report: {
cid: 'genAnalogInput',
type: 'attReport',
convert: (model, msg, publish, options) => null,
},
ignore_multistate_report: {
cid: 'genMultistateInput',
type: 'attReport',
convert: (model, msg, publish, options) => null,
},
ignore_multistate_change: {
cid: 'genMultistateInput',
type: 'devChange',
convert: (model, msg, publish, options) => null,
},
ignore_power_change: {
cid: 'genPowerCfg',
type: 'devChange',
convert: (model, msg, publish, options) => null,
},
ignore_metering_change: {
cid: 'seMetering',
type: 'devChange',
convert: (model, msg, publish, options) => null,
},
ignore_electrical_change: {
cid: 'haElectricalMeasurement',
type: 'devChange',
convert: (model, msg, publish, options) => null,
},
ignore_cmd_readRsp: {
cmd: 'readRsp',
convert: (model, msg, publish, options) => null,
Expand Down
11 changes: 11 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
'use strict';

const converters = {
factory_reset: {
key: 'reset',
attr: [],
convert: (value, message) => {
return {
cid: 'genBasic',
cmd: 'resetFactDefault',
zclData: {},
};
},
},
onoff: {
key: 'state',
attr: ['onOff'],
Expand Down
Loading

0 comments on commit 2e57c6d

Please sign in to comment.