Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Allow hiding of devices
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Sep 5, 2017
1 parent 50b58cf commit 7487a6a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,7 @@ Add platform to `config.json`, for configuration see below.
"password": "<password>",
"url": "http://fritz.box",
"interval": 60,
"hide": ["wifi", "<ain>"],
"options": {
"strictSSL": false
}
Expand All @@ -54,6 +55,8 @@ The `url` and `interval` settings are optional:
- `url`: Fritz!Box address
- `interval`: polling interval for updating accessories if state was changed outside homebringe

The `hide` config options allows to specify an array of device AINs that will not be added to homebridge. Use `wifi` for hiding the guest wifi switch.

To enable debugging run homebridge with `-D` option:

homebridge -D
Expand Down
9 changes: 4 additions & 5 deletions config.json
@@ -1,13 +1,12 @@
{
// ...

"platforms": [
{
"platform": "Fritz!Box",
"name": "My FritzBox",
"username": "<username>",
"password": "<password>",
"name": "My Fritz!Box",
"username": "",
"password": "",
"url": "http://fritz.box",
"hide": [],
"interval": 60,
"debug": false
}
Expand Down
33 changes: 22 additions & 11 deletions index.js
Expand Up @@ -39,6 +39,9 @@ function FritzPlatform(log, config) {
this.options = this.config.options || {};
this.interval = 1000 * (this.config.interval || 60); // 1 minute

// array of hidden devices
if (!Array.isArray(this.options.hide)) this.options.hide = [];

// fritz url
var url = this.config.url || 'http://fritz.box';
if (!isWebUri(url)) this.log.warn("Invalid Fritz!Box url - forgot http(s)://?");
Expand Down Expand Up @@ -88,7 +91,9 @@ FritzPlatform.prototype = {
self.log("Discovering accessories");

// wifi
accessories.push(new FritzWifiAccessory(self));
if (self.options.hide.indexOf("wifi") == -1) {
accessories.push(new FritzWifiAccessory(self));
}

self.fritz("getDeviceList").then(function(devices) {
// cache list of devices in options for reuse by non-API functions
Expand All @@ -99,28 +104,34 @@ FritzPlatform.prototype = {
self.log("Outlets found: %s", ains.toString());

ains.forEach(function(ain) {
accessories.push(new FritzOutletAccessory(self, ain));
if (self.options.hide.indexOf(ain) == -1) {
accessories.push(new FritzOutletAccessory(self, ain));
}
});

// thermostats
self.fritz('getThermostatList').then(function(ains) {
self.log("Thermostats found: %s", ains.toString());

ains.forEach(function(ain) {
accessories.push(new FritzThermostatAccessory(self, ain));
if (self.options.hide.indexOf(ain) == -1) {
accessories.push(new FritzThermostatAccessory(self, ain));
}
});

// add remaining non-api devices that support temperature, e.g. Fritz!DECT 100 repeater
var sensors = [];
devices.forEach(function(device) {
var ain = device.identifier.replace(/\s/g, '');
var unknown = !accessories.find(function(accessory) {
return accessory.ain && accessory.ain == ain;
});

if (unknown && device.temperature) {
sensors.push(ain);
accessories.push(new FritzTemperatureSensorAccessory(self, ain));
if (device.temperature) {
var ain = device.identifier.replace(/\s/g, '');
if (!accessories.find(function(accessory) {
return accessory.ain && accessory.ain == ain;
})) {
sensors.push(ain);
if (self.options.hide.indexOf(ain) == -1) {
accessories.push(new FritzTemperatureSensorAccessory(self, ain));
}
}
}
});
self.log("Sensors found: %s", sensors.toString());
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "homebridge-fritz",
"version": "0.5.6",
"version": "0.5.7",
"author": "Andreas Goetz <cpuidle@gmx.de>",
"homepage": "https://github.com/andig/homebridge-fritz#readme",
"description": "Homebridge platform plugin for Fritz!Box",
Expand Down Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"bluebird": "^3.3.5",
"extend": "^3.0.0",
"fritzapi": "^0.9.2",
"fritzapi": "^0.9.4",
"valid-url": "^1.0.9"
},
"devDependencies": {
Expand Down

0 comments on commit 7487a6a

Please sign in to comment.