Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from chriscn/features/make_regex_config_optional
Browse files Browse the repository at this point in the history
Make regex config optional, remove nested if statement
  • Loading branch information
chriscn authored Jun 9, 2020
2 parents a97f498 + bd922a5 commit 423d6f3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,17 @@ export class MiHomePlatform implements DynamicPlatformPlugin {
const uuid = this.api.hap.uuid.generate(device.id.toString());
let friendlyName = '';

if (this.config.regex.enabled) {
if (this.config.regex.match_string == undefined || this.config.regex.match_string == null || this.config.regex.match_string == '') {
friendlyName = this.toTitleCase(device.label);
} else {
friendlyName = this.toTitleCase(device.label.match(this.config.regex.match_string)[1]);
}
} else {
if (this.config.regex == undefined
|| this.config.regex == null
|| this.config.regex.enabled == undefined
|| this.config.regex.enabled == null
|| !this.config.regex.enabled
|| this.config.regex.match_string == undefined
|| this.config.regex.match_string == null
|| this.config.regex.match_string == '') {
friendlyName = this.toTitleCase(device.label);
} else {
friendlyName = this.toTitleCase(device.label.match(this.config.regex.match_string)[1]);
}
// cleans up the name to be more homekit elagant

Expand Down

0 comments on commit 423d6f3

Please sign in to comment.