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

Commit

Permalink
add filter based on accessory serial number; add option to disable 2f…
Browse files Browse the repository at this point in the history
…a req.
  • Loading branch information
oznu committed Nov 4, 2021
1 parent c10b81c commit e832e71
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
50 changes: 47 additions & 3 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -54,6 +58,14 @@
"type": "string"
}
},
"accessorySerialFilter": {
"title": "Accessory",
"type": "array",
"items": {
"title": "Accessory Serial",
"type": "string"
}
},
"forceFahrenheit": {
"title": "Force Degrees Fahrenheit",
"type": "boolean"
Expand All @@ -74,15 +86,22 @@
"debug",
{
"type": "help",
"helpvalue": "<h5>Two Factor Authentication</h5><em class='primary-text'>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.</em>"
"helpvalue": "<h5>Pin Code</h5><em class='primary-text'>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.</em>"
},
{
"notitle": true,
"key": "twoFactorAuthPin"
},
{
"type": "help",
"helpvalue": "<h5>Instance Blacklist</h5><em class='primary-text'>Enter the usernames of any Homebridge instances on your network that you don't want to be able to control from the Google Assistant.</em>"
"helpvalue": "<em class='primary-text'>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.</em>"
},
{
"key": "disablePinCodeRequirement"
},
{
"type": "help",
"helpvalue": "<h5>Instance Blacklist</h5><em class='primary-text'>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.</em>"
},
{
"nodescription": true,
Expand Down Expand Up @@ -130,6 +149,31 @@
}
]
},
{
"type": "help",
"helpvalue": "<em class='primary-text'>Enter the serial of the accessories you don't want to control from the Google Assistant.</em>"
},
{
"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": "<h5>Force Fahrenheit</h5><em class='primary-text'>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.</em>"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>",
Expand Down
15 changes: 12 additions & 3 deletions src/hap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class Hap {

instanceBlacklist: Array<string> = [];
accessoryFilter: Array<string> = [];
accessorySerialFilter: Array<string> = [];
deviceNameMap: Array<{ replace: string; with: string }> = [];

constructor(socket, log, pin: string, config: PluginConfig) {
Expand All @@ -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...');
Expand Down Expand Up @@ -244,7 +246,7 @@ export class Hap {
status: 'ERROR',
});
}
return resolve();
return resolve(undefined);
});
});
}
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export interface PluginConfig extends PlatformConfig {
token: string;
debug?: boolean;
twoFactorAuthPin: string;
disablePinCodeRequirement?: boolean;
instanceBlacklist?: Array<string>;
accessoryFilter?: Array<string>;
accessorySerialFilter?: Array<string>;
forceFahrenheit?: boolean;
}

Expand Down Expand Up @@ -49,8 +51,9 @@ export interface HapService {
characteristics: HapCharacteristic[];
primary: boolean;
hidden: boolean;
serialNumber: string;

// custom
// custom
uniqueId?: string;
serviceName?: string;
accessoryInformation?: any;
Expand Down

0 comments on commit e832e71

Please sign in to comment.