diff --git a/README.md b/README.md index 33d39745..cdd5b0d1 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ Before configuration, please goto [Tuya IoT Platform](https://iot.tuya.com) - `options.username` - **required** : Username - `options.password` - **required** : Password - `options.appSchema` - **required** : App schema. 'tuyaSmart' for Tuya Smart App, 'smartlife' for Smart Life App. +- `options.homeWhitelist` - **optional**: An array of integer home ID values to whitelist. If present, only includes devices matching this Home ID value. **Note:** - The app account can't be used in multiple HomeBridge/HomeAssistant instance at the same time! Please consider using different app accounts instead. diff --git a/config.schema.json b/config.schema.json index 95a9372d..6fc10e88 100644 --- a/config.schema.json +++ b/config.schema.json @@ -81,7 +81,19 @@ "condition": { "functionBody": "return model.options.projectType === '2';" } - } + }, + "homeWhitelist": { + "title": "Whitelisted Home IDs", + "description": "An optional list of Home IDs to match. If blank, all homes are matched.", + "type": "array", + "items": { + "title": "Home ID", + "type": "integer" + }, + "condition": { + "functionBody": "return model.options.projectType === '2';" + } + } } } } diff --git a/src/config.ts b/src/config.ts index 89458d22..332f6dcb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -17,6 +17,7 @@ export interface TuyaPlatformHomeConfigOptions { username: string; password: string; appSchema: string; + homeWhitelist: Array; } export type TuyaPlatformConfigOptions = TuyaPlatformCustomConfigOptions | TuyaPlatformHomeConfigOptions; @@ -41,5 +42,6 @@ export const homeOptionsSchema = { username: { type: 'string', required: true }, password: { type: 'string', required: true }, appSchema: { 'type': 'string', required: true }, + homeWhitelist: { 'type': 'array'}, }, }; diff --git a/src/platform.ts b/src/platform.ts index 772ff31d..e02c81e7 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -254,7 +254,16 @@ export class TuyaPlatform implements DynamicPlatformPlugin { const homeIDList: number[] = []; for (const { home_id, name } of res.result) { this.log.info(`Got home_id=${home_id}, name=${name}`); - homeIDList.push(home_id); + if (this.options.homeWhitelist) { + if (this.options.homeWhitelist.includes(home_id)) { + this.log.info(`Found home_id=${home_id} in whitelist; including devices from this home.`); + homeIDList.push(home_id); + } else { + this.log.info(`Did not find home_id=${home_id} in whitelist; excluding devices from this home.`); + } + } else { + homeIDList.push(home_id); + } } if (homeIDList.length === 0) {