Multiple devices per platform

This commit is contained in:
dennis committed 2023-02-04 01:43:18 +01:00
1 parent 232d38ac8c
commit a396e49c8e
2 files changed
+21 -14

No files matched your search

+14 -9
View File
@@ -3,25 +3,30 @@
"pluginType": "platform", "pluginType": "platform",
"singular": true, "singular": true,
"schema": { "schema": {
"devices": {
"type": "array",
"items": {
"title": "Switch",
"type": "object", "type": "object",
"properties": { "properties": {
"name": { "name": {
"title": "Name", "title": "Name",
"type": "string", "type": "string",
"required": true, "required": true
"default": "Scene Switcher"
}, },
"numScenes": { "numScenes": {
"title": "Number of Scenes", "title": "Max. Scenes",
"type": "number",
"required": true,
"default": 4
},
"secondsToKeep": {
"title": "Holding Time",
"type": "number", "type": "number",
"required": true, "required": true,
"default": 5 "default": 5
},
"secondsToKeep": {
"title": "Reset Timeout",
"type": "number",
"required": true,
"default": 10
}
}
} }
} }
} }
+7 -5
View File
@@ -65,14 +65,15 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
} }
discoverDevices() { discoverDevices() {
const uuid = this.defineUuid(this.config.name, '0'); for (let i = 0; i < this.config.devices.length; i++) {
const accessoryConfig: PlatformConfigData = { const accessoryConfig: PlatformConfigData = {
Name: this.config.name ? this.config.name : 'Scene Switch', Name: this.config.devices[i].name,
MaxNumScenes: this.config.numScenes, MaxNumScenes: this.config.devices[i].numScenes,
SecondsBeforeReset: this.config.secondsToKeep, SecondsBeforeReset: this.config.devices[i].secondsToKeep,
}; };
const uuid = this.defineUuid(accessoryConfig.Name, '0');
// see if an accessory with the same uuid has already been registered and restored from // see if an accessory with the same uuid has already been registered and restored from
// the cached devices we stored in the `configureAccessory` method above // the cached devices we stored in the `configureAccessory` method above
const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid); const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);
@@ -111,4 +112,5 @@ export class MultiTapSwitchPlatform implements DynamicPlatformPlugin {
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]); this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
} }
} }
}
} }