Skip to content

Commit

Permalink
adding support for whitelisting homes (#84)
Browse files Browse the repository at this point in the history
* adding support for whitelisting homes

* changing homeWhitelist to an array

* Update config.schema.json

Co-authored-by: gaosen <0x5e@sina.cn>
  • Loading branch information
JulianLepinski and 0x5e committed Nov 16, 2022
1 parent d80793e commit 6b3a48f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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';"
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TuyaPlatformHomeConfigOptions {
username: string;
password: string;
appSchema: string;
homeWhitelist: Array<number>;
}

export type TuyaPlatformConfigOptions = TuyaPlatformCustomConfigOptions | TuyaPlatformHomeConfigOptions;
Expand All @@ -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'},
},
};
11 changes: 10 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6b3a48f

Please sign in to comment.