Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

homebridge-delay-switch

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-delay-switch - npm Package Compare versions

Comparing version 3.2.4 to 3.2.5

.eslintrc.json

250

index.js

@@ -1,7 +0,7 @@

var Service, Characteristic;
var Service, Characteristic
module.exports = function (homebridge) {
Service = homebridge.hap.Service;
Characteristic = homebridge.hap.Characteristic;
homebridge.registerAccessory("homebridge-delay-switch", "DelaySwitch", delaySwitch);
Service = homebridge.hap.Service
Characteristic = homebridge.hap.Characteristic
homebridge.registerAccessory('homebridge-delay-switch', 'DelaySwitch', delaySwitch)
}

@@ -11,109 +11,109 @@

function delaySwitch(log, config, api) {
let UUIDGen = api.hap.uuid;
let UUIDGen = api.hap.uuid
this.log = log;
this.name = config['name'];
this.delay = config['delay'] || 0;
this.delayUnit = config['delayUnit'] || "ms";
this.debug = config.debug || false
this.sensorType = config['sensorType'];
if (typeof this.sensorType === 'undefined')
this.sensorType = 'motion'
this.flipSensor = config['flipSensorState'];
this.disableSensor = config['disableSensor'] || !config['sensorType'] || this.delay === 0;
this.startOnReboot = config['startOnReboot'] || false;
this.switchOn = false;
this.sensorTriggered = 0;
this.uuid = UUIDGen.generate(this.name)
this.log = log
this.name = config['name']
this.delay = config['delay'] || 0
this.delayUnit = config['delayUnit'] || 'ms'
this.debug = config.debug || false
this.sensorType = config['sensorType']
if (typeof this.sensorType === 'undefined')
this.sensorType = 'motion'
this.flipSensor = config['flipSensorState']
this.disableSensor = config['disableSensor'] || !config['sensorType'] || this.delay === 0
this.startOnReboot = config['startOnReboot'] || false
this.switchOn = false
this.sensorTriggered = 0
this.uuid = UUIDGen.generate(this.name)
switch (this.delayUnit) {
case 's':
this.delayTime = this.delay * 1000;
break;
case 'm':
this.delayTime = this.delay * 60 * 1000;
break;
case 'h':
this.delayTime = this.delay * 60 * 60 * 1000;
break;
case 'd':
this.delayTime = this.delay * 24 * 60 * 60 * 1000;
break;
default:
this.delayTime = this.delay;
break;
}
switch (this.delayUnit) {
case 's':
this.delayTime = this.delay * 1000
break
case 'm':
this.delayTime = this.delay * 60 * 1000
break
case 'h':
this.delayTime = this.delay * 60 * 60 * 1000
break
case 'd':
this.delayTime = this.delay * 24 * 60 * 60 * 1000
break
default:
this.delayTime = this.delay
break
}
// define debug method to output debug logs when enabled in the config
this.log.easyDebug = (...content) => {
if (this.debug) {
this.log(content.reduce((previous, current) => {
return previous + ' ' + current
}))
} else
this.log.debug(content.reduce((previous, current) => {
return previous + ' ' + current
}))
}
// define debug method to output debug logs when enabled in the config
this.log.easyDebug = (...content) => {
if (this.debug) {
this.log(content.reduce((previous, current) => {
return previous + ' ' + current
}))
} else
this.log.debug(content.reduce((previous, current) => {
return previous + ' ' + current
}))
}
this.getSensorState = () => {
state = this.sensorTriggered
if (this.flipSensor && this.sensorType === 'motion')
return !state
if (this.sensorType === 'motion')
return !!state
if (this.flipSensor)
return state ^ 1
return state
}
this.getSensorState = () => {
const state = this.sensorTriggered
if (this.flipSensor && this.sensorType === 'motion')
return !state
if (this.sensorType === 'motion')
return !!state
if (this.flipSensor)
return state ^ 1
return state
}
}
delaySwitch.prototype.getServices = function () {
var informationService = new Service.AccessoryInformation();
var informationService = new Service.AccessoryInformation()
informationService
.setCharacteristic(Characteristic.Manufacturer, "Delay Switch")
.setCharacteristic(Characteristic.Model, `Delay-${this.delay}${this.delayUnit}`)
.setCharacteristic(Characteristic.SerialNumber, this.uuid);
informationService
.setCharacteristic(Characteristic.Manufacturer, 'Delay Switch')
.setCharacteristic(Characteristic.Model, `Delay-${this.delay}${this.delayUnit}`)
.setCharacteristic(Characteristic.SerialNumber, this.uuid)
this.switchService = new Service.Switch(this.name);
this.switchService.getCharacteristic(Characteristic.On)
.on('get', this.getOn.bind(this))
.on('set', this.setOn.bind(this))
.updateValue(this.startOnReboot)
this.switchService = new Service.Switch(this.name)
this.switchService.getCharacteristic(Characteristic.On)
.on('get', this.getOn.bind(this))
.on('set', this.setOn.bind(this))
.updateValue(this.startOnReboot)
var services = [informationService, this.switchService]
var services = [informationService, this.switchService]
if (!this.disableSensor) {
switch (this.sensorType) {
case 'contact':
this.sensorService = new Service.ContactSensor(this.name + ' Trigger');
this.sensorCharacteristic = Characteristic.ContactSensorState
break;
case 'occupancy':
this.sensorService = new Service.OccupancySensor(this.name + ' Trigger');
this.sensorCharacteristic = Characteristic.OccupancyDetected
break;
case 'leak':
this.sensorService = new Service.LeakSensor(this.name + ' Trigger');
this.sensorCharacteristic = Characteristic.LeakDetected
break;
default:
this.sensorService = new Service.MotionSensor(this.name + ' Trigger');
this.sensorCharacteristic = Characteristic.MotionDetected
break;
}
if (!this.disableSensor) {
switch (this.sensorType) {
case 'contact':
this.sensorService = new Service.ContactSensor(this.name + ' Trigger')
this.sensorCharacteristic = Characteristic.ContactSensorState
break
case 'occupancy':
this.sensorService = new Service.OccupancySensor(this.name + ' Trigger')
this.sensorCharacteristic = Characteristic.OccupancyDetected
break
case 'leak':
this.sensorService = new Service.LeakSensor(this.name + ' Trigger')
this.sensorCharacteristic = Characteristic.LeakDetected
break
default:
this.sensorService = new Service.MotionSensor(this.name + ' Trigger')
this.sensorCharacteristic = Characteristic.MotionDetected
break
}
this.sensorService
.getCharacteristic(this.sensorCharacteristic)
.on('get', (callback) => {
callback(null, this.getSensorState())
});
this.sensorService
.getCharacteristic(this.sensorCharacteristic)
.on('get', (callback) => {
callback(null, this.getSensorState())
})
services.push(this.sensorService)
}
services.push(this.sensorService)
}
return services;
return services

@@ -124,37 +124,37 @@ }

if (value === false) {
this.log.easyDebug('Stopping the Timer');
this.switchOn = false;
clearTimeout(this.timer);
this.sensorTriggered = 0;
if (!this.disableSensor)
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
} else if (value === true) {
this.switchOn = true;
clearTimeout(this.timer);
if (this.delay > 0) {
this.log.easyDebug('Starting the Timer');
this.timer = setTimeout(function () {
this.log.easyDebug('Time is Up!');
this.switchService.getCharacteristic(Characteristic.On).updateValue(false);
this.switchOn = false;
if (value === false) {
this.log.easyDebug('Stopping the Timer')
this.switchOn = false
clearTimeout(this.timer)
this.sensorTriggered = 0
if (!this.disableSensor)
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState())
} else if (value === true) {
this.switchOn = true
clearTimeout(this.timer)
if (this.delay > 0) {
this.log.easyDebug('Starting the Timer')
this.timer = setTimeout(function () {
this.log.easyDebug('Time is Up!')
this.switchService.getCharacteristic(Characteristic.On).updateValue(false)
this.switchOn = false
if (!this.disableSensor) {
this.sensorTriggered = 1;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
this.log.easyDebug('Triggering Sensor');
setTimeout(function () {
this.sensorTriggered = 0;
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState());
}.bind(this), 3000);
}
if (!this.disableSensor) {
this.sensorTriggered = 1
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState())
this.log.easyDebug('Triggering Sensor')
setTimeout(function () {
this.sensorTriggered = 0
this.sensorService.getCharacteristic(this.sensorCharacteristic).updateValue(this.getSensorState())
}.bind(this), 3000)
}
}.bind(this), this.delayTime);
}
}
callback();
}.bind(this), this.delayTime)
}
}
callback()
}
delaySwitch.prototype.getOn = function (callback) {
callback(null, this.switchOn);
callback(null, this.switchOn)
}
{
"name": "homebridge-delay-switch",
"version": "3.2.4",
"version": "3.2.5",
"description": "Delay switches for Homebridge",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -1,2 +0,2 @@

<img src="branding/delayswitch_homebridge.png" width="500px">
<img alt="logo" src="branding/delayswitch_homebridge.png" width="500px">

@@ -6,4 +6,5 @@ # Homebridge-Delay-Switch

[![Downloads](https://img.shields.io/npm/dt/homebridge-delay-switch.svg?color=critical)](https://www.npmjs.com/package/homebridge-delay-switch)
[![Version](https://img.shields.io/npm/v/homebridge-delay-switch)](https://www.npmjs.com/package/homebridge-delay-switch)<br>
[![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins) [![Homebridge Discord](https://img.shields.io/discord/432663330281226270?color=728ED5&logo=discord&label=discord)](https://discord.gg/HWUKH9C)<br>
[![Version](https://img.shields.io/npm/v/homebridge-delay-switch)](https://www.npmjs.com/package/homebridge-delay-switch)
[![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins) [![Homebridge Discord](https://img.shields.io/discord/432663330281226270?color=728ED5&logo=discord&label=discord)](https://discord.gg/HWUKH9C)
[![certified-hoobs-plugin](https://badgen.net/badge/HOOBS/Certified/yellow)](https://plugins.hoobs.org?ref=10876) [![hoobs-support](https://badgen.net/badge/HOOBS/Support/yellow)](https://support.hoobs.org?ref=10876)

@@ -19,7 +20,7 @@

* ```sudo npm install -g homebridge-delay-switch```
* ```sudo npm install -g homebridge-delay-switch```
* Create an accessory in your config.json file
* Restart homebridge
## Example config.json:
## Example config.json

@@ -51,3 +52,2 @@ ```

## Why do we need this Plugin?

@@ -62,3 +62,2 @@

## How it Works

@@ -92,4 +91,4 @@

<a target="blank" href="https://www.paypal.me/nitaybz"><img src="https://img.shields.io/badge/PayPal-Donate-blue.svg?logo=paypal"/></a><br>
<a target="blank" href="https://www.patreon.com/nitaybz"><img src="https://img.shields.io/badge/PATREON-Become a patron-red.svg?logo=patreon"/></a><br>
<a target="blank" href="https://ko-fi.com/nitaybz"><img src="https://img.shields.io/badge/Ko--Fi-Buy%20me%20a%20coffee-29abe0.svg?logo=ko-fi"/></a>
[![PayPal](https://img.shields.io/badge/PayPal-Donate-blue.svg?logo=paypal)](https://www.paypal.me/nitaybz)
[![Patreon](https://img.shields.io/badge/PATREON-Become%20a%20Patreon-red.svg?logo=patreon)](https://www.patreon.com/nitaybz)
[![Ko-Fi](https://img.shields.io/badge/Ko--Fi-Buy%20me%20a%20coffee-29abe0.svg?logo=ko-fi)](https://ko-fi.com/nitaybz)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc