@riddix/hamh 2.1.0-alpha.841 → 2.1.0-alpha.842

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.
@@ -163276,6 +163276,15 @@ function clearPendingTilt(st) {
163276
163276
  st.pendingTilt = null;
163277
163277
  }
163278
163278
  var coverOptimistic = /* @__PURE__ */ new WeakMap();
163279
+ function haRestEnd(action) {
163280
+ if (action.action.includes("open_cover")) {
163281
+ return "open";
163282
+ }
163283
+ if (action.action.includes("close_cover")) {
163284
+ return "close";
163285
+ }
163286
+ return null;
163287
+ }
163279
163288
  function getCoverOptimistic(endpoint) {
163280
163289
  let st = coverOptimistic.get(endpoint);
163281
163290
  if (!st) {
@@ -163390,7 +163399,10 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163390
163399
  if (!entry) {
163391
163400
  return MovementStatus.Stopped;
163392
163401
  }
163393
- const reachedTarget = positionAware && current100ths != null && existingTarget != null && Math.abs(current100ths - existingTarget) < 100;
163402
+ const getExpected = config11.getExpectedRestPosition;
163403
+ const expectedPercent = entry.expectedRestEnd != null && getExpected != null ? getExpected(entry.expectedRestEnd, this.agent) : null;
163404
+ const goal = expectedPercent != null ? expectedPercent * 100 : existingTarget;
163405
+ const reachedTarget = positionAware && current100ths != null && goal != null && Math.abs(current100ths - goal) < 100;
163394
163406
  const expired = Date.now() - entry.startedAt >= optimisticMovementTimeoutMs;
163395
163407
  if (reachedTarget || expired) {
163396
163408
  clearOptimisticAxis(optimistic, axis);
@@ -163495,7 +163507,7 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163495
163507
  }
163496
163508
  // Record the optimistic direction and emit it now so a controller gets the
163497
163509
  // moving->stopped edge even when HA never reports a transitional state (#429).
163498
- startOptimisticMovement(axis, status3) {
163510
+ startOptimisticMovement(axis, status3, expectedRestEnd) {
163499
163511
  const optimistic = getCoverOptimistic(this.endpoint);
163500
163512
  clearOptimisticAxis(optimistic, axis);
163501
163513
  const endpoint = this.endpoint;
@@ -163540,7 +163552,7 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163540
163552
  })();
163541
163553
  }, optimisticMovementTimeoutMs);
163542
163554
  timer.unref?.();
163543
- optimistic[axis] = { status: status3, startedAt, timer };
163555
+ optimistic[axis] = { status: status3, startedAt, timer, expectedRestEnd };
163544
163556
  this.writeOperationalStatus({ [axis]: status3 });
163545
163557
  }
163546
163558
  async handleMovement(type, _, direction, targetPercent100ths) {
@@ -163599,17 +163611,25 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163599
163611
  }
163600
163612
  handleLiftOpen() {
163601
163613
  clearPendingLift(getCoverDebounce(this.endpoint));
163602
- this.startOptimisticMovement("lift", MovementStatus.Opening);
163603
163614
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163604
163615
  const action = this.state.config.openCoverLift(void 0, this.agent);
163616
+ this.startOptimisticMovement(
163617
+ "lift",
163618
+ MovementStatus.Opening,
163619
+ haRestEnd(action)
163620
+ );
163605
163621
  logger218.info(`handleLiftOpen: calling action=${action.action}`);
163606
163622
  homeAssistant.callAction(action);
163607
163623
  }
163608
163624
  handleLiftClose() {
163609
163625
  clearPendingLift(getCoverDebounce(this.endpoint));
163610
- this.startOptimisticMovement("lift", MovementStatus.Closing);
163611
163626
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163612
163627
  const action = this.state.config.closeCoverLift(void 0, this.agent);
163628
+ this.startOptimisticMovement(
163629
+ "lift",
163630
+ MovementStatus.Closing,
163631
+ haRestEnd(action)
163632
+ );
163613
163633
  logger218.info(`handleLiftClose: calling action=${action.action}`);
163614
163634
  homeAssistant.callAction(action);
163615
163635
  }
@@ -163620,14 +163640,15 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163620
163640
  return;
163621
163641
  }
163622
163642
  this.state.targetPositionLiftPercent100ths = targetPercent100ths;
163623
- this.startOptimisticMovement(
163624
- "lift",
163625
- currentPositionMatter != null && targetPercent100ths < currentPositionMatter ? MovementStatus.Opening : MovementStatus.Closing
163626
- );
163627
163643
  const targetPosition = targetPercent100ths / 100;
163628
163644
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163629
163645
  const action = config11.setLiftPosition(targetPosition, this.agent);
163630
163646
  const entityId = homeAssistant.entityId;
163647
+ this.startOptimisticMovement(
163648
+ "lift",
163649
+ currentPositionMatter != null && targetPercent100ths < currentPositionMatter ? MovementStatus.Opening : MovementStatus.Closing,
163650
+ haRestEnd(action)
163651
+ );
163631
163652
  const actions = this.env.get(HomeAssistantActions);
163632
163653
  const st = getCoverDebounce(this.endpoint);
163633
163654
  st.pendingLift = { action, entityId, actions };
@@ -163660,21 +163681,27 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163660
163681
  const st = getCoverDebounce(this.endpoint);
163661
163682
  clearPendingTilt(st);
163662
163683
  if (st.pendingLift?.action.action.includes("tilt")) clearPendingLift(st);
163663
- this.startOptimisticMovement("tilt", MovementStatus.Opening);
163664
- const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163665
- homeAssistant.callAction(
163666
- this.state.config.openCoverTilt(void 0, this.agent)
163684
+ const action = this.state.config.openCoverTilt(void 0, this.agent);
163685
+ this.startOptimisticMovement(
163686
+ "tilt",
163687
+ MovementStatus.Opening,
163688
+ haRestEnd(action)
163667
163689
  );
163690
+ const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163691
+ homeAssistant.callAction(action);
163668
163692
  }
163669
163693
  handleTiltClose() {
163670
163694
  const st = getCoverDebounce(this.endpoint);
163671
163695
  clearPendingTilt(st);
163672
163696
  if (st.pendingLift?.action.action.includes("tilt")) clearPendingLift(st);
163673
- this.startOptimisticMovement("tilt", MovementStatus.Closing);
163674
- const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163675
- homeAssistant.callAction(
163676
- this.state.config.closeCoverTilt(void 0, this.agent)
163697
+ const action = this.state.config.closeCoverTilt(void 0, this.agent);
163698
+ this.startOptimisticMovement(
163699
+ "tilt",
163700
+ MovementStatus.Closing,
163701
+ haRestEnd(action)
163677
163702
  );
163703
+ const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163704
+ homeAssistant.callAction(action);
163678
163705
  }
163679
163706
  handleGoToTiltPosition(targetPercent100ths) {
163680
163707
  const config11 = this.state.config;
@@ -163683,14 +163710,15 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
163683
163710
  return;
163684
163711
  }
163685
163712
  this.state.targetPositionTiltPercent100ths = targetPercent100ths;
163686
- this.startOptimisticMovement(
163687
- "tilt",
163688
- currentPositionMatter != null && targetPercent100ths < currentPositionMatter ? MovementStatus.Opening : MovementStatus.Closing
163689
- );
163690
163713
  const targetPosition = targetPercent100ths / 100;
163691
163714
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
163692
163715
  const action = config11.setTiltPosition(targetPosition, this.agent);
163693
163716
  const entityId = homeAssistant.entityId;
163717
+ this.startOptimisticMovement(
163718
+ "tilt",
163719
+ currentPositionMatter != null && targetPercent100ths < currentPositionMatter ? MovementStatus.Opening : MovementStatus.Closing,
163720
+ haRestEnd(action)
163721
+ );
163694
163722
  const actions = this.env.get(HomeAssistantActions);
163695
163723
  const st = getCoverDebounce(this.endpoint);
163696
163724
  st.pendingTilt = { action, entityId, actions };
@@ -163832,6 +163860,7 @@ var adjustPositionForWriting2 = (position, agent) => {
163832
163860
  const matterSem = usesMatterSemantics(agent);
163833
163861
  return adjustPositionForWriting(position, featureFlags, matterSem);
163834
163862
  };
163863
+ var expectedRestPosition = (end, agent) => adjustPositionForReading2(end === "open" ? 100 : 0, agent);
163835
163864
  var shouldSwapOpenClose = (agent) => {
163836
163865
  const homeAssistant = agent.get(HomeAssistantEntityBehavior);
163837
163866
  const entitySwap = homeAssistant.state.mapping?.coverSwapOpenClose;
@@ -163919,11 +163948,11 @@ var config6 = {
163919
163948
  }
163920
163949
  return position == null ? null : adjustPositionForReading2(position, agent);
163921
163950
  },
163951
+ getExpectedRestPosition: expectedRestPosition,
163922
163952
  getCoverType: (entity) => deviceClassMapping(entity)?.type,
163923
163953
  getEndProductType: (entity) => deviceClassMapping(entity)?.endProductType,
163924
163954
  getMovementStatus: (entity, agent) => {
163925
- const { featureFlags } = agent.env.get(BridgeDataProvider);
163926
- const swapped = featureFlags?.coverSwapOpenClose === true;
163955
+ const swapped = shouldSwapOpenClose(agent);
163927
163956
  const coverState = entity.state;
163928
163957
  if (coverState === CoverDeviceState.opening) {
163929
163958
  return swapped ? WindowCovering3.MovementStatus.Closing : WindowCovering3.MovementStatus.Opening;