@riddix/hamh 2.1.0-alpha.808 → 2.1.0-alpha.810

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.
@@ -154537,19 +154537,27 @@ var FeaturedBase6 = WindowCoveringServer.with(
154537
154537
  "Tilt",
154538
154538
  "PositionAwareTilt"
154539
154539
  );
154540
+ var coverDebounce = /* @__PURE__ */ new WeakMap();
154541
+ function getCoverDebounce(endpoint) {
154542
+ let st = coverDebounce.get(endpoint);
154543
+ if (!st) {
154544
+ st = {
154545
+ liftTimer: null,
154546
+ tiltTimer: null,
154547
+ pendingLift: null,
154548
+ pendingTilt: null,
154549
+ lastLiftCommandTime: 0,
154550
+ lastTiltCommandTime: 0
154551
+ };
154552
+ coverDebounce.set(endpoint, st);
154553
+ }
154554
+ return st;
154555
+ }
154540
154556
  var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedBase6 {
154541
- liftDebounceTimer = null;
154542
- tiltDebounceTimer = null;
154543
- // Track when the last command was received to implement two-phase debounce
154544
- lastLiftCommandTime = 0;
154545
- lastTiltCommandTime = 0;
154546
- // Track lift direction to skip redundant tilt on downOrClose / upOrOpen (#246)
154557
+ // Written and read within one synchronous command (upOrOpen fires lift then
154558
+ // tilt on the same instance), so these stay as instance fields (#246).
154547
154559
  lastLiftMovementMs = 0;
154548
154560
  lastLiftMovementDirection = null;
154549
- // Store everything needed for debounced HA calls - entityId and actions service
154550
- // must be captured before setTimeout because agent context expires after command handler
154551
- pendingLiftAction = null;
154552
- pendingTiltAction = null;
154553
154561
  // Two-phase debounce: longer for first command (quick swipe sends initial step value),
154554
154562
  // shorter for subsequent commands during drag
154555
154563
  static DEBOUNCE_INITIAL_MS = 400;
@@ -154568,16 +154576,18 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
154568
154576
  return null;
154569
154577
  }
154570
154578
  async [Symbol.asyncDispose]() {
154571
- if (this.liftDebounceTimer) {
154572
- clearTimeout(this.liftDebounceTimer);
154573
- this.liftDebounceTimer = null;
154574
- }
154575
- if (this.tiltDebounceTimer) {
154576
- clearTimeout(this.tiltDebounceTimer);
154577
- this.tiltDebounceTimer = null;
154579
+ const st = coverDebounce.get(this.endpoint);
154580
+ if (st) {
154581
+ if (st.liftTimer) {
154582
+ clearTimeout(st.liftTimer);
154583
+ }
154584
+ if (st.tiltTimer) {
154585
+ clearTimeout(st.tiltTimer);
154586
+ }
154587
+ st.pendingLift = null;
154588
+ st.pendingTilt = null;
154589
+ coverDebounce.delete(this.endpoint);
154578
154590
  }
154579
- this.pendingLiftAction = null;
154580
- this.pendingTiltAction = null;
154581
154591
  await super[Symbol.asyncDispose]();
154582
154592
  }
154583
154593
  async initialize() {
@@ -154767,28 +154777,29 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
154767
154777
  const action = config11.setLiftPosition(targetPosition, this.agent);
154768
154778
  const entityId = homeAssistant.entityId;
154769
154779
  const actions = this.env.get(HomeAssistantActions);
154770
- this.pendingLiftAction = { action, entityId, actions };
154780
+ const st = getCoverDebounce(this.endpoint);
154781
+ st.pendingLift = { action, entityId, actions };
154771
154782
  const now = Date.now();
154772
- const timeSinceLastCommand = now - this.lastLiftCommandTime;
154773
- this.lastLiftCommandTime = now;
154783
+ const timeSinceLastCommand = now - st.lastLiftCommandTime;
154784
+ st.lastLiftCommandTime = now;
154774
154785
  const isFirstInSequence = timeSinceLastCommand > _WindowCoveringServerBase.COMMAND_SEQUENCE_THRESHOLD_MS;
154775
154786
  const overrideMs = this.resolveDebounceOverride(homeAssistant);
154776
154787
  const debounceMs = overrideMs != null ? overrideMs : isFirstInSequence ? _WindowCoveringServerBase.DEBOUNCE_INITIAL_MS : _WindowCoveringServerBase.DEBOUNCE_SUBSEQUENT_MS;
154777
154788
  logger206.debug(
154778
154789
  `Lift command: target=${targetPosition}%, debounce=${debounceMs}ms (${overrideMs != null ? "override" : isFirstInSequence ? "initial" : "subsequent"})`
154779
154790
  );
154780
- if (this.liftDebounceTimer) {
154781
- clearTimeout(this.liftDebounceTimer);
154791
+ if (st.liftTimer) {
154792
+ clearTimeout(st.liftTimer);
154782
154793
  }
154783
- this.liftDebounceTimer = setTimeout(() => {
154784
- this.liftDebounceTimer = null;
154785
- if (this.pendingLiftAction) {
154794
+ st.liftTimer = setTimeout(() => {
154795
+ st.liftTimer = null;
154796
+ if (st.pendingLift) {
154786
154797
  const {
154787
154798
  action: pendingAction,
154788
154799
  entityId: eid,
154789
154800
  actions: act
154790
- } = this.pendingLiftAction;
154791
- this.pendingLiftAction = null;
154801
+ } = st.pendingLift;
154802
+ st.pendingLift = null;
154792
154803
  act.call(pendingAction, eid);
154793
154804
  }
154794
154805
  }, debounceMs);
@@ -154817,28 +154828,29 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
154817
154828
  const action = config11.setTiltPosition(targetPosition, this.agent);
154818
154829
  const entityId = homeAssistant.entityId;
154819
154830
  const actions = this.env.get(HomeAssistantActions);
154820
- this.pendingTiltAction = { action, entityId, actions };
154831
+ const st = getCoverDebounce(this.endpoint);
154832
+ st.pendingTilt = { action, entityId, actions };
154821
154833
  const now = Date.now();
154822
- const timeSinceLastCommand = now - this.lastTiltCommandTime;
154823
- this.lastTiltCommandTime = now;
154834
+ const timeSinceLastCommand = now - st.lastTiltCommandTime;
154835
+ st.lastTiltCommandTime = now;
154824
154836
  const isFirstInSequence = timeSinceLastCommand > _WindowCoveringServerBase.COMMAND_SEQUENCE_THRESHOLD_MS;
154825
154837
  const overrideMs = this.resolveDebounceOverride(homeAssistant);
154826
154838
  const debounceMs = overrideMs != null ? overrideMs : isFirstInSequence ? _WindowCoveringServerBase.DEBOUNCE_INITIAL_MS : _WindowCoveringServerBase.DEBOUNCE_SUBSEQUENT_MS;
154827
154839
  logger206.debug(
154828
154840
  `Tilt command: target=${targetPosition}%, debounce=${debounceMs}ms (${overrideMs != null ? "override" : isFirstInSequence ? "initial" : "subsequent"})`
154829
154841
  );
154830
- if (this.tiltDebounceTimer) {
154831
- clearTimeout(this.tiltDebounceTimer);
154842
+ if (st.tiltTimer) {
154843
+ clearTimeout(st.tiltTimer);
154832
154844
  }
154833
- this.tiltDebounceTimer = setTimeout(() => {
154834
- this.tiltDebounceTimer = null;
154835
- if (this.pendingTiltAction) {
154845
+ st.tiltTimer = setTimeout(() => {
154846
+ st.tiltTimer = null;
154847
+ if (st.pendingTilt) {
154836
154848
  const {
154837
154849
  action: pendingAction,
154838
154850
  entityId: eid,
154839
154851
  actions: act
154840
- } = this.pendingTiltAction;
154841
- this.pendingTiltAction = null;
154852
+ } = st.pendingTilt;
154853
+ st.pendingTilt = null;
154842
154854
  act.call(pendingAction, eid);
154843
154855
  }
154844
154856
  }, debounceMs);