Socket
Socket
Sign inDemoInstall

homebridge-multiswitcheroo

Package Overview
Dependencies
15
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.0.2

5

CHANGELOG.md

@@ -17,2 +17,7 @@ # Changelog

# Changelog
## [3.0.2] - 2023-09-06
### Fixed
- Added check for valid config before creating switches.
## [3.0.1] - 2023-08-23

@@ -19,0 +24,0 @@ ### Fixed

43

index.js

@@ -31,3 +31,2 @@ const axios = require('axios');

if (this.config.statusUrl) {
//this.log.debug(`Emitter calling URL`);
axios.get(this.config.statusUrl, { rejectUnauthorized: false })

@@ -46,4 +45,2 @@ .then((response) => done(null, response.data))

statusemitter.on('poll', (data) => {
//this.log.debug(`Parsing URL data`);
//this.log.debug(`Received status data:`, data);
const statusData = JSON.stringify(data);

@@ -55,6 +52,2 @@ for (const switchService of this.switches) {

switchService.getCharacteristic(Characteristic.On).updateValue(isOn);
//if (!isOn && switchService.getCharacteristic(Characteristic.On).value) {
//this.log.warn(`$(switchConfig.name) is off in the Home app, but should be on bsed on server respone.`);
//switchService.getCharacteristic(Characteristic.On).setValue(true);
//}
}

@@ -68,13 +61,17 @@ }

for (const switchConfig of config.switches) {
const switchName = switchConfig.name;
const switchService = new Service.Switch(switchName, switchName);
switchService.switchConfig = switchConfig; // Attach switchConfig to the service
switchService
.getCharacteristic(Characteristic.On)
.on('set', (on, callback) => { this.setOn(on, callback, switchConfig); })
.on('get', (callback) => { this.getOn(callback, switchConfig); });
if (!Array.isArray(config.switches)) { //check for a valid array of switches before trying to create them
this.log.error('MultiSwitcheroo switches array is not properly defined. Please define switches in the config & restart, or disable the plugin.');
} else {
for (const switchConfig of config.switches) {
const switchName = switchConfig.name;
const switchService = new Service.Switch(switchName, switchName);
switchService.switchConfig = switchConfig; // Attach switchConfig to the service
switchService
.getCharacteristic(Characteristic.On)
.on('set', (on, callback) => { this.setOn(on, callback, switchConfig); })
.on('get', (callback) => { this.getOn(callback, switchConfig); });
this.switches.push(switchService);
this.log.info(`Switch created: ${switchConfig.name}`);
this.switches.push(switchService);
this.log.info(`Switch created: ${switchConfig.name}`);
}
}

@@ -93,7 +90,5 @@

setOn(on, callback, switchConfig) {
//this.log.debug(`setOn calling URL`);
axios.get(on ? switchConfig.onUrl : switchConfig.offUrl, { rejectUnauthorized: false })
.then((response) => {
if (response.status === 200) {
//this.log.debug(`${switchConfig.name} toggled successfully ${response.status}`);
callback(null);

@@ -112,4 +107,2 @@ } else {

getOn(callback, switchConfig) {
//this.log.debug(`getOn URL Rec'd: ${this.config.statusUrl}`);
//this.log.debug(`getOn Pattern Rec'd: ${switchConfig.statusPattern}`);

@@ -121,14 +114,10 @@ if (!this.config.statusUrl || !switchConfig.statusPattern) {

//this.log.debug(`getOn statusPattern: ${switchConfig.statusPattern}`);
//this.log.debug(`getOn calling URL`);
axios.get(this.config.statusUrl, { rejectUnauthorized: false })
.then((response) => {
if (response.status === 200) {
//this.log.debug(`getOn Response Data:`, response.data);
const statusData = JSON.stringify(response.data); // Parse the response data
const isOn = !!statusData.match(switchConfig.statusPattern);
//this.log.debug(`getOn Status URL: ${this.config.statusUrl}`);
//this.log.debug(`getOn switchConfig Pattern: ${switchConfig.statusPattern}`);

@@ -135,0 +124,0 @@ callback(null, isOn);

{
"name": "homebridge-multiswitcheroo",
"displayName": "MultiSwitcheroo",
"version": "3.0.1",
"version": "3.0.2",
"author": "iSteve-O",

@@ -6,0 +6,0 @@ "description": "User defined switches for http GET requests. Simple on/off or multiswitch on/off. Useful for lights, A/V systems, home automation, and includes live status polling!",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc