@riddix/hamh 2.1.0-alpha.449 → 2.1.0-alpha.451

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.
@@ -166407,6 +166407,8 @@ function LevelControlServer2(config10) {
166407
166407
 
166408
166408
  // src/matter/behaviors/on-off-server.ts
166409
166409
  var logger159 = Logger.get("OnOffServer");
166410
+ var optimisticOnOffState = /* @__PURE__ */ new Map();
166411
+ var OPTIMISTIC_TIMEOUT_MS2 = 3e3;
166410
166412
  var OnOffServerBase = class extends OnOffServer {
166411
166413
  async initialize() {
166412
166414
  await super.initialize();
@@ -166415,9 +166417,19 @@ var OnOffServerBase = class extends OnOffServer {
166415
166417
  this.reactTo(homeAssistant.onChange, this.update);
166416
166418
  }
166417
166419
  update({ state }) {
166418
- applyPatchState(this.state, {
166419
- onOff: this.isOn(state)
166420
- });
166420
+ const onOff = this.isOn(state);
166421
+ const entityId = this.agent.get(HomeAssistantEntityBehavior).entity.entity_id;
166422
+ const optimistic = optimisticOnOffState.get(entityId);
166423
+ if (optimistic != null) {
166424
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS2) {
166425
+ optimisticOnOffState.delete(entityId);
166426
+ } else if (onOff === optimistic.expectedOnOff) {
166427
+ optimisticOnOffState.delete(entityId);
166428
+ } else {
166429
+ return;
166430
+ }
166431
+ }
166432
+ applyPatchState(this.state, { onOff });
166421
166433
  }
166422
166434
  isOn(entity) {
166423
166435
  return this.state.config?.isOn?.(entity, this.agent) ?? (this.agent.get(HomeAssistantEntityBehavior).isAvailable && entity.state !== "off");
@@ -166435,6 +166447,10 @@ var OnOffServerBase = class extends OnOffServer {
166435
166447
  logger159.info(`[${homeAssistant.entityId}] Turning ON -> ${action.action}`);
166436
166448
  notifyLightTurnedOn(homeAssistant.entityId);
166437
166449
  applyPatchState(this.state, { onOff: true });
166450
+ optimisticOnOffState.set(homeAssistant.entityId, {
166451
+ expectedOnOff: true,
166452
+ timestamp: Date.now()
166453
+ });
166438
166454
  homeAssistant.callAction(action);
166439
166455
  if (turnOff === null) {
166440
166456
  setTimeout(this.callback(this.autoReset), 1e3);
@@ -166452,6 +166468,10 @@ var OnOffServerBase = class extends OnOffServer {
166452
166468
  };
166453
166469
  logger159.info(`[${homeAssistant.entityId}] Turning OFF -> ${action.action}`);
166454
166470
  applyPatchState(this.state, { onOff: false });
166471
+ optimisticOnOffState.set(homeAssistant.entityId, {
166472
+ expectedOnOff: false,
166473
+ timestamp: Date.now()
166474
+ });
166455
166475
  homeAssistant.callAction(action);
166456
166476
  }
166457
166477
  autoReset() {
@@ -166536,6 +166556,7 @@ function buildEntityPayload(registry2, entityId) {
166536
166556
  }
166537
166557
  var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends Endpoint {
166538
166558
  entityId;
166559
+ mappedEntityIds;
166539
166560
  trackedEntityIds;
166540
166561
  lastStates = /* @__PURE__ */ new Map();
166541
166562
  debouncedFlush;
@@ -166619,11 +166640,13 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166619
166640
  if (config10.temperatureEntityId)
166620
166641
  trackedEntityIds.push(config10.temperatureEntityId);
166621
166642
  if (config10.humidityEntityId) trackedEntityIds.push(config10.humidityEntityId);
166643
+ const mappedIds = trackedEntityIds.filter((id) => id !== primaryEntityId);
166622
166644
  const endpoint = new _ComposedAirPurifierEndpoint(
166623
166645
  parentTypeWithState,
166624
166646
  primaryEntityId,
166625
166647
  endpointId,
166626
- trackedEntityIds
166648
+ trackedEntityIds,
166649
+ mappedIds
166627
166650
  );
166628
166651
  const clusterLabels = [
166629
166652
  "AirPurifier",
@@ -166634,10 +166657,11 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166634
166657
  logger160.info(`Created air purifier ${primaryEntityId}: ${clusterLabels}`);
166635
166658
  return endpoint;
166636
166659
  }
166637
- constructor(type, entityId, id, trackedEntityIds) {
166660
+ constructor(type, entityId, id, trackedEntityIds, mappedEntityIds) {
166638
166661
  super(type, { id });
166639
166662
  this.entityId = entityId;
166640
166663
  this.trackedEntityIds = trackedEntityIds;
166664
+ this.mappedEntityIds = mappedEntityIds;
166641
166665
  }
166642
166666
  async updateStates(states) {
166643
166667
  let anyChanged = false;
@@ -166847,6 +166871,7 @@ function buildEntityPayload2(registry2, entityId) {
166847
166871
  }
166848
166872
  var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166849
166873
  entityId;
166874
+ mappedEntityIds;
166850
166875
  subEndpoints = /* @__PURE__ */ new Map();
166851
166876
  lastStates = /* @__PURE__ */ new Map();
166852
166877
  debouncedUpdates = /* @__PURE__ */ new Map();
@@ -166919,11 +166944,15 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166919
166944
  mapping
166920
166945
  }
166921
166946
  });
166947
+ const mappedIds = [];
166948
+ if (config10.humidityEntityId) mappedIds.push(config10.humidityEntityId);
166949
+ if (config10.pressureEntityId) mappedIds.push(config10.pressureEntityId);
166922
166950
  const endpoint = new _ComposedSensorEndpoint(
166923
166951
  parentTypeWithState,
166924
166952
  primaryEntityId,
166925
166953
  endpointId,
166926
- parts
166954
+ parts,
166955
+ mappedIds
166927
166956
  );
166928
166957
  endpoint.subEndpoints.set(primaryEntityId, tempSub);
166929
166958
  if (config10.humidityEntityId && humSub) {
@@ -166937,9 +166966,10 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166937
166966
  );
166938
166967
  return endpoint;
166939
166968
  }
166940
- constructor(type, entityId, id, parts) {
166969
+ constructor(type, entityId, id, parts, mappedEntityIds) {
166941
166970
  super(type, { id, parts });
166942
166971
  this.entityId = entityId;
166972
+ this.mappedEntityIds = mappedEntityIds;
166943
166973
  }
166944
166974
  async updateStates(states) {
166945
166975
  this.scheduleUpdate(this, this.entityId, states);
@@ -169478,7 +169508,7 @@ init_nodejs();
169478
169508
  init_home_assistant_entity_behavior();
169479
169509
  var logger170 = Logger.get("ColorControlServer");
169480
169510
  var optimisticColorState = /* @__PURE__ */ new Map();
169481
- var OPTIMISTIC_TIMEOUT_MS2 = 3e3;
169511
+ var OPTIMISTIC_TIMEOUT_MS3 = 3e3;
169482
169512
  var OPTIMISTIC_TOLERANCE2 = 5;
169483
169513
  var pendingColorStaging = /* @__PURE__ */ new Map();
169484
169514
  function consumePendingColorStaging(entityId) {
@@ -169568,7 +169598,7 @@ var ColorControlServerBase = class extends FeaturedBase7 {
169568
169598
  let skipColorTemp = false;
169569
169599
  let skipHueSat = false;
169570
169600
  if (optimistic != null) {
169571
- if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS2) {
169601
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS3) {
169572
169602
  optimisticColorState.delete(entity.entity_id);
169573
169603
  } else {
169574
169604
  if (optimistic.colorTemperatureMireds != null && currentMireds != null) {
@@ -171002,7 +171032,7 @@ init_esm();
171002
171032
  init_home_assistant_entity_behavior();
171003
171033
  var logger175 = Logger.get("SpeakerLevelControlServer");
171004
171034
  var optimisticLevelState2 = /* @__PURE__ */ new Map();
171005
- var OPTIMISTIC_TIMEOUT_MS3 = 3e3;
171035
+ var OPTIMISTIC_TIMEOUT_MS4 = 3e3;
171006
171036
  var OPTIMISTIC_TOLERANCE3 = 5;
171007
171037
  var FeaturedBase9 = LevelControlServer.with("OnOff");
171008
171038
  var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
@@ -171041,7 +171071,7 @@ var SpeakerLevelControlServerBase = class extends FeaturedBase9 {
171041
171071
  );
171042
171072
  const optimistic = optimisticLevelState2.get(entity.entity_id);
171043
171073
  if (optimistic != null && currentLevel != null) {
171044
- if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS3) {
171074
+ if (Date.now() - optimistic.timestamp > OPTIMISTIC_TIMEOUT_MS4) {
171045
171075
  optimisticLevelState2.delete(entity.entity_id);
171046
171076
  } else if (Math.abs(currentLevel - optimistic.expectedLevel) <= OPTIMISTIC_TOLERANCE3) {
171047
171077
  optimisticLevelState2.delete(entity.entity_id);