Skip to content

Commit

Permalink
Support battery level. Koenkk#3
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Apr 14, 2018
1 parent 5c1beec commit f5c0d08
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
56 changes: 16 additions & 40 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"mqtt": "*",
"zigbee-shepherd": "*",
"zcl-packet": "git+https://github.com/koenkk/zcl-packet.git",
"yaml-config": "*"
}
}
29 changes: 27 additions & 2 deletions parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@ const clickLookup = {
4: 'quadruple',
}

const battery = {
min: 2500,
max: 3000,
}

const toPercentage = (value, min, max) => {
if (value > max) {
value = max;
} else if (value < min) {
value = min;
}

const normalised = (value - min) / (max - min);
return (normalised * 100).toFixed(2);
}

// Global variable store that can be used by devices.
const store = {}

const parsers = [
{
devices: ['WXKG01LM'],
cid: 'genBasic',
topic: 'battery',
parse: (msg, publish) => {
if (msg.data.data['65282']) {
const voltage = msg.data.data['65282']['1'].elmVal;
return voltage ? toPercentage(voltage, battery.min, battery.max) : null;
}
}
},
{
devices: ['WXKG01LM'],
cid: 'genOnOff',
Expand Down Expand Up @@ -36,8 +63,6 @@ const parsers = [
publish('many');
}
}

return null;
}
},
{
Expand Down

0 comments on commit f5c0d08

Please sign in to comment.