Skip to content

Commit

Permalink
Merge pull request #20 from chrisjshull/features
Browse files Browse the repository at this point in the history
 make it possible to hide certain switches #16
  • Loading branch information
chrisjshull committed Mar 11, 2018
2 parents 91605f6 + d46ea6d commit e018072
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 22 deletions.
13 changes: 7 additions & 6 deletions README.md
Expand Up @@ -22,7 +22,7 @@ _Note: The name of the device matches the name displayed in the Nest app. In my
4. Fill in you info in 'Step 1'
5. In 'Step 2' set:
* **Company Name**: _HomeBridge-Nest_
* **Company URL**: _https://github.com/kraigm/homebridge-nest_
* **Company URL**: _https://github.com/chrisjshull/homebridge-nest_
* **Country**: _[Your Country]_
* **Size of Company**: _Individual_
6. Then just agree to the terms and submit
Expand All @@ -32,13 +32,13 @@ _Note: The name of the device matches the name displayed in the Nest app. In my
* **Description**: _Open source project to provide HomeKit integration_
* **Categories**: _Home Automation_
* **Users**: _Individual_
* **Support URL**: _https://github.com/kraigm/homebridge-nest_
* **Support URL**: _https://github.com/chrisjshull/homebridge-nest_
* **Redirect URL**: _[LEAVE BLANK]_
* **Permissions (minimum)**:
* Enable **Thermostat** with **read/write v4**
* Enable **Away** with **read/write v2**
* Enable **Smoke+CO alarm** with **read v4** (if you ever might want Nest Protect)
* Enable **Camera** with **read v2** (if you ever might want Nest Cam, motion detection only)
* Enable **Thermostat** with **read/write**
* Enable **Away** with **read/write**
* Enable **Smoke+CO alarm** with **read** (if you ever might want Nest Protect)
* Enable **Camera** with **read** (if you ever might want Nest Cam, motion detection only)
* Permission description: fill in anything
9. Now you should have a product. Now locate the id/secret section on the right of your product's page
10. Copy the **Product ID** to your HomeBridge config as the **clientId** in the Nest config
Expand Down Expand Up @@ -77,3 +77,4 @@ Fields:
* "code": your Pincode from Nest (see instructions)
* "token": The only (and final) authentication piece you need to use the new API (see instructions)
* "structureId": "your structure's ID" // optional structureId to filter to (see logs on first run for each device's structureId)
* "disable": [] // optional list of features to disable ("Thermostat.Fan", "Thermostat.Home", "Thermostat.Eco")
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -207,6 +207,9 @@ const setupConnection = function(config, log) {
};

NestPlatform.prototype = {
shouldEnableFeature: function (key) {
return !this.config.disable || !this.config.disable.includes(key);
},
accessories: function (callback) {
this.log("Fetching Nest devices.");

Expand All @@ -225,8 +228,8 @@ NestPlatform.prototype = {
continue;
}
const structure = data.structures[structureId];
const accessory = new DeviceType(this.conn, this.log, device, structure);
that.accessoryLookup[deviceId] = accessory;
const accessory = new DeviceType(this.conn, this.log, device, structure, this);
this.accessoryLookup[deviceId] = accessory;
foundAccessories.push(accessory);
}
}.bind(this);
Expand Down
4 changes: 2 additions & 2 deletions lib/nest-cam-accessory.js
Expand Up @@ -28,8 +28,8 @@ module.exports = function(exportedTypes) {
return NestCamAccessory;
};

function NestCamAccessory(conn, log, device, structure) {
NestDeviceAccessory.call(this, conn, log, device, structure);
function NestCamAccessory(conn, log, device, structure, platform) {
NestDeviceAccessory.call(this, conn, log, device, structure, platform);

const motionSvc = this.addService(Service.MotionSensor);
this.bindCharacteristic(motionSvc, Characteristic.MotionDetected, "Motion",
Expand Down
3 changes: 2 additions & 1 deletion lib/nest-device-accessory.js
Expand Up @@ -40,7 +40,7 @@ module.exports = function(exportedTypes) {
};

// Base type for Nest devices
function NestDeviceAccessory(conn, log, device, structure) {
function NestDeviceAccessory(conn, log, device, structure, platform) {

// device info
this.conn = conn;
Expand All @@ -50,6 +50,7 @@ function NestDeviceAccessory(conn, log, device, structure) {
this.device = device;
this.structure = structure;
this.structureId = structure.structure_id;
this.platform = platform;

this.log('initing ' + this.deviceType + ' "' + this.name + '":', 'deviceId:', this.deviceId, 'structureId:', this.structureId);
this.log.debug(this.device);
Expand Down
4 changes: 2 additions & 2 deletions lib/nest-protect-accessory.js
Expand Up @@ -40,8 +40,8 @@ module.exports = function(exportedTypes) {
return NestProtectAccessory;
};

function NestProtectAccessory(conn, log, device, structure) {
NestDeviceAccessory.call(this, conn, log, device, structure);
function NestProtectAccessory(conn, log, device, structure, platform) {
NestDeviceAccessory.call(this, conn, log, device, structure, platform);

const smokeSvc = this.addService(Service.SmokeSensor)
.setCharacteristic(Characteristic.Name, this.device.name + " " + "Smoke");
Expand Down
24 changes: 15 additions & 9 deletions lib/nest-thermostat-accessory.js
Expand Up @@ -32,8 +32,8 @@ module.exports = function(exportedTypes) {
return NestThermostatAccessory;
};

function NestThermostatAccessory(conn, log, device, structure) {
NestDeviceAccessory.call(this, conn, log, device, structure);
function NestThermostatAccessory(conn, log, device, structure, platform) {
NestDeviceAccessory.call(this, conn, log, device, structure, platform);

const thermostatService = this.addService(Service.Thermostat);

Expand Down Expand Up @@ -114,7 +114,7 @@ function NestThermostatAccessory(conn, log, device, structure) {
bindCharacteristic(Characteristic.CoolingThresholdTemperature, "Cooling threshold temperature", this.getCoolingThresholdTemperature, this.setCoolingThresholdTemperature, formatAsDisplayTemperature);
bindCharacteristic(Characteristic.HeatingThresholdTemperature, "Heating threshold temperature", this.getHeatingThresholdTemperature, this.setHeatingThresholdTemperature, formatAsDisplayTemperature);

if (this.device.has_fan) {
if (this.device.has_fan && this.platform.shouldEnableFeature("Thermostat.Fan")) {
const thermostatFanService = this.addService(Service.Fan);
const formatFanState = function (val) {
if (val) {
Expand All @@ -125,11 +125,15 @@ function NestThermostatAccessory(conn, log, device, structure) {
this.bindCharacteristic(thermostatFanService, Characteristic.On, "Fan State", this.getFanState, this.setFanState, formatFanState);
}

const homeService = this.addService(Service.Switch, "Home Occupied", "home_occupied");
this.bindCharacteristic(homeService, Characteristic.On, "Home Occupied", this.getHome, this.setHome);
if (this.platform.shouldEnableFeature("Thermostat.Home")) {
const homeService = this.addService(Service.Switch, "Home Occupied", "home_occupied");
this.bindCharacteristic(homeService, Characteristic.On, "Home Occupied", this.getHome, this.setHome);
}

const thermostatEcoModeService = this.addService(Service.Switch, "Eco Mode", "eco_mode");
this.bindCharacteristic(thermostatEcoModeService, Characteristic.On, "Eco Mode", this.getEcoMode, this.setEcoMode);
if (this.platform.shouldEnableFeature("Thermostat.Eco")) {
const thermostatEcoModeService = this.addService(Service.Switch, "Eco Mode", "eco_mode");
this.bindCharacteristic(thermostatEcoModeService, Characteristic.On, "Eco Mode", this.getEcoMode, this.setEcoMode);
}

// Add custom characteristics

Expand Down Expand Up @@ -398,8 +402,10 @@ NestThermostatAccessory.prototype.getFanState = function () {
NestThermostatAccessory.prototype.setFanState = function (targetFanState, callback) {
this.log("Setting target fan state for " + this.name + " to: " + targetFanState);

return this.updateDevicePropertyAsync("fan_timer_active", Boolean(targetFanState), "fan enable/disable")
.asCallback(callback);
this.updateDevicePropertyAsync("fan_timer_active", Boolean(targetFanState), "fan enable/disable")
.asCallback(function () {
setTimeout(callback, 3000, ...arguments); // fan seems to "flicker" when you first enable it
});
};

NestThermostatAccessory.prototype.getHome = function () {
Expand Down

0 comments on commit e018072

Please sign in to comment.