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

homebridge-bigAssFans

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

homebridge-bigAssFans - npm Package Compare versions

Comparing version 0.0.3 to 1.0.0

109

index.js
var bigAssApi = require("BigAssFansAPI");
bigAssApi.logging = true;

@@ -13,16 +14,27 @@ var Service, Characteristic;

function BigAssFanAccessory(log, config) {
this.log = log;
this.name = config["name"];
this.fanName = config["fan_name"];
this.fanID = config["fan_id"];
this.fanIPAddress = config["fan_ip_address"]; // Can be null - resorts to broadcasting
this.lightOn = config["light_on"]; // Can be null - default is belo
this.fanOn = config["fan_on"]; // Can be null - default is below
this.log = log;
this.name = config["name"];
this.fanName = config["fan_name"]; // TODO: Allow this to be null
this.fanID = config["fan_id"];
this.fanIPAddress = config["fan_ip_address"]; // Can be null - resorts to broadcasting
this.lightOn = config["light_on"]; // Can be null - default is below
this.fanOn = config["fan_on"]; // Can be null - default is below
this.homekitFanName = config["homekit_fan_name"]
this.homekitLightName = config["homekit_light_name"]
// Set defaults
this.fanIPAddress = this.fanIPAddress ? this.fanIPAddress : "255.255.255.255";
this.lightOn = this.lightOn ? this.lightOn : 16;
this.fanOn = this.fanOn ? this.fanOn : 3;
var setDefault = function(property, value) {
if (!this[property]) {this[property] = value}
}.bind(this);
setDefault("fanIPAddress", "255.255.255.255");
setDefault("lightOn", 16);
setDefault("fanOn", 3);
setDefault("name", this.fanName);
setDefault("homekitFanName", this.name);
setDefault("homekitLightName", this.name);
// Don't scan for any fans since we know the exact address of the fan (faster!)
// TODO: Make fan_id optional and do the scan for the user
this.fanMaster = new bigAssApi.FanMaster(0);

@@ -42,9 +54,22 @@

var serviceWithCharacteristic = service.getCharacteristic(characteristic)
var thisChar = service.getCharacteristic(characteristic)
if (getOutputMapping) {
serviceWithCharacteristic.on('get', this.getStateFactory(propertyToWrap, subProperty, getOutputMapping).bind(this));
thisChar.on('get', this.getStateFactory(propertyToWrap,
subProperty,
getOutputMapping).bind(this));
// Register for updates outside of the homekit system
this.myBigAss[propertyToWrap].registerUpdateCallback(subProperty, function(newValue) {
service.setCharacteristic(characteristic, getOutputMapping(newValue));
if (thisChar.emit) {
// Emit this change to the homekit system
// oldValue : Grabs the old cached value for this characterisitic
// newValue : The value we just recieved
// context : Gives context so that whoever requested the update doesn't recieve it.
// In this case we need everyone to get the update
thisChar.emit('change', {
oldValue:thisChar.value,
newValue:getOutputMapping(newValue),
context:null });
}
});

@@ -54,3 +79,5 @@ }

if (setOutputMapping) {
serviceWithCharacteristic.on('set', this.setStateFactory(propertyToWrap, subProperty, setOutputMapping).bind(this));
thisChar.on('set', this.setStateFactory(propertyToWrap,
subProperty,
setOutputMapping).bind(this));
}

@@ -69,2 +96,16 @@

var setScalingWrapper = function(maxValue) {
return function(value) {
var retVal = Math.round(value * maxValue / 100);
console.log("Value in: "+value + "value out: " + retVal);
return retVal
}
}
var getScalingWrapper = function(maxValue) {
return function(value) {
return Math.round(value * 100 / maxValue);
}
}
var boolGetWrapper = function(value) {

@@ -75,2 +116,7 @@ return value > 0;

var lightSetWrapper = function(value) {
// We define that returning null will ignore the command
// For some reason homekit likes to send extraneous "On" commands
if (value && this.myBigAss.light.brightness > 0) {
return null;
}
return (value ? this.lightOn : 0);

@@ -80,2 +126,7 @@ }.bind(this)

var fanSetWrapper = function(value) {
// We define that returning null will ignore the command
// For some reason homekit likes to send extraneous "On" commands
if (value && this.myBigAss.fan.speed > 0) {
return null;
}
return (value ? this.fanOn : 0);

@@ -85,7 +136,7 @@ }.bind(this)

var fanRotationSetWrapper = function(value) {
return (value == Characteristic.RotationDirection.CLOCKWISE ? true : false);
return value == Characteristic.RotationDirection.COUNTER_CLOCKWISE;
}
var fanRotationGetWrapper = function(value) {
return (value ? Characteristic.RotationDirection.CLOCKWISE : Characteristic.RotationDirection.COUNTER_CLOCKWISE);
return (value ? Characteristic.RotationDirection.COUNTER_CLOCKWISE : Characteristic.RotationDirection.CLOCKWISE);
}

@@ -97,4 +148,7 @@

this.lightService = new Service.Lightbulb(this.name);
var lightMaxBrightness = this.myBigAss.light.max ? this.myBigAss.light.max : 16;
var fanMaxSpeed = this.myBigAss.fan.max ? this.myBigAss.fan.max : 7;
this.lightService = new Service.Lightbulb(this.homekitLightName);
setCharacteristicOnService(this.lightService, Characteristic.On,

@@ -106,5 +160,5 @@ "light", "brightness",

"light", "brightness",
passThroughWrapper, passThroughWrapper)
getScalingWrapper(lightMaxBrightness), setScalingWrapper(lightMaxBrightness))
this.fanService = new Service.Fan(this.name);
this.fanService = new Service.Fan(this.homekitFanName);

@@ -121,3 +175,3 @@ setCharacteristicOnService(this.fanService, Characteristic.On,

"fan", "speed",
passThroughWrapper, passThroughWrapper)
getScalingWrapper(fanMaxSpeed), setScalingWrapper(fanMaxSpeed))

@@ -138,3 +192,4 @@ // this.occupancyService = new Service.OccupancySensor(this.name);

this.myBigAss[propertyToWrap].update(subProperty, function(err, value) {
callback(err, outputMapping(value));
var returnVal = outputMapping(value);
callback(err, returnVal);
});

@@ -146,7 +201,13 @@ }

return function(state, callback) {
this.myBigAss[propertyToWrap].setProperty(subProperty, outputMapping(state), function(err) {
callback(err);
});
var valToSet = outputMapping(state)
if (valToSet != null) {
this.myBigAss[propertyToWrap].setProperty(subProperty, valToSet, function(err) {
callback(err);
});
} else {
// If null is returned, ignore the command
callback(null);
}
}
}
{
"name": "homebridge-bigAssFans",
"version": "0.0.3",
"version": "1.0.0",
"description": "A Homebridge plugin for Big Ass Fans",

@@ -21,3 +21,6 @@ "main": "index.js",

},
"dependencies": {
"BigAssFansAPI": ">=1.1.0"
},
"homepage": "https://github.com/sean9keenan/homebridge-bigAssFans"
}

@@ -21,2 +21,5 @@ Homekit

In order to get the fan_id, run the example program [getFanInfo.js from theBigAssFansAPI](https://github.com/sean9keenan/BigAssFansAPI/blob/master/Examples/getFanInfo.js).
You must also set the fan_name to the name returned here.
Install this package with

@@ -27,4 +30,21 @@ ```

### About the config
| Field | Required? | Description |
|--------------------|--------------|------------------------------------------|
| name | Optional | Overall Name to use for this accessory |
| fan_name | _*Required*_ | Must get this from `getFanInfo.js` |
| fan_id | _*Required*_ | Must get this from `getFanInfo.js` |
| fan_ip_address | Optional | IP address of fan, defaults to broadcast |
| light_on | Optional | What "On" means - default Max |
| fan_on | Optional | What "On" means - default 3/7 |
| homekit_fan_name | Optional | Name to call the Fan in Homekit |
| homekit_light_name | Optional | Name to call the Light in Homekit |
Important note
--------------
All of the smarts in your fan will continue to operate - eg. If you set homekit and your fan's local settings set to turn the light on when occupancy is sensed, and then decide to turn it off via homekit the local settings will _still_ turn the light on
All of the smarts in your fan will continue to operate - eg. If you set homekit and your fan's local settings set to turn the light on when occupancy is sensed, and then decide to turn it off via homekit the local settings will _still_ turn the light on
Future features
---------------
- Not having to specify fan_name and fan_id.
- Getting motion sensors to work
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