Skip to content

Commit

Permalink
Display name updates
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleBoyer committed Jul 15, 2024
1 parent 884a876 commit 27738d1
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 99 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,
"displayName": "Konnected BlaQ",
"name": "homebridge-blaq",
"version": "0.2.9",
"version": "0.2.10",
"description": "Control and view your garage door(s) remotely with real-time updates using Konnected's BlaQ hardware",
"license": "Apache-2.0",
"type": "module",
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-learn-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type BlaQGarageLearnModeAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Learn/Pair Mode';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -73,7 +75,7 @@ export class BlaQGarageLearnModeAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.switchService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.switchService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.switchService.getCharacteristic(this.platform.characteristic.On)
.onGet(this.getIsOn.bind(this))
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type BlaQGarageLightAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Light';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -77,7 +79,7 @@ export class BlaQGarageLightAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.lightbulbService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.lightbulbService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.lightbulbService.getCharacteristic(this.platform.characteristic.On)
.onGet(this.getPowerState.bind(this))
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-lock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type BlaQGarageLockAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Lock Remotes';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -77,7 +79,7 @@ export class BlaQGarageLockAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.lockService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.lockService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.lockService.getCharacteristic(this.platform.characteristic.LockCurrentState)
.onGet(this.getLockState.bind(this));
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-motion-sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type BlaQGarageMotionSensorAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Motion Sensor';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -72,7 +74,7 @@ export class BlaQGarageMotionSensorAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.motionSensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.motionSensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.motionSensorService.getCharacteristic(this.platform.characteristic.MotionDetected)
.onGet(this.getMotionDetected.bind(this));
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-obstruction-sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type BlaQGarageObstructionSensorAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Obstruction Sensor';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -72,7 +74,7 @@ export class BlaQGarageObstructionSensorAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.occupancySensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.occupancySensorService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.occupancySensorService.getCharacteristic(this.platform.characteristic.OccupancyDetected)
.onGet(this.getObstructionDetected.bind(this));
Expand Down
4 changes: 3 additions & 1 deletion src/accessory/garage-pre-close-warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type BlaQGaragePreCloseWarningAccessoryConstructorParams = {
apiBaseURL: string;
};

export const label = 'Pre-close Warning';

/**
* Platform Accessory
* An instance of this class is created for each accessory your platform registers
Expand Down Expand Up @@ -73,7 +75,7 @@ export class BlaQGaragePreCloseWarningAccessory implements BaseBlaQAccessory {

// Set the service name. This is what is displayed as the name on the Home
// app. We use what we stored in `accessory.context` in `discoverDevices`.
this.outletService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName);
this.outletService.setCharacteristic(this.platform.characteristic.Name, accessory.context.device.displayName + ' ' + label);

this.outletService.getCharacteristic(this.platform.characteristic.On)
.onGet(this.getIsOn.bind(this))
Expand Down
143 changes: 53 additions & 90 deletions src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type ModelAndSerialNumber = {
serialNumber: string;
};

type InitAccessoryParams = ModelAndSerialNumber & {
platform: BlaQHomebridgePluginPlatform;
accessory: PlatformAccessory;
};

export type BlaQInitAccessoryCallback = (configDevice: ConfigDevice, Model: string, SerialNumber: string) => {
platform: BlaQHomebridgePluginPlatform;
accessory: PlatformAccessory;
Expand Down Expand Up @@ -99,115 +104,73 @@ export class BlaQHub {
});
}

private initGarageDoorAccessory({ model, serialNumber }: ModelAndSerialNumber){
const {platform, accessory} = this.initAccessoryCallback(
this.configDevice,
model,
serialNumber,
);
private initGarageDoorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
this.accessories.push(new BlaQGarageDoorAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}

private initGarageLightAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Light`;
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
model,
serialNumber,
);
this.accessories.push(new BlaQGarageLightAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
private initGarageLightAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enableLight) {
this.accessories.push(new BlaQGarageLightAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initGarageLockAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Remote Lock`;
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
model,
serialNumber,
);
this.accessories.push(new BlaQGarageLockAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
private initGarageLockAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enableLockRemotes){
this.accessories.push(new BlaQGarageLockAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initGarageMotionSensorAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Motion Sensor`;
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
model,
serialNumber,
);
this.accessories.push(new BlaQGarageMotionSensorAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
private initGarageMotionSensorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enableMotionSensor){
this.accessories.push(new BlaQGarageMotionSensorAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initGaragePreCloseWarningAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Pre Close Warning`;
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
model,
serialNumber,
);
this.accessories.push(new BlaQGaragePreCloseWarningAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
private initGaragePreCloseWarningAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enablePreCloseWarning){
this.accessories.push(new BlaQGaragePreCloseWarningAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initGarageLearnModeAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Learn/Pair Mode`;
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
model,
serialNumber,
);
this.accessories.push(new BlaQGarageLearnModeAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
private initGarageLearnModeAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enableLearnMode){
this.accessories.push(new BlaQGarageLearnModeAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initGarageObstructionSensorAccessory({ model, serialNumber }: ModelAndSerialNumber){
const baseDisplayName = this.configDevice.displayName || 'Garage Door';
const displayName = `${baseDisplayName} Obstruction Sensor`;
private initGarageObstructionSensorAccessory({ platform, accessory, model, serialNumber}: InitAccessoryParams){
if(this.pluginConfig.enableSeparateObstructionSensor){
this.accessories.push(new BlaQGarageObstructionSensorAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}
}

private initAccessories({ model, serialNumber }: ModelAndSerialNumber){
const {platform, accessory} = this.initAccessoryCallback(
{ ...this.configDevice, displayName },
this.configDevice,
model,
serialNumber,
);
this.accessories.push(new BlaQGarageObstructionSensorAccessory({
platform, accessory, model, serialNumber, apiBaseURL: this.getAPIBaseURL(),
}));
}

private initAccessories({ model, serialNumber }: ModelAndSerialNumber){
this.initGarageDoorAccessory({ model, serialNumber });
if(this.pluginConfig.enableLight) {
this.initGarageLightAccessory({ model, serialNumber });
}
if(this.pluginConfig.enableLockRemotes){
this.initGarageLockAccessory({ model, serialNumber });
}
if(this.pluginConfig.enableMotionSensor){
this.initGarageMotionSensorAccessory({ model, serialNumber });
}
if(this.pluginConfig.enablePreCloseWarning){
this.initGaragePreCloseWarningAccessory({ model, serialNumber });
}
if(this.pluginConfig.enableLearnMode){
this.initGarageLearnModeAccessory({ model, serialNumber });
}
if(this.pluginConfig.enableSeparateObstructionSensor){
this.initGarageObstructionSensorAccessory({ model, serialNumber });
}
this.initGarageDoorAccessory({ platform, accessory, model, serialNumber });
this.initGarageLightAccessory({ platform, accessory, model, serialNumber });
this.initGarageLockAccessory({ platform, accessory, model, serialNumber });
this.initGarageMotionSensorAccessory({ platform, accessory, model, serialNumber });
this.initGaragePreCloseWarningAccessory({ platform, accessory, model, serialNumber });
this.initGarageLearnModeAccessory({ platform, accessory, model, serialNumber });
this.initGarageObstructionSensorAccessory({ platform, accessory, model, serialNumber });
}

private handlePingUpdate(msg: PingMessageEvent){
Expand Down

0 comments on commit 27738d1

Please sign in to comment.