Skip to content

Commit 1d49de1

Browse files
committed
Addressed feedback from PR #257
1 parent dbe9df6 commit 1d49de1

6 files changed

Lines changed: 32 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to homebridge-dummy will be documented in this file.
44

5-
## 1.5.17-beta.1 ()
5+
## 1.5.17-beta.2 ()
66

77
### Added
88
- 'Simulate Duration' option to enable auto-shutoff for [`Valves`](https://github.com/mpatfield/homebridge-easy-mqtt/wiki/Valve) that do not have duration topics
@@ -11,6 +11,9 @@ All notable changes to homebridge-dummy will be documented in this file.
1111
### Fixed
1212
- Potential crash on launch
1313

14+
### Notes
15+
Please consider giving this plugin a ⭐️ on [GitHub](https://github.com/mpatfield/homebridge-easy-mqtt) if you're finding it useful!
16+
1417
## 1.5.16 (2026-05-25)
1518

1619
### Added

config.schema.template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@
202202
"minimumDuration": {
203203
"type": "integer",
204204
"title": "${config.title.minimumDuration}",
205-
"minimum": 5
205+
"minimum": 1
206206
},
207207
"maximumDuration": {
208208
"type": "integer",
209209
"title": "${config.title.maximumDuration}",
210-
"minimum": 5
210+
"minimum": 1
211211
},
212212
"simulateDuration": {
213213
"type": "boolean",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Homebridge Easy MQTT",
55
"description": "Homebridge plugin for MQTT devices",
66
"type": "module",
7-
"version": "1.5.17-beta.1",
7+
"version": "1.5.17-beta.2",
88
"homepage": "https://github.com/mpatfield/homebridge-easy-mqtt#readme",
99
"repository": {
1010
"type": "git",

src/accessory/abstract/common.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export abstract class Common<C extends Assertable> {
3737
public teardown() {
3838
if (this.timeout !== undefined && this.timeoutCallback !== undefined) {
3939
this.log.warning(strings.autoReset.teardown, this.name);
40-
clearTimeout(this.timeout);
4140
this.timeoutCallback();
41+
this.stopTimeout();
4242
}
4343
}
4444

@@ -553,9 +553,7 @@ export abstract class Common<C extends Assertable> {
553553
this.logIfDesired(strings.autoReset.reset);
554554
}
555555

556-
clearTimeout(this.timeout);
557-
this.timeout = undefined;
558-
this.timeoutCallback = undefined;
556+
this.stopTimeout();
559557

560558
if (config === undefined) {
561559

@@ -602,6 +600,12 @@ export abstract class Common<C extends Assertable> {
602600
this.logIfDesired(string, config.time.toString());
603601
}
604602

603+
protected stopTimeout() {
604+
clearTimeout(this.timeout);
605+
this.timeout = undefined;
606+
this.timeoutCallback = undefined;
607+
}
608+
605609
protected logIfDesired(message: string, ...parameters: string[]): void;
606610
protected logIfDesired(level: LogType, message: string, ...parameters: string[]): void;
607611
protected logIfDesired(levelOrMessage: LogType | string, ...rest: string[]) {

src/accessory/valve.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ValveAccessory extends BaseAccessory<ValveConfig> {
5858
dependency.log.warning(strings.valve.durationTopicsIgnored, this.name, `(${durationTopics.join(', ')})`);
5959
}
6060

61-
this.setupTopicless(HKCharacteristicKey.SetDuration, minimumDuration)?.setProps( {
61+
this.setupTopicless(HKCharacteristicKey.SetDuration, minimumDuration, ()=>{})?.setProps( {
6262
minValue: minimumDuration,
6363
maxValue: maximumDuration,
6464
});
@@ -98,8 +98,13 @@ export class ValveAccessory extends BaseAccessory<ValveConfig> {
9898

9999
override onUpdate(key: HKCharacteristicKey, value: CharacteristicValue, logString: string | undefined = undefined): boolean {
100100

101-
if (this.simulateDuration && key === HKCharacteristicKey.InUse && value === this.Characteristic.InUse.IN_USE) {
102-
this.startTimerSimulator();
101+
if (this.simulateDuration && key === HKCharacteristicKey.InUse) {
102+
103+
if (value === this.Characteristic.InUse.IN_USE) {
104+
this.startTimerSimulator();
105+
} else if (value === this.Characteristic.InUse.NOT_IN_USE) {
106+
this.stopTimerSimulator();
107+
}
103108
}
104109

105110
return super.onUpdate(key, value, logString);
@@ -112,7 +117,7 @@ export class ValveAccessory extends BaseAccessory<ValveConfig> {
112117
}
113118

114119
const remainingSeconds = (this.durationFinishTime - Date.now()) / SECOND;
115-
return Math.max(0, remainingSeconds);
120+
return Math.max(0, Math.ceil(remainingSeconds));
116121
}
117122

118123
private startTimerSimulator() {
@@ -150,6 +155,12 @@ export class ValveAccessory extends BaseAccessory<ValveConfig> {
150155
this.onUpdateNumeric(HKCharacteristicKey.RemainingDuration, duration);
151156
}
152157

158+
private stopTimerSimulator() {
159+
this.durationFinishTime = undefined;
160+
this.onUpdateNumeric(HKCharacteristicKey.RemainingDuration, 0);
161+
this.stopTimeout();
162+
}
163+
153164
private toValveTypeCV(value: ValveType | undefined): CharacteristicValue {
154165

155166
if (value === undefined) {

0 commit comments

Comments
 (0)