@riddix/hamh 2.1.0-alpha.440 → 2.1.0-alpha.442

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.
@@ -166145,6 +166145,8 @@ init_home_assistant_entity_behavior();
166145
166145
  init_esm();
166146
166146
  init_home_assistant_entity_behavior();
166147
166147
  var lastTurnOnTimestamps = /* @__PURE__ */ new Map();
166148
+ var optimisticLevelTimestamps = /* @__PURE__ */ new Map();
166149
+ var OPTIMISTIC_LEVEL_COOLDOWN_MS = 2e3;
166148
166150
  function notifyLightTurnedOn(entityId) {
166149
166151
  lastTurnOnTimestamps.set(entityId, Date.now());
166150
166152
  }
@@ -166189,6 +166191,11 @@ var LevelControlServerBase = class extends FeaturedBase4 {
166189
166191
  if (currentLevel != null) {
166190
166192
  currentLevel = Math.min(Math.max(minLevel, currentLevel), maxLevel);
166191
166193
  }
166194
+ const lastOptimistic = optimisticLevelTimestamps.get(entity.entity_id);
166195
+ const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_LEVEL_COOLDOWN_MS;
166196
+ if (inCooldown && currentLevel != null) {
166197
+ currentLevel = null;
166198
+ }
166192
166199
  applyPatchState(this.state, {
166193
166200
  minLevel,
166194
166201
  maxLevel,
@@ -166256,6 +166263,7 @@ var LevelControlServerBase = class extends FeaturedBase4 {
166256
166263
  };
166257
166264
  }
166258
166265
  this.state.currentLevel = level;
166266
+ optimisticLevelTimestamps.set(entityId, Date.now());
166259
166267
  homeAssistant.callAction(action);
166260
166268
  }
166261
166269
  };
@@ -168633,9 +168641,9 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
168633
168641
  `handleMovement: type=${MovementType[type]}, direction=${MovementDirection[direction]}, target=${targetPercent100ths}, currentLift=${currentLift}, currentTilt=${currentTilt}, absolutePosition=${this.features.absolutePosition}`
168634
168642
  );
168635
168643
  if (type === MovementType.Lift) {
168636
- if (direction === MovementDirection.Open && (targetPercent100ths == null || targetPercent100ths === 0)) {
168644
+ if (targetPercent100ths === 0) {
168637
168645
  this.handleLiftOpen();
168638
- } else if (direction === MovementDirection.Close && (targetPercent100ths == null || targetPercent100ths === 1e4)) {
168646
+ } else if (targetPercent100ths === 1e4) {
168639
168647
  this.handleLiftClose();
168640
168648
  } else if (targetPercent100ths != null && this.features.absolutePosition) {
168641
168649
  this.handleGoToLiftPosition(targetPercent100ths);
@@ -168645,9 +168653,9 @@ var WindowCoveringServerBase = class _WindowCoveringServerBase extends FeaturedB
168645
168653
  this.handleLiftClose();
168646
168654
  }
168647
168655
  } else if (type === MovementType.Tilt) {
168648
- if (direction === MovementDirection.Open && (targetPercent100ths == null || targetPercent100ths === 0)) {
168656
+ if (targetPercent100ths === 0) {
168649
168657
  this.handleTiltOpen();
168650
- } else if (direction === MovementDirection.Close && (targetPercent100ths == null || targetPercent100ths === 1e4)) {
168658
+ } else if (targetPercent100ths === 1e4) {
168651
168659
  this.handleTiltClose();
168652
168660
  } else if (targetPercent100ths != null && this.features.absolutePosition) {
168653
168661
  this.handleGoToTiltPosition(targetPercent100ths);
@@ -169344,6 +169352,8 @@ init_nodejs();
169344
169352
  // src/matter/behaviors/color-control-server.ts
169345
169353
  init_home_assistant_entity_behavior();
169346
169354
  var logger170 = Logger.get("ColorControlServer");
169355
+ var optimisticColorTimestamps = /* @__PURE__ */ new Map();
169356
+ var OPTIMISTIC_COLOR_COOLDOWN_MS = 2e3;
169347
169357
  var FeaturedBase7 = ColorControlServer.with("ColorTemperature", "HueSaturation");
169348
169358
  var ColorControlServerBase = class extends FeaturedBase7 {
169349
169359
  pendingTransitionTime;
@@ -169422,6 +169432,8 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169422
169432
  const newColorMode = this.getColorModeFromFeatures(
169423
169433
  config10.getCurrentMode(entity.state, this.agent)
169424
169434
  );
169435
+ const lastOptimistic = optimisticColorTimestamps.get(entity.entity_id);
169436
+ const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_COLOR_COOLDOWN_MS;
169425
169437
  if (this.features.colorTemperature) {
169426
169438
  const existingMireds = this.state.colorTemperatureMireds;
169427
169439
  if (existingMireds != null) {
@@ -169446,12 +169458,12 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169446
169458
  applyPatchState(this.state, {
169447
169459
  coupleColorTempToLevelMinMireds: minMireds,
169448
169460
  startUpColorTemperatureMireds: startUpMireds,
169449
- colorTemperatureMireds: effectiveMireds
169461
+ ...inCooldown ? {} : { colorTemperatureMireds: effectiveMireds }
169450
169462
  });
169451
169463
  }
169452
169464
  applyPatchState(this.state, {
169453
- colorMode: newColorMode,
169454
- ...this.features.hueSaturation ? {
169465
+ ...inCooldown ? {} : { colorMode: newColorMode },
169466
+ ...this.features.hueSaturation && !inCooldown ? {
169455
169467
  currentHue: hue,
169456
169468
  currentSaturation: saturation
169457
169469
  } : {}
@@ -169478,6 +169490,7 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169478
169490
  colorTemperatureMireds: targetMireds,
169479
169491
  colorMode: ColorControl3.ColorMode.ColorTemperatureMireds
169480
169492
  });
169493
+ optimisticColorTimestamps.set(homeAssistant.entityId, Date.now());
169481
169494
  homeAssistant.callAction(action);
169482
169495
  }
169483
169496
  moveToHueLogic(targetHue) {
@@ -169508,6 +169521,7 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169508
169521
  currentSaturation: targetSaturation,
169509
169522
  colorMode: ColorControl3.ColorMode.CurrentHueAndCurrentSaturation
169510
169523
  });
169524
+ optimisticColorTimestamps.set(homeAssistant.entityId, Date.now());
169511
169525
  homeAssistant.callAction(action);
169512
169526
  }
169513
169527
  applyTransition(action) {
@@ -170811,6 +170825,8 @@ init_home_assistant_entity_behavior();
170811
170825
  init_esm();
170812
170826
  init_home_assistant_entity_behavior();
170813
170827
  var logger175 = Logger.get("SpeakerLevelControlServer");
170828
+ var optimisticLevelTimestamps2 = /* @__PURE__ */ new Map();
170829
+ var OPTIMISTIC_LEVEL_COOLDOWN_MS2 = 2e3;
170814
170830
  var FeaturedBase9 = LevelControlServer.with("OnOff");
170815
170831
  var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
170816
170832
  async initialize() {
@@ -170846,10 +170862,15 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
170846
170862
  logger175.debug(
170847
170863
  `[${entityId}] Volume update: HA=${currentLevelPercent != null ? Math.round(currentLevelPercent * 100) : "null"}% -> currentLevel=${currentLevel}`
170848
170864
  );
170865
+ const lastOptimistic = optimisticLevelTimestamps2.get(entity.entity_id);
170866
+ const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_LEVEL_COOLDOWN_MS2;
170867
+ if (inCooldown && currentLevel != null) {
170868
+ currentLevel = null;
170869
+ }
170849
170870
  applyPatchState(this.state, {
170850
170871
  minLevel,
170851
170872
  maxLevel,
170852
- currentLevel
170873
+ ...currentLevel != null ? { currentLevel } : {}
170853
170874
  });
170854
170875
  }
170855
170876
  async moveToLevel(request) {
@@ -170892,6 +170913,7 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
170892
170913
  return;
170893
170914
  }
170894
170915
  this.state.currentLevel = level;
170916
+ optimisticLevelTimestamps2.set(entityId, Date.now());
170895
170917
  homeAssistant.callAction(
170896
170918
  config10.moveToLevelPercent(levelPercent, this.agent)
170897
170919
  );