New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

apcupsd2mqtt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apcupsd2mqtt - npm Package Compare versions

Comparing version

to
1.0.0

18

index.js

@@ -20,3 +20,4 @@ const exec = require('child_process').exec;

const datapoints = ['upsname', 'serialno', 'status', 'linev', 'linefreq', 'loadpct', 'battv', 'bcharge'];
const datapoints = ['upsname', 'status', 'linev', 'linefreq', 'loadpct', 'battv', 'bcharge', 'timeleft'];
const numeric = ['linev', 'linefreq', 'loadpct', 'battv', 'bcharge', 'timeleft'];
const curvalues = {}; // Holds current values

@@ -58,11 +59,16 @@ let devicename = config.upsName;

value = value.replace(/(^\s+|\s+$)/g, '');
if (numeric.indexOf(label) !== -1) {
value = parseFloat(value.split(' ')[0]);
}
if (label === 'upsname') {
devicename = value;
}
// Check if value is known, if not store and publish value
if (curvalues[label] !== value) {
} else if (curvalues[label] !== value) {
curvalues[label] = value;
log.debug(value + ' changed!');
// Publish value
mqtt.publish(config.name + '/status/' + devicename + '/' + label, value, {retain: true});
const topic = config.name + '/status/' + devicename + '/' + label;
const payload = JSON.stringify({val: value});
log.debug('mqtt >', topic, payload);
mqtt.publish(topic, payload, {retain: true});
}

@@ -73,3 +79,3 @@ }

log.debug(curvalues);
setTimeout(poll, config.interval);
setTimeout(poll, config.interval * 1000);
});

@@ -76,0 +82,0 @@ }

{
"name": "apcupsd2mqtt",
"version": "0.0.1",
"version": "1.0.0",
"description": "Publish values from apcupsd to MQTT",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,2 +11,5 @@ # apcupsd2mqtt

This is a fork of https://github.com/cyberjunky/node-apcupsd - modified to follow
[mqtt-smarthome architectural proposal](https://mqtt-smarthome/mqtt-smarthome).
## Install

@@ -24,8 +27,6 @@

Copyright (c) 2017 Sebastian Raff
Copyright (c) 2017 Sebastian Raff
Copyright (c) 2014 Ron Klinkien
[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
[mit-url]: LICENSE