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

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,6 +172123,7 @@ 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 {
@@ -172145,25 +172146,43 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172145
172146
  this.triggerPress(eventType);
172146
172147
  }
172147
172148
  triggerPress(eventType) {
172148
- const pressCount = this.getPressCount(eventType);
172149
+ const lower = eventType.toLowerCase();
172150
+ if (this.isLongPress(lower)) {
172151
+ this.state.currentPosition = 1;
172152
+ this.events.initialPress?.emit({ newPosition: 1 }, this.context);
172153
+ this.events.longPress?.emit({ newPosition: 1 }, this.context);
172154
+ this.fireBridgeEvent(eventType, 1);
172155
+ return;
172156
+ }
172157
+ if (this.isLongRelease(lower)) {
172158
+ this.events.longRelease?.emit({ previousPosition: 1 }, this.context);
172159
+ this.state.currentPosition = 0;
172160
+ this.fireBridgeEvent(eventType, 1);
172161
+ return;
172162
+ }
172163
+ if (lower.includes("cont") && lower.includes("press")) {
172164
+ return;
172165
+ }
172166
+ const pressCount = this.getPressCount(lower);
172149
172167
  this.state.currentPosition = 1;
172150
172168
  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
172169
  setTimeout(
172161
172170
  this.callback(() => {
172162
172171
  this.events.shortRelease?.emit({ previousPosition: 1 }, this.context);
172163
172172
  this.state.currentPosition = 0;
172173
+ this.events.multiPressComplete?.emit(
172174
+ {
172175
+ previousPosition: 0,
172176
+ totalNumberOfPressesCounted: pressCount
172177
+ },
172178
+ this.context
172179
+ );
172164
172180
  }),
172165
172181
  100
172166
172182
  );
172183
+ this.fireBridgeEvent(eventType, pressCount);
172184
+ }
172185
+ fireBridgeEvent(eventType, pressCount) {
172167
172186
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
172168
172187
  homeAssistant.fireEvent("hamh_action", {
172169
172188
  action: "press",
@@ -172172,8 +172191,13 @@ var GenericSwitchServerBase = class extends FeaturedBase7 {
172172
172191
  source: "matter_bridge"
172173
172192
  });
172174
172193
  }
172175
- getPressCount(eventType) {
172176
- const lower = eventType.toLowerCase();
172194
+ isLongPress(lower) {
172195
+ return lower.includes("long") && !lower.includes("release") || lower === "hold";
172196
+ }
172197
+ isLongRelease(lower) {
172198
+ return lower.includes("long") && lower.includes("release");
172199
+ }
172200
+ getPressCount(lower) {
172177
172201
  if (lower.includes("triple") || lower.includes("3_press") || lower.includes("three")) {
172178
172202
  return 3;
172179
172203
  }