@riddix/hamh 2.1.0-alpha.578 → 2.1.0-alpha.580

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.
@@ -172123,9 +172123,11 @@ var logger180 = Logger.get("GenericSwitchServer");
172123
172123
  var FeaturedBase7 = SwitchServer.with(
172124
172124
  "MomentarySwitch",
172125
172125
  "MomentarySwitchRelease",
172126
+ "MomentarySwitchLongPress",
172126
172127
  "MomentarySwitchMultiPress"
172127
172128
  );
172128
172129
  var GenericSwitchServerBase = class extends FeaturedBase7 {
172130
+ inLongPress = false;
172129
172131
  async initialize() {
172130
172132
  await super.initialize();
172131
172133
  const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
@@ -172145,25 +172147,45 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172145
172147
  this.triggerPress(eventType);
172146
172148
  }
172147
172149
  triggerPress(eventType) {
172148
- const pressCount = this.getPressCount(eventType);
172150
+ const lower = eventType.toLowerCase();
172151
+ if (this.isLongPress(lower)) {
172152
+ this.inLongPress = true;
172153
+ this.state.currentPosition = 1;
172154
+ this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172155
+ this.events.longPress?.emit({ newPosition: 1 }, this.context);
172156
+ this.fireBridgeEvent(eventType, 1);
172157
+ return;
172158
+ }
172159
+ if (this.isLongRelease(lower)) {
172160
+ if (!this.inLongPress) {
172161
+ this.state.currentPosition = 1;
172162
+ this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172163
+ this.events.longPress?.emit({ newPosition: 1 }, this.context);
172164
+ }
172165
+ this.inLongPress = false;
172166
+ this.state.currentPosition = 0;
172167
+ this.events.longRelease?.emit({ previousPosition: 1 }, this.context);
172168
+ this.fireBridgeEvent(eventType, 1);
172169
+ return;
172170
+ }
172171
+ if (lower.includes("cont") && lower.includes("press")) {
172172
+ return;
172173
+ }
172174
+ const pressCount = this.getPressCount(lower);
172149
172175
  this.state.currentPosition = 1;
172150
172176
  this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172151
- if (pressCount > 1) {
172152
- this.events.multiPressComplete?.emit(
172153
- {
172154
- previousPosition: 0,
172155
- totalNumberOfPressesCounted: pressCount
172156
- },
172157
- this.context
172158
- );
172159
- }
172160
- setTimeout(
172161
- this.callback(() => {
172162
- this.events.shortRelease?.emit({ previousPosition: 1 }, this.context);
172163
- this.state.currentPosition = 0;
172164
- }),
172165
- 100
172177
+ this.state.currentPosition = 0;
172178
+ this.events.shortRelease?.emit({ previousPosition: 1 }, this.context);
172179
+ this.events.multiPressComplete?.emit(
172180
+ {
172181
+ previousPosition: 0,
172182
+ totalNumberOfPressesCounted: pressCount
172183
+ },
172184
+ this.context
172166
172185
  );
172186
+ this.fireBridgeEvent(eventType, pressCount);
172187
+ }
172188
+ fireBridgeEvent(eventType, pressCount) {
172167
172189
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
172168
172190
  homeAssistant.fireEvent("hamh_action", {
172169
172191
  action: "press",
@@ -172172,8 +172194,13 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172172
172194
  source: "matter_bridge"
172173
172195
  });
172174
172196
  }
172175
- getPressCount(eventType) {
172176
- const lower = eventType.toLowerCase();
172197
+ isLongPress(lower) {
172198
+ return lower.includes("long") && !lower.includes("release") || lower === "hold";
172199
+ }
172200
+ isLongRelease(lower) {
172201
+ return lower.includes("long") && lower.includes("release");
172202
+ }
172203
+ getPressCount(lower) {
172177
172204
  if (lower.includes("triple") || lower.includes("3_press") || lower.includes("three")) {
172178
172205
  return 3;
172179
172206
  }
@@ -179098,6 +179125,7 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
179098
179125
  lastState;
179099
179126
  pendingMappedChange = false;
179100
179127
  flushUpdate;
179128
+ eventUpdateChain = Promise.resolve();
179101
179129
  async delete() {
179102
179130
  this.flushUpdate.clear();
179103
179131
  await super.delete();
@@ -179118,6 +179146,12 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
179118
179146
  `State update received for ${this.entityId}: state=${state.state}`
179119
179147
  );
179120
179148
  this.lastState = state;
179149
+ if (this.entityId.startsWith("event.")) {
179150
+ this.eventUpdateChain = this.eventUpdateChain.then(
179151
+ () => this.flushPendingUpdate(state)
179152
+ );
179153
+ return;
179154
+ }
179121
179155
  this.flushUpdate(state);
179122
179156
  }
179123
179157
  async flushPendingUpdate(state) {