Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Commit 2f4f97b

Browse files
author
Takeshi Kishi
authored
add config option (#20)
1 parent 8b80f39 commit 2f4f97b

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

config.schema.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,37 @@
1515
"title": "Access Token",
1616
"type": "string",
1717
"required": true
18+
},
19+
"LIGHT": {
20+
"title": "Light",
21+
"type": "boolean",
22+
"default": true
23+
},
24+
"AC": {
25+
"title": "Air Conditioner",
26+
"type": "boolean",
27+
"default": true
28+
},
29+
"TV": {
30+
"title": "TV",
31+
"type": "boolean",
32+
"default": true
1833
}
1934
}
20-
}
35+
},
36+
"layout": [
37+
"name",
38+
"accessToken",
39+
{
40+
"type": "fieldset",
41+
"title": "Appliance Type",
42+
"expandable": true,
43+
"expanded": false,
44+
"items": [
45+
"LIGHT",
46+
"AC",
47+
"TV"
48+
]
49+
}
50+
]
2151
}

src/platform.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ export class NatureRemoPlatform implements DynamicPlatformPlugin {
6565
}
6666
const appliances = await this.natureRemoApi.getAllAppliances();
6767
for (const appliance of appliances) {
68-
if (appliance.type === 'LIGHT' || appliance.type === 'AC' || appliance.type === 'TV') {
69-
const existingAccessory = this.accessories.find(accessory => accessory.UUID === appliance.id);
68+
const existingAccessory = this.accessories.find(accessory => accessory.UUID === appliance.id);
69+
if ((this.config.LIGHT && appliance.type === 'LIGHT')
70+
|| (this.config.AC && appliance.type === 'AC')
71+
|| (this.config.TV && appliance.type === 'TV')) {
7072
if (existingAccessory) {
7173
this.logger.info('Restoring existing accessory from cache:', existingAccessory.displayName);
7274
if (appliance.type === 'LIGHT') {
@@ -89,6 +91,10 @@ export class NatureRemoPlatform implements DynamicPlatformPlugin {
8991
}
9092
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
9193
}
94+
} else {
95+
if (existingAccessory) {
96+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [existingAccessory]);
97+
}
9298
}
9399
}
94100
}

0 commit comments

Comments
 (0)