From e832e7182b134047e5a140bfeabf2610e9cec24b Mon Sep 17 00:00:00 2001 From: oznu Date: Thu, 4 Nov 2021 16:55:26 +1000 Subject: [PATCH] add filter based on accessory serial number; add option to disable 2fa req. --- config.schema.json | 50 +++++++++++++++++++++++++++++++++++++++++++--- package.json | 2 +- src/hap.ts | 15 +++++++++++--- src/interfaces.ts | 5 ++++- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/config.schema.json b/config.schema.json index feb4012..45af464 100644 --- a/config.schema.json +++ b/config.schema.json @@ -29,10 +29,14 @@ "default": "Keep your token a secret!" }, "twoFactorAuthPin": { - "placeholder": "Two Factor Authentication Pin Code", + "placeholder": "Pin Code", "type": "string", "pattern": "^[0-9]*$" }, + "disablePinCodeRequirement": { + "title": "Disable Pin Code Requirement", + "type": "boolean" + }, "debug": { "title": "Enable Debug Logging", "type": "boolean" @@ -54,6 +58,14 @@ "type": "string" } }, + "accessorySerialFilter": { + "title": "Accessory", + "type": "array", + "items": { + "title": "Accessory Serial", + "type": "string" + } + }, "forceFahrenheit": { "title": "Force Degrees Fahrenheit", "type": "boolean" @@ -74,7 +86,7 @@ "debug", { "type": "help", - "helpvalue": "
Two Factor Authentication
If you provide a two factor authentication code, the Google Assistant will prompt you for your code before performing certain actions. e.g. unlocking a Lock Mechanism." + "helpvalue": "
Pin Code
If you provide a pin code, the Google Assistant will prompt you for your code before performing certain actions. e.g. unlocking a Lock Mechanism." }, { "notitle": true, @@ -82,7 +94,14 @@ }, { "type": "help", - "helpvalue": "
Instance Blacklist
Enter the usernames of any Homebridge instances on your network that you don't want to be able to control from the Google Assistant." + "helpvalue": "Certain devices require a pin code to be set before they will be registered with Google Home. To overide this behaviour, check the box below. Use at your own risk." + }, + { + "key": "disablePinCodeRequirement" + }, + { + "type": "help", + "helpvalue": "
Instance Blacklist
Enter the usernames of any Homebridge instances or child bridges on your network that you don't want to be able to control from the Google Assistant." }, { "nodescription": true, @@ -130,6 +149,31 @@ } ] }, + { + "type": "help", + "helpvalue": "Enter the serial of the accessories you don't want to control from the Google Assistant." + }, + { + "nodescription": true, + "notitle": true, + "key": "accessorySerialFilter", + "type": "array", + "items": [ + { + "type": "div", + "displayFlex": true, + "flex-direction": "row", + "items": [ + { + "key": "accessorySerialFilter[]", + "flex": "1 1 50px", + "notitle": true, + "placeholder": "Enter accessory serial..." + } + ] + } + ] + }, { "type": "help", "helpvalue": "
Force Fahrenheit
Some Homebridge thermostat plugins do not correctly report they are using Fahrenheit temperature units. Enabling this option will force all thermostats accessories to display temperature units in Fahrenheit." diff --git a/package.json b/package.json index 87d88e9..8096963 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": false, "name": "homebridge-gsh", "displayName": "Homebridge Google Smart Home", - "version": "2.1.0", + "version": "2.2.0", "description": "Google Smart Home", "license": "GPL-3.0", "author": "oznu ", diff --git a/src/hap.ts b/src/hap.ts index 8187b79..af2f172 100644 --- a/src/hap.ts +++ b/src/hap.ts @@ -85,6 +85,7 @@ export class Hap { instanceBlacklist: Array = []; accessoryFilter: Array = []; + accessorySerialFilter: Array = []; deviceNameMap: Array<{ replace: string; with: string }> = []; constructor(socket, log, pin: string, config: PluginConfig) { @@ -94,6 +95,7 @@ export class Hap { this.pin = pin; this.accessoryFilter = config.accessoryFilter || []; + this.accessorySerialFilter = config.accessorySerialFilter || []; this.instanceBlacklist = config.instanceBlacklist || []; this.log.debug('Waiting 15 seconds before starting instance discovery...'); @@ -244,7 +246,7 @@ export class Hap { status: 'ERROR', }); } - return resolve(); + return resolve(undefined); }); }); } @@ -384,12 +386,19 @@ export class Hap { // perform user-defined service filters based on name if (this.accessoryFilter.includes(service.serviceName)) { + this.log.debug(`Skipping ${service.serviceName} ${service.accessoryInformation['Serial Number']} - matches accessoryFilter`); + return; + } + + // perform user-defined service filters based on serial number + if (this.accessorySerialFilter.includes(service.accessoryInformation['Serial Number'])) { + this.log.debug(`Skipping ${service.serviceName} ${service.accessoryInformation['Serial Number']} - matches accessorySerialFilter'`); return; } // if 2fa is forced for this service type, but a pin has not been set ignore the service - if (this.types[service.serviceType].twoFactorRequired && !this.config.twoFactorAuthPin) { - this.log.warn(`Not registering ${service.serviceName} - Two Factor Authentication Pin has not been set and is required for ` + + if (this.types[service.serviceType].twoFactorRequired && !this.config.twoFactorAuthPin && !this.config.disablePinCodeRequirement) { + this.log.warn(`Not registering ${service.serviceName} - Pin cide has not been set and is required for secure ` + `${service.serviceType} accessory types. See https://git.io/JUQWX`); return; } diff --git a/src/interfaces.ts b/src/interfaces.ts index bd4bd85..cfdd34f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -6,8 +6,10 @@ export interface PluginConfig extends PlatformConfig { token: string; debug?: boolean; twoFactorAuthPin: string; + disablePinCodeRequirement?: boolean; instanceBlacklist?: Array; accessoryFilter?: Array; + accessorySerialFilter?: Array; forceFahrenheit?: boolean; } @@ -49,8 +51,9 @@ export interface HapService { characteristics: HapCharacteristic[]; primary: boolean; hidden: boolean; + serialNumber: string; - // custom + // custom uniqueId?: string; serviceName?: string; accessoryInformation?: any;