diff --git a/config.schema.json b/config.schema.json index 660170e..3237e65 100644 --- a/config.schema.json +++ b/config.schema.json @@ -191,7 +191,7 @@ "description": "Accessory state survives Homebridge restart", "type": "boolean", "condition": { - "functionBody": "return ['switch', 'lock', 'garagedoor', 'windowcovering'].includes(model.devices[arrayIndices].accessoryType) && [undefined, false].includes(model.devices[arrayIndices].accessoryHasResetTimer);" + "functionBody": "return ['garagedoor', 'lock', 'switch', 'valve', 'windowcovering'].includes(model.devices[arrayIndices].accessoryType) && [undefined, false].includes(model.devices[arrayIndices].accessoryHasResetTimer);" } }, "accessoryHasResetTimer": { diff --git a/package-lock.json b/package-lock.json index 9392f40..e9fd729 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-virtual-accessories", - "version": "1.2.7", + "version": "1.2.8-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-virtual-accessories", - "version": "1.2.7", + "version": "1.2.8-beta.1", "license": "Apache-2.0", "dependencies": { "@js-joda/core": "^5.6.3", diff --git a/package.json b/package.json index 36da711..838020c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "homebridge-virtual-accessories", "displayName": "Virtual Accessories for Homebridge", "type": "module", - "version": "1.2.7", + "version": "1.2.8-beta.1", "description": "Virtual HomeKit accessories for Homebridge.", "author": "justjam2013", "license": "Apache-2.0", diff --git a/src/accessories/virtualAccessoryValve.ts b/src/accessories/virtualAccessoryValve.ts index 850d426..de7b080 100644 --- a/src/accessories/virtualAccessoryValve.ts +++ b/src/accessories/virtualAccessoryValve.ts @@ -22,6 +22,8 @@ export class Valve extends Accessory { private valveType: number; private durationTimer: Timer; + private readonly stateStorageKey: string = 'ValveActive'; + /** * These are just used to create a working example * You should implement your own code to track the state of your accessory @@ -56,6 +58,16 @@ export class Valve extends Accessory { break; } + // If the accessory is stateful retrieve stored state, otherwise set to default state + if (this.accessoryConfiguration.accessoryIsStateful) { + const cachedState = this.loadState(this.storagePath, this.stateStorageKey) as number; + + if (cachedState !== undefined) { + this.states.ValveActive = cachedState; + this.states.ValveInUse = (this.states.ValveActive === Valve.ACTIVE) ? Valve.IN_USE : Valve.NOT_IN_USE; + } + } + this.durationTimer = new Timer(this.accessoryConfiguration.valveDuration, Timer.Units.Seconds); // set accessory information @@ -142,6 +154,11 @@ export class Valve extends Accessory { this.platform.log.info(`[${this.accessoryConfiguration.accessoryName}] Setting In Use: ${this.getInUseName(this.states.ValveInUse)}`); + // Store device state if stateful + if (this.accessoryConfiguration.accessoryIsStateful) { + this.saveState(this.storagePath, this.stateStorageKey, this.states.ValveActive); + } + this.durationTimer.stop(); if (this.states.ValveActive === Valve.ACTIVE) { this.durationTimer.start(