@riddix/hamh 2.1.0-alpha.748 → 2.1.0-alpha.749

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.
@@ -127010,6 +127010,7 @@ function entityMappingApi(mappingStorage) {
127010
127010
  coverSwapOpenClose: body.coverSwapOpenClose,
127011
127011
  coverExposeAsDimmableLight: body.coverExposeAsDimmableLight,
127012
127012
  coverSliderDebounceMs: body.coverSliderDebounceMs,
127013
+ updateThrottleMs: body.updateThrottleMs,
127013
127014
  disableClimateOnOff: body.disableClimateOnOff,
127014
127015
  disableClimateFanControl: body.disableClimateFanControl,
127015
127016
  climateKeepModeOnIdle: body.climateKeepModeOnIdle,
@@ -131643,6 +131644,7 @@ var EntityMappingStorage = class extends Service {
131643
131644
  coverSwapOpenClose: request.coverSwapOpenClose || void 0,
131644
131645
  coverExposeAsDimmableLight: request.coverExposeAsDimmableLight || void 0,
131645
131646
  coverSliderDebounceMs: sanitizeDebounceMs(request.coverSliderDebounceMs),
131647
+ updateThrottleMs: sanitizeThrottleMs(request.updateThrottleMs),
131646
131648
  disableClimateOnOff: request.disableClimateOnOff || void 0,
131647
131649
  disableClimateFanControl: request.disableClimateFanControl || void 0,
131648
131650
  climateKeepModeOnIdle: request.climateKeepModeOnIdle || void 0,
@@ -131650,7 +131652,7 @@ var EntityMappingStorage = class extends Service {
131650
131652
  climateAutoMode: request.climateAutoMode || void 0,
131651
131653
  composedEntities: request.composedEntities?.filter((e) => e.entityId?.trim()) ?? void 0
131652
131654
  };
131653
- if (!config11.matterDeviceType && !config11.customName && !config11.customProductName && !config11.customVendorName && !config11.customSerialNumber && config11.customVendorId === void 0 && config11.disabled !== true && !config11.filterLifeEntity && !config11.cleaningModeEntity && !config11.temperatureEntity && !config11.humidityEntity && !config11.batteryEntity && !config11.roomEntities && !config11.disableLockPin && !config11.powerEntity && !config11.energyEntity && !config11.pressureEntity && !config11.suctionLevelEntity && !config11.mopIntensityEntity && (!config11.customServiceAreas || config11.customServiceAreas.length === 0) && (!config11.customFanSpeedTags || Object.keys(config11.customFanSpeedTags).length === 0) && !config11.currentRoomEntity && !config11.cleanedAreaEntity && !config11.disableCustomAreaRoomModes && !config11.valetudoIdentifier && !config11.coverSwapOpenClose && !config11.coverExposeAsDimmableLight && !config11.coverSliderDebounceMs && !config11.disableClimateOnOff && !config11.disableClimateFanControl && !config11.climateKeepModeOnIdle && !config11.climateExposeFan && !config11.climateAutoMode && (!config11.composedEntities || config11.composedEntities.length === 0)) {
131655
+ if (!config11.matterDeviceType && !config11.customName && !config11.customProductName && !config11.customVendorName && !config11.customSerialNumber && config11.customVendorId === void 0 && config11.disabled !== true && !config11.filterLifeEntity && !config11.cleaningModeEntity && !config11.temperatureEntity && !config11.humidityEntity && !config11.batteryEntity && !config11.roomEntities && !config11.disableLockPin && !config11.powerEntity && !config11.energyEntity && !config11.pressureEntity && !config11.suctionLevelEntity && !config11.mopIntensityEntity && (!config11.customServiceAreas || config11.customServiceAreas.length === 0) && (!config11.customFanSpeedTags || Object.keys(config11.customFanSpeedTags).length === 0) && !config11.currentRoomEntity && !config11.cleanedAreaEntity && !config11.disableCustomAreaRoomModes && !config11.valetudoIdentifier && !config11.coverSwapOpenClose && !config11.coverExposeAsDimmableLight && !config11.coverSliderDebounceMs && !config11.updateThrottleMs && !config11.disableClimateOnOff && !config11.disableClimateFanControl && !config11.climateKeepModeOnIdle && !config11.climateExposeFan && !config11.climateAutoMode && (!config11.composedEntities || config11.composedEntities.length === 0)) {
131654
131656
  bridgeMap.delete(request.entityId);
131655
131657
  } else {
131656
131658
  bridgeMap.set(request.entityId, config11);
@@ -131690,6 +131692,16 @@ function sanitizeDebounceMs(value) {
131690
131692
  }
131691
131693
  return Math.min(5e3, Math.round(n));
131692
131694
  }
131695
+ function sanitizeThrottleMs(value) {
131696
+ if (value === void 0 || value === null || value === "") {
131697
+ return void 0;
131698
+ }
131699
+ const n = typeof value === "string" ? Number(value) : value;
131700
+ if (typeof n !== "number" || !Number.isFinite(n) || n <= 0) {
131701
+ return void 0;
131702
+ }
131703
+ return Math.min(6e4, Math.round(n));
131704
+ }
131693
131705
 
131694
131706
  // src/services/storage/lock-credential-storage.ts
131695
131707
  init_service();
@@ -149079,10 +149091,54 @@ var AggregatorEndpoint2 = class extends Endpoint {
149079
149091
  // src/matter/endpoints/legacy/legacy-endpoint.ts
149080
149092
  init_dist();
149081
149093
  init_esm();
149082
- init_home_assistant_entity_behavior();
149083
149094
  import debounce6 from "debounce";
149084
149095
  import { isEqual } from "lodash-es";
149085
149096
 
149097
+ // src/utils/throttle-latest.ts
149098
+ function throttleLatest(fn, intervalMs) {
149099
+ let lastRun = Number.NEGATIVE_INFINITY;
149100
+ let timer;
149101
+ let pending;
149102
+ const run = (args) => {
149103
+ lastRun = Date.now();
149104
+ fn(...args);
149105
+ };
149106
+ const throttled = ((...args) => {
149107
+ const elapsed = Date.now() - lastRun;
149108
+ if (elapsed >= intervalMs) {
149109
+ if (timer) {
149110
+ clearTimeout(timer);
149111
+ timer = void 0;
149112
+ }
149113
+ pending = void 0;
149114
+ run(args);
149115
+ return;
149116
+ }
149117
+ pending = args;
149118
+ if (!timer) {
149119
+ timer = setTimeout(() => {
149120
+ timer = void 0;
149121
+ if (pending) {
149122
+ const next = pending;
149123
+ pending = void 0;
149124
+ run(next);
149125
+ }
149126
+ }, intervalMs - elapsed);
149127
+ }
149128
+ });
149129
+ throttled.clear = () => {
149130
+ if (timer) {
149131
+ clearTimeout(timer);
149132
+ timer = void 0;
149133
+ }
149134
+ pending = void 0;
149135
+ };
149136
+ return throttled;
149137
+ }
149138
+
149139
+ // src/matter/endpoints/legacy/legacy-endpoint.ts
149140
+ init_home_assistant_entity_behavior();
149141
+
149086
149142
  // src/matter/endpoints/entity-endpoint.ts
149087
149143
  init_esm7();
149088
149144
  var EntityEndpoint = class extends Endpoint {
@@ -162034,11 +162090,17 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
162034
162090
  }
162035
162091
  const customName = effectiveMapping?.customName;
162036
162092
  const mappedIds = getMappedEntityIds(effectiveMapping);
162037
- return new _LegacyEndpoint(type, entityId, customName, mappedIds);
162093
+ return new _LegacyEndpoint(
162094
+ type,
162095
+ entityId,
162096
+ customName,
162097
+ mappedIds,
162098
+ effectiveMapping?.updateThrottleMs
162099
+ );
162038
162100
  }
162039
- constructor(type, entityId, customName, mappedEntityIds) {
162101
+ constructor(type, entityId, customName, mappedEntityIds, throttleMs) {
162040
162102
  super(type, entityId, customName, mappedEntityIds);
162041
- this.flushUpdate = debounce6(this.flushPendingUpdate.bind(this), 50);
162103
+ this.flushUpdate = throttleMs && throttleMs > 50 ? throttleLatest(this.flushPendingUpdate.bind(this), throttleMs) : debounce6(this.flushPendingUpdate.bind(this), 50);
162042
162104
  }
162043
162105
  lastState;
162044
162106
  pendingMappedChange = false;