Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8135a4

Browse files
author
Stefan Kuper
committed
blacklist / whitelist
1 parent70ec953 commitc8135a4

File tree

3 files changed

+169
-7
lines changed

3 files changed

+169
-7
lines changed

‎lib/netatmo-accessory.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ module.exports = function(pHomebridge) {
9090
this.log.debug("Service not supported in "+this.name+": "+svcName);
9191
}
9292
}catch(err){
93-
this.log("Could not process service file "+file);
94-
this.log(err);
95-
this.log(err.stack);
93+
this.log.warn("Could not process service file "+file);
94+
this.log.warn(err);
95+
this.log.warn(err.stack);
9696
}
9797
}.bind(this)
9898
);

‎lib/netatmo-device.js‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,27 @@ class NetatmoDevice {
8989
callback("The abstract method loadDeviceData should be overridden",null)
9090
}
9191

92-
buildAccessories(callback){
92+
buildAccessories(callback){
9393
Object.keys(this.deviceData).forEach(function(key){
94-
varaccessory=this.buildAccessory(this.deviceData[key]);
95-
this.log.debug("Did build accessory "+accessory.name);
96-
this.accessories.push(accessory);
94+
95+
// key is id! Should go into blacklist / whitelist !
96+
97+
varkeep=true;
98+
99+
if(this.config.whitelist&&this.config.whitelist.length>0){
100+
keep=(this.config.whitelist.indexOf(key)>-1);
101+
}
102+
if(this.config.blacklist&&this.config.blacklist.length>0){
103+
keep=keep&&(this.config.blacklist.indexOf(key)<0);
104+
}
105+
106+
if(keep){
107+
varaccessory=this.buildAccessory(this.deviceData[key]);
108+
this.log.debug("Did build accessory "+accessory.name);
109+
this.accessories.push(accessory);
110+
}
111+
112+
97113
}.bind(this));
98114
callback(null,this.accessories);
99115
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
varassert=require('assert');
2+
varlogx=require("./logger")._system;
3+
4+
varhomebridgeMock=require('./homebridge-mock')();
5+
6+
vardummyAuth={
7+
client_id:"1234567890",
8+
client_secret:"0987654321",
9+
username:"test@tester.com",
10+
password:"password"
11+
};
12+
13+
varapi={
14+
getStationsData:function(callback){
15+
varstationData=[
16+
{
17+
"_id":"d1:00:00:00:00:00",
18+
"modules":[
19+
{"_id":"d1:m1:11:11:11:11","data_type":[]},
20+
],
21+
"data_type":[]
22+
},{
23+
"_id":"d2:00:00:00:00:00",
24+
"modules":[
25+
{"_id":"d2:m1:11:11:11:11","data_type":[]},
26+
{"_id":"d2:m2:11:11:11:11","data_type":[]},
27+
{"_id":"d2:m3:11:11:11:11","data_type":[]}
28+
],
29+
"data_type":[]
30+
},{
31+
"_id":"d3:00:00:00:00:00",
32+
"modules":[
33+
{"_id":"d3:m1:11:11:11:11","data_type":[]},
34+
{"_id":"d3:m2:11:11:11:11","data_type":[]},
35+
{"_id":"d3:m3:11:11:11:11","data_type":[]}
36+
],
37+
"data_type":[]
38+
}
39+
];
40+
callback(null,stationData);
41+
},
42+
getHomeData:function(callback){
43+
varhomeData={"homes" :
44+
[
45+
{"id" :"11:22:33:44:55:66"},
46+
{"id" :"22:22:22:22:22:22"},
47+
{"id" :"33:33:33:33:33:33"},
48+
{"id" :"44:22:44:44:22:44"},
49+
{"id" :"55:00:00:00:00:55"},
50+
{"id" :"66:66:66:66:66:66"}
51+
]
52+
};
53+
callback(null,homeData);
54+
}
55+
};
56+
57+
describe("Blacklist / Whitelist",function(){
58+
59+
describe("Weather Device",function(){
60+
61+
varWeatherDevice=require("../../device/weatherstation-device")(homebridgeMock);
62+
63+
it('build accessories with empty config loads all',function(done){
64+
varconfig={};
65+
varstation=newWeatherDevice(logx,api,config);
66+
67+
station.buildAccessoriesForDevices(function(err,deviceAccessories){
68+
assert.equal(deviceAccessories.length,10);
69+
done();
70+
});
71+
});
72+
73+
it('build accessories with blacklist device loads all but module',function(done){
74+
varconfig={blacklist:["d2:00:00:00:00:00"]};
75+
varstation=newWeatherDevice(logx,api,config);
76+
77+
station.buildAccessoriesForDevices(function(err,deviceAccessories){
78+
assert.equal(deviceAccessories.length,9);
79+
done();
80+
});
81+
});
82+
83+
it('build accessories with blacklist module loads all but module',function(done){
84+
varconfig={blacklist:["d2:m2:11:11:11:11"]};
85+
varstation=newWeatherDevice(logx,api,config);
86+
87+
station.buildAccessoriesForDevices(function(err,deviceAccessories){
88+
assert.equal(deviceAccessories.length,9);
89+
done();
90+
});
91+
});
92+
93+
});
94+
95+
describe("Camera Device",function(){
96+
97+
varCameraDevice=require("../../device/camera-device")(homebridgeMock);
98+
99+
it('build accessories with empty config loads all',function(done){
100+
varconfig={};
101+
varcamera=newCameraDevice(logx,api,config);
102+
camera.buildAccessoriesForDevices(function(err,deviceAccessories){
103+
assert.equal(deviceAccessories.length,6);
104+
done();
105+
});
106+
});
107+
108+
it('build accessories with empty whitelist loads all',function(done){
109+
varconfig={whitelist:[]};
110+
varcamera=newCameraDevice(logx,api,config);
111+
camera.buildAccessoriesForDevices(function(err,deviceAccessories){
112+
assert.equal(deviceAccessories.length,6);
113+
done();
114+
});
115+
});
116+
117+
it('build accessories with empty blacklist loads all',function(done){
118+
varconfig={blacklist:[]};
119+
varcamera=newCameraDevice(logx,api,config);
120+
camera.buildAccessoriesForDevices(function(err,deviceAccessories){
121+
assert.equal(deviceAccessories.length,6);
122+
done();
123+
});
124+
});
125+
126+
it('build accessories with blacklist entry loads 5',function(done){
127+
varconfig={blacklist:["33:33:33:33:33:33"]};
128+
varcamera=newCameraDevice(logx,api,config);
129+
camera.buildAccessoriesForDevices(function(err,deviceAccessories){
130+
assert.equal(deviceAccessories.length,5);
131+
// TODO: Check 333 not there!
132+
done();
133+
});
134+
});
135+
136+
it('build accessories with whitelist entry loads 1',function(done){
137+
varconfig={whitelist:["55:00:00:00:00:55"]};
138+
varcamera=newCameraDevice(logx,api,config);
139+
camera.buildAccessoriesForDevices(function(err,deviceAccessories){
140+
assert.equal(deviceAccessories.length,1);
141+
// TODO: Check 333 not there!
142+
done();
143+
});
144+
});
145+
});
146+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp