Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding support for whitelisting homes #84

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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