Skip to content

Commit

Permalink
Merge pull request #85 from justjam2013/disable-cron-trigger-logging
Browse files Browse the repository at this point in the history
Added option to disable event logging for cron trigger
  • Loading branch information
justjam2013 authored Jan 8, 2025
2 parents dbab774 + 9346012 commit 171b315
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@
"type": "string",
"format": "date-time"
},
"disableTriggerEventLogging": {
"title": "Disable Trigger Event Logging",
"description": "Disable logging for high frequency trigger events",
"type": "boolean"
},
"isDisabled": {
"title": "Disable Cron Trigger",
"description": "Turn off/on trigger",
Expand Down
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.2.6",
"version": "1.2.7-beta.1",
"description": "Virtual HomeKit accessories for Homebridge.",
"author": "justjam2013",
"license": "Apache-2.0",
Expand Down
1 change: 1 addition & 0 deletions src/configuration/configurationCronTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class CronTriggerConfiguration {
zoneId!: string;
startDateTime!: string;
endDateTime!: string;
disableTriggerEventLogging: boolean = false;
isDisabled: boolean = false;

// private static cronPattern = '^((((\\d+,)+\\d+|(\\d+(\\/|-|#)\\d+)|\\d+L?|\\*(\\/\\d+)?|L(-\\d+)?|\\?|[A-Z]{3}(-[A-Z]{3})?) ?){5,7})$';
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/virtualSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export abstract class VirtualSensor extends Accessory {
/**
* This method is called by the trigger to toggle the sensor
*/
triggerKeySensorState(sensorState: number, trigger: Trigger) {
triggerKeySensorState(sensorState: number, trigger: Trigger, isLoggingDisabled: boolean = false) {
if (trigger.sensorConfig.accessoryID !== this.accessoryConfiguration.accessoryID) {
throw new TriggerNotAllowedError(`Trigger ${trigger.name} is not allowed to trigger this sensor`);
}
Expand All @@ -143,7 +143,7 @@ export abstract class VirtualSensor extends Accessory {

this.service!.updateCharacteristic(this.sensorCharacteristic, (this.states.SensorState));

if (sensorStateChanged) {
if (sensorStateChanged && !isLoggingDisabled) {
this.platform.log.info(`[${this.accessoryConfiguration.accessoryName}] Setting Sensor Current State: ${this.getStateName(this.states.SensorState)}`);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/triggers/triggerCron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class CronTrigger extends Trigger {
return;
}

if (triggerConfig.disableTriggerEventLogging) {
this.log.info(`[${this.sensorConfig.accessoryName}] Cron trigger event logging is disabled. Sensor state changes will not be displayed in the logs`);
}

// Hardcode reset delay
const resetDelayMillis: number = 3 * 1000; // 3 second reset delay

Expand Down Expand Up @@ -70,9 +74,9 @@ export class CronTrigger extends Trigger {

this.log.debug(`[${this.sensorConfig.accessoryName}] Matched cron pattern '${triggerConfig.pattern}'. Triggering sensor`);

sensor.triggerKeySensorState(this.sensor.OPEN_TRIGGERED, this);
sensor.triggerKeySensorState(this.sensor.OPEN_TRIGGERED, this, triggerConfig.disableTriggerEventLogging);
await this.delay(resetDelayMillis);
sensor.triggerKeySensorState(this.sensor.CLOSED_NORMAL, this);
sensor.triggerKeySensorState(this.sensor.CLOSED_NORMAL, this, triggerConfig.disableTriggerEventLogging);
}

// If we're after the end date, terminate the cron job
Expand Down

0 comments on commit 171b315

Please sign in to comment.