@riddix/hamh 2.1.0-alpha.448 → 2.1.0-alpha.450

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.
@@ -166261,8 +166261,9 @@ init_home_assistant_entity_behavior();
166261
166261
  init_esm();
166262
166262
  init_home_assistant_entity_behavior();
166263
166263
  var lastTurnOnTimestamps = /* @__PURE__ */ new Map();
166264
- var optimisticLevelTimestamps = /* @__PURE__ */ new Map();
166265
- var OPTIMISTIC_LEVEL_COOLDOWN_MS = 2e3;
166264
+ var optimisticLevelState = /* @__PURE__ */ new Map();
166265
+ var OPTIMISTIC_TIMEOUT_MS = 3e3;
166266
+ var OPTIMISTIC_TOLERANCE = 5;
166266
166267
  function notifyLightTurnedOn(entityId) {
166267
166268
  lastTurnOnTimestamps.set(entityId, Date.now());
166268
166269
  }
@@ -166307,10 +166308,15 @@ var LevelControlServerBase = class extends FeaturedBase4 {
166307
166308
  if (currentLevel != null) {
166308
166309
  currentLevel = Math.min(Math.max(minLevel, currentLevel), maxLevel);
166309
166310
  }
166310
- const lastOptimistic = optimisticLevelTimestamps.get(entity.entity_id);
166311
- const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_LEVEL_COOLDOWN_MS;
166312
- if (inCooldown && currentLevel != null) {
166313
- currentLevel = null;
166311
+ const optimistic = optimisticLevelState.get(entity.entity_id);
166312
+ if (optimistic != null && currentLevel != null) {
166313
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS) {
166314
+ optimisticLevelState.delete(entity.entity_id);
166315
+ } else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE) {
166316
+ optimisticLevelState.delete(entity.entity_id);
166317
+ } else {
166318
+ currentLevel = null;
166319
+ }
166314
166320
  }
166315
166321
  applyPatchState(this.state, {
166316
166322
  minLevel,
@@ -166379,7 +166385,10 @@ var LevelControlServerBase = class extends FeaturedBase4 {
166379
166385
  };
166380
166386
  }
166381
166387
  this.state.currentLevel = level;
166382
- optimisticLevelTimestamps.set(entityId, Date.now());
166388
+ optimisticLevelState.set(entityId, {
166389
+ expectedLevel: level,
166390
+ timestamp: Date.now()
166391
+ });
166383
166392
  homeAssistant.callAction(action);
166384
166393
  }
166385
166394
  };
@@ -166527,6 +166536,7 @@ function buildEntityPayload(registry2, entityId) {
166527
166536
  }
166528
166537
  var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends Endpoint {
166529
166538
  entityId;
166539
+ mappedEntityIds;
166530
166540
  trackedEntityIds;
166531
166541
  lastStates = /* @__PURE__ */ new Map();
166532
166542
  debouncedFlush;
@@ -166610,11 +166620,13 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166610
166620
  if (config10.temperatureEntityId)
166611
166621
  trackedEntityIds.push(config10.temperatureEntityId);
166612
166622
  if (config10.humidityEntityId) trackedEntityIds.push(config10.humidityEntityId);
166623
+ const mappedIds = trackedEntityIds.filter((id) => id !== primaryEntityId);
166613
166624
  const endpoint = new _ComposedAirPurifierEndpoint(
166614
166625
  parentTypeWithState,
166615
166626
  primaryEntityId,
166616
166627
  endpointId,
166617
- trackedEntityIds
166628
+ trackedEntityIds,
166629
+ mappedIds
166618
166630
  );
166619
166631
  const clusterLabels = [
166620
166632
  "AirPurifier",
@@ -166625,10 +166637,11 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166625
166637
  logger160.info(`Created air purifier ${primaryEntityId}: ${clusterLabels}`);
166626
166638
  return endpoint;
166627
166639
  }
166628
- constructor(type, entityId, id, trackedEntityIds) {
166640
+ constructor(type, entityId, id, trackedEntityIds, mappedEntityIds) {
166629
166641
  super(type, { id });
166630
166642
  this.entityId = entityId;
166631
166643
  this.trackedEntityIds = trackedEntityIds;
166644
+ this.mappedEntityIds = mappedEntityIds;
166632
166645
  }
166633
166646
  async updateStates(states) {
166634
166647
  let anyChanged = false;
@@ -166838,6 +166851,7 @@ function buildEntityPayload2(registry2, entityId) {
166838
166851
  }
166839
166852
  var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166840
166853
  entityId;
166854
+ mappedEntityIds;
166841
166855
  subEndpoints = /* @__PURE__ */ new Map();
166842
166856
  lastStates = /* @__PURE__ */ new Map();
166843
166857
  debouncedUpdates = /* @__PURE__ */ new Map();
@@ -166910,11 +166924,15 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166910
166924
  mapping
166911
166925
  }
166912
166926
  });
166927
+ const mappedIds = [];
166928
+ if (config10.humidityEntityId) mappedIds.push(config10.humidityEntityId);
166929
+ if (config10.pressureEntityId) mappedIds.push(config10.pressureEntityId);
166913
166930
  const endpoint = new _ComposedSensorEndpoint(
166914
166931
  parentTypeWithState,
166915
166932
  primaryEntityId,
166916
166933
  endpointId,
166917
- parts
166934
+ parts,
166935
+ mappedIds
166918
166936
  );
166919
166937
  endpoint.subEndpoints.set(primaryEntityId, tempSub);
166920
166938
  if (config10.humidityEntityId && humSub) {
@@ -166928,9 +166946,10 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166928
166946
  );
166929
166947
  return endpoint;
166930
166948
  }
166931
- constructor(type, entityId, id, parts) {
166949
+ constructor(type, entityId, id, parts, mappedEntityIds) {
166932
166950
  super(type, { id, parts });
166933
166951
  this.entityId = entityId;
166952
+ this.mappedEntityIds = mappedEntityIds;
166934
166953
  }
166935
166954
  async updateStates(states) {
166936
166955
  this.scheduleUpdate(this, this.entityId, states);
@@ -169468,8 +169487,9 @@ init_nodejs();
169468
169487
  // src/matter/behaviors/color-control-server.ts
169469
169488
  init_home_assistant_entity_behavior();
169470
169489
  var logger170 = Logger.get("ColorControlServer");
169471
- var optimisticColorTimestamps = /* @__PURE__ */ new Map();
169472
- var OPTIMISTIC_COLOR_COOLDOWN_MS = 2e3;
169490
+ var optimisticColorState = /* @__PURE__ */ new Map();
169491
+ var OPTIMISTIC_TIMEOUT_MS2 = 3e3;
169492
+ var OPTIMISTIC_TOLERANCE2 = 5;
169473
169493
  var pendingColorStaging = /* @__PURE__ */ new Map();
169474
169494
  function consumePendingColorStaging(entityId) {
169475
169495
  const data = pendingColorStaging.get(entityId);
@@ -169554,8 +169574,29 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169554
169574
  const newColorMode = this.getColorModeFromFeatures(
169555
169575
  config10.getCurrentMode(entity.state, this.agent)
169556
169576
  );
169557
- const lastOptimistic = optimisticColorTimestamps.get(entity.entity_id);
169558
- const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_COLOR_COOLDOWN_MS;
169577
+ const optimistic = optimisticColorState.get(entity.entity_id);
169578
+ let skipColorTemp = false;
169579
+ let skipHueSat = false;
169580
+ if (optimistic != null) {
169581
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS2) {
169582
+ optimisticColorState.delete(entity.entity_id);
169583
+ } else {
169584
+ if (optimistic.colorTemperatureMireds != null && currentMireds != null) {
169585
+ if (Math.abs(currentMireds - optimistic.colorTemperatureMireds) <= OPTIMISTIC_TOLERANCE2) {
169586
+ optimisticColorState.delete(entity.entity_id);
169587
+ } else {
169588
+ skipColorTemp = true;
169589
+ }
169590
+ }
169591
+ if (optimistic.currentHue != null && optimistic.currentSaturation != null) {
169592
+ if (Math.abs(hue - optimistic.currentHue) <= OPTIMISTIC_TOLERANCE2 && Math.abs(saturation - optimistic.currentSaturation) <= OPTIMISTIC_TOLERANCE2) {
169593
+ optimisticColorState.delete(entity.entity_id);
169594
+ } else {
169595
+ skipHueSat = true;
169596
+ }
169597
+ }
169598
+ }
169599
+ }
169559
169600
  if (this.features.colorTemperature) {
169560
169601
  const existingMireds = this.state.colorTemperatureMireds;
169561
169602
  if (existingMireds != null) {
@@ -169580,12 +169621,12 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169580
169621
  applyPatchState(this.state, {
169581
169622
  coupleColorTempToLevelMinMireds: minMireds,
169582
169623
  startUpColorTemperatureMireds: startUpMireds,
169583
- ...inCooldown ? {} : { colorTemperatureMireds: effectiveMireds }
169624
+ ...skipColorTemp ? {} : { colorTemperatureMireds: effectiveMireds }
169584
169625
  });
169585
169626
  }
169586
169627
  applyPatchState(this.state, {
169587
- ...inCooldown ? {} : { colorMode: newColorMode },
169588
- ...this.features.hueSaturation && !inCooldown ? {
169628
+ ...skipColorTemp && skipHueSat ? {} : { colorMode: newColorMode },
169629
+ ...this.features.hueSaturation && !skipHueSat ? {
169589
169630
  currentHue: hue,
169590
169631
  currentSaturation: saturation
169591
169632
  } : {}
@@ -169612,7 +169653,10 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169612
169653
  colorTemperatureMireds: targetMireds,
169613
169654
  colorMode: ColorControl3.ColorMode.ColorTemperatureMireds
169614
169655
  });
169615
- optimisticColorTimestamps.set(homeAssistant.entityId, Date.now());
169656
+ optimisticColorState.set(homeAssistant.entityId, {
169657
+ colorTemperatureMireds: targetMireds,
169658
+ timestamp: Date.now()
169659
+ });
169616
169660
  if (this.isLightOff()) {
169617
169661
  pendingColorStaging.set(homeAssistant.entityId, action.data ?? {});
169618
169662
  return;
@@ -169647,7 +169691,11 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169647
169691
  currentSaturation: targetSaturation,
169648
169692
  colorMode: ColorControl3.ColorMode.CurrentHueAndCurrentSaturation
169649
169693
  });
169650
- optimisticColorTimestamps.set(homeAssistant.entityId, Date.now());
169694
+ optimisticColorState.set(homeAssistant.entityId, {
169695
+ currentHue: targetHue,
169696
+ currentSaturation: targetSaturation,
169697
+ timestamp: Date.now()
169698
+ });
169651
169699
  if (this.isLightOff()) {
169652
169700
  pendingColorStaging.set(homeAssistant.entityId, action.data ?? {});
169653
169701
  return;
@@ -170963,8 +171011,9 @@ init_home_assistant_entity_behavior();
170963
171011
  init_esm();
170964
171012
  init_home_assistant_entity_behavior();
170965
171013
  var logger175 = Logger.get("SpeakerLevelControlServer");
170966
- var optimisticLevelTimestamps2 = /* @__PURE__ */ new Map();
170967
- var OPTIMISTIC_LEVEL_COOLDOWN_MS2 = 2e3;
171014
+ var optimisticLevelState2 = /* @__PURE__ */ new Map();
171015
+ var OPTIMISTIC_TIMEOUT_MS3 = 3e3;
171016
+ var OPTIMISTIC_TOLERANCE3 = 5;
170968
171017
  var FeaturedBase9 = LevelControlServer.with("OnOff");
170969
171018
  var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
170970
171019
  async initialize() {
@@ -171000,10 +171049,15 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
171000
171049
  logger175.debug(
171001
171050
  `[${entityId}] Volume update: HA=${currentLevelPercent != null ? Math.round(currentLevelPercent * 100) : "null"}% -> currentLevel=${currentLevel}`
171002
171051
  );
171003
- const lastOptimistic = optimisticLevelTimestamps2.get(entity.entity_id);
171004
- const inCooldown = lastOptimistic != null && Date.now() - lastOptimistic < OPTIMISTIC_LEVEL_COOLDOWN_MS2;
171005
- if (inCooldown && currentLevel != null) {
171006
- currentLevel = null;
171052
+ const optimistic = optimisticLevelState2.get(entity.entity_id);
171053
+ if (optimistic != null && currentLevel != null) {
171054
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS3) {
171055
+ optimisticLevelState2.delete(entity.entity_id);
171056
+ } else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE3) {
171057
+ optimisticLevelState2.delete(entity.entity_id);
171058
+ } else {
171059
+ currentLevel = null;
171060
+ }
171007
171061
  }
171008
171062
  applyPatchState(this.state, {
171009
171063
  minLevel,
@@ -171051,7 +171105,10 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
171051
171105
  return;
171052
171106
  }
171053
171107
  this.state.currentLevel = level;
171054
- optimisticLevelTimestamps2.set(entityId, Date.now());
171108
+ optimisticLevelState2.set(entityId, {
171109
+ expectedLevel: level,
171110
+ timestamp: Date.now()
171111
+ });
171055
171112
  homeAssistant.callAction(
171056
171113
  config10.moveToLevelPercent(levelPercent, this.agent)
171057
171114
  );