@riddix/hamh 2.1.0-alpha.579 → 2.1.0-alpha.581

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -172127,11 +172127,17 @@ var FeaturedBase7 = SwitchServer.with(
172127
172127
  "MomentarySwitchMultiPress"
172128
172128
  );
172129
172129
  var GenericSwitchServerBase = class extends FeaturedBase7 {
172130
+ inLongPress = false;
172130
172131
  async initialize() {
172131
172132
  await super.initialize();
172132
172133
  const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
172133
172134
  const entityId = homeAssistant.entityId;
172134
- logger180.debug(`[${entityId}] GenericSwitch initialized`);
172135
+ const attrs = homeAssistant.entity.state.attributes;
172136
+ const maxPress = this.detectMultiPressMax(attrs.event_types ?? []);
172137
+ this.state.multiPressMax = maxPress;
172138
+ logger180.debug(
172139
+ `[${entityId}] GenericSwitch initialized (multiPressMax: ${maxPress})`
172140
+ );
172135
172141
  this.reactTo(homeAssistant.onChange, this.handleEventChange);
172136
172142
  }
172137
172143
  handleEventChange() {
@@ -172148,6 +172154,7 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172148
172154
  triggerPress(eventType) {
172149
172155
  const lower = eventType.toLowerCase();
172150
172156
  if (this.isLongPress(lower)) {
172157
+ this.inLongPress = true;
172151
172158
  this.state.currentPosition = 1;
172152
172159
  this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172153
172160
  this.events.longPress?.emit({ newPosition: 1 }, this.context);
@@ -172155,8 +172162,14 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172155
172162
  return;
172156
172163
  }
172157
172164
  if (this.isLongRelease(lower)) {
172158
- this.events.longRelease?.emit({ previousPosition: 1 }, this.context);
172165
+ if (!this.inLongPress) {
172166
+ this.state.currentPosition = 1;
172167
+ this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172168
+ this.events.longPress?.emit({ newPosition: 1 }, this.context);
172169
+ }
172170
+ this.inLongPress = false;
172159
172171
  this.state.currentPosition = 0;
172172
+ this.events.longRelease?.emit({ previousPosition: 1 }, this.context);
172160
172173
  this.fireBridgeEvent(eventType, 1);
172161
172174
  return;
172162
172175
  }
@@ -172166,19 +172179,14 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172166
172179
  const pressCount = this.getPressCount(lower);
172167
172180
  this.state.currentPosition = 1;
172168
172181
  this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172169
- setTimeout(
172170
- this.callback(() => {
172171
- this.events.shortRelease?.emit({ previousPosition: 1 }, this.context);
172172
- this.state.currentPosition = 0;
172173
- this.events.multiPressComplete?.emit(
172174
- {
172175
- previousPosition: 0,
172176
- totalNumberOfPressesCounted: pressCount
172177
- },
172178
- this.context
172179
- );
172180
- }),
172181
- 100
172182
+ this.state.currentPosition = 0;
172183
+ this.events.shortRelease?.emit({ previousPosition: 1 }, this.context);
172184
+ this.events.multiPressComplete?.emit(
172185
+ {
172186
+ previousPosition: 0,
172187
+ totalNumberOfPressesCounted: pressCount
172188
+ },
172189
+ this.context
172182
172190
  );
172183
172191
  this.fireBridgeEvent(eventType, pressCount);
172184
172192
  }
@@ -172197,6 +172205,14 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172197
172205
  isLongRelease(lower) {
172198
172206
  return lower.includes("long") && lower.includes("release");
172199
172207
  }
172208
+ detectMultiPressMax(eventTypes) {
172209
+ let max = 1;
172210
+ for (const et of eventTypes) {
172211
+ const count = this.getPressCount(et.toLowerCase());
172212
+ if (count > max) max = count;
172213
+ }
172214
+ return max;
172215
+ }
172200
172216
  getPressCount(lower) {
172201
172217
  if (lower.includes("triple") || lower.includes("3_press") || lower.includes("three")) {
172202
172218
  return 3;
@@ -179122,6 +179138,7 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
179122
179138
  lastState;
179123
179139
  pendingMappedChange = false;
179124
179140
  flushUpdate;
179141
+ eventUpdateChain = Promise.resolve();
179125
179142
  async delete() {
179126
179143
  this.flushUpdate.clear();
179127
179144
  await super.delete();
@@ -179142,6 +179159,12 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
179142
179159
  `State update received for ${this.entityId}: state=${state.state}`
179143
179160
  );
179144
179161
  this.lastState = state;
179162
+ if (this.entityId.startsWith("event.")) {
179163
+ this.eventUpdateChain = this.eventUpdateChain.then(
179164
+ () => this.flushPendingUpdate(state)
179165
+ );
179166
+ return;
179167
+ }
179145
179168
  this.flushUpdate(state);
179146
179169
  }
179147
179170
  async flushPendingUpdate(state) {