Skip to content

Commit

Permalink
Merge pull request #44 from justjam2013/fix-sensor-trigger
Browse files Browse the repository at this point in the history
Fixed companion sensor triggering
  • Loading branch information
justjam2013 authored Nov 26, 2024
2 parents f96e1a3 + 46e522c commit 643b5d4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 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 @@
"name": "homebridge-virtual-accessories",
"displayName": "Virtual Accessories for Homebridge",
"type": "module",
"version": "1.1.2",
"version": "1.1.3",
"description": "Virtual accessories for Homebridge.",
"author": "justjam2013",
"license": "Apache-2.0",
Expand Down
12 changes: 6 additions & 6 deletions src/accessories/virtualAccessorySwitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ export class Switch extends Accessory {
this.resetTimer!.startTimer();
}

if (this.accessoryConfiguration.accessoryHasCompanionSensor) {
this.states.SensorState = this.determineSensorState();

this.companionSensor!.triggerCompanionSensorState(this.states.SensorState, this);
}

if (this.accessoryConfiguration.accessoryIsStateful) {
this.saveState(this.storagePath, this.stateStorageKey, this.states.SwitchState);
}

this.platform.log.info(`[${this.accessoryConfiguration.accessoryName}] Setting State: ${Switch.getStateName(this.states.SwitchState)}`);

if (this.accessoryConfiguration.accessoryHasCompanionSensor) {
this.states.SensorState = this.determineSensorState();

this.companionSensor!.triggerCompanionSensorState(this.states.SensorState, this);
}
}

setCompanionSwitchState(value: boolean) {
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/virtualSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export abstract class VirtualSensor extends Accessory {
/**
* Handle requests to get the current value of the "Sensor State" characteristic
*/
handleSensorStateGet() {
async handleSensorStateGet() {
const sensorState = this.states.SensorState;

this.platform.log.debug(`[${this.accessoryConfiguration.accessoryName}] Getting Sensor Current State: ${this.getStateName(sensorState)}`);
Expand All @@ -115,7 +115,7 @@ export abstract class VirtualSensor extends Accessory {
/**
* This method is called by the accessory that has this sensor as a companion
*/
triggerCompanionSensorState(sensorState: number, accessory: Accessory) {
async triggerCompanionSensorState(sensorState: number, accessory: Accessory) {
if (!this.isCompanionSensor) {
throw new NotCompanionError(`${this.accessoryConfiguration.accessoryName} is not a companion sensor`);
} else if (accessory.accessory.UUID !== this.accessory.UUID) {
Expand Down

0 comments on commit 643b5d4

Please sign in to comment.