@riddix/hamh 2.1.0-alpha.470 → 2.1.0-alpha.472

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.
@@ -166688,13 +166688,15 @@ var FanControlServerBase = class extends FeaturedBase4 {
166688
166688
  return;
166689
166689
  }
166690
166690
  if (onOff && this.lastNonZeroPercent > 0) {
166691
- try {
166692
- applyPatchState(this.state, {
166693
- percentSetting: this.lastNonZeroPercent,
166694
- ...this.features.multiSpeed && this.lastNonZeroSpeed > 0 ? { speedSetting: this.lastNonZeroSpeed } : {}
166695
- });
166696
- } catch {
166697
- }
166691
+ this.agent.asLocalActor(() => {
166692
+ try {
166693
+ applyPatchState(this.state, {
166694
+ percentSetting: this.lastNonZeroPercent,
166695
+ ...this.features.multiSpeed && this.lastNonZeroSpeed > 0 ? { speedSetting: this.lastNonZeroSpeed } : {}
166696
+ });
166697
+ } catch {
166698
+ }
166699
+ });
166698
166700
  }
166699
166701
  }
166700
166702
  // Cross-cluster sync: keep OnOff in sync with FanControl per Matter spec
@@ -166796,25 +166798,35 @@ var FanOnOffServer = OnOffServer2({
166796
166798
 
166797
166799
  // src/matter/endpoints/composed/composed-air-purifier-endpoint.ts
166798
166800
  var logger162 = Logger.get("ComposedAirPurifierEndpoint");
166799
- var temperatureConfig = {
166800
- getValue(entity, agent) {
166801
- const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
166802
- const state = entity.state;
166803
- const attributes7 = entity.attributes;
166804
- const temperature3 = state == null || Number.isNaN(+state) ? null : +state;
166805
- if (temperature3 == null) return void 0;
166806
- return Temperature.withUnit(
166807
- temperature3,
166808
- attributes7.unit_of_measurement ?? fallbackUnit
166809
- );
166810
- }
166811
- };
166812
- var humidityConfig = {
166813
- getValue({ state }) {
166814
- if (state == null || Number.isNaN(+state)) return null;
166815
- return +state;
166816
- }
166817
- };
166801
+ function createTemperatureConfig(temperatureEntityId) {
166802
+ return {
166803
+ getValue(_entity, agent) {
166804
+ const stateProvider = agent.env.get(EntityStateProvider);
166805
+ const tempState = stateProvider.getState(temperatureEntityId);
166806
+ if (!tempState) return void 0;
166807
+ const temperature3 = Number.parseFloat(tempState.state);
166808
+ if (Number.isNaN(temperature3)) return void 0;
166809
+ const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
166810
+ const attrs = tempState.attributes;
166811
+ return Temperature.withUnit(
166812
+ temperature3,
166813
+ attrs.unit_of_measurement ?? fallbackUnit
166814
+ );
166815
+ }
166816
+ };
166817
+ }
166818
+ function createHumidityConfig(humidityEntityId) {
166819
+ return {
166820
+ getValue(_entity, agent) {
166821
+ const stateProvider = agent.env.get(EntityStateProvider);
166822
+ const humState = stateProvider.getState(humidityEntityId);
166823
+ if (!humState) return null;
166824
+ const humidity = Number.parseFloat(humState.state);
166825
+ if (Number.isNaN(humidity)) return null;
166826
+ return humidity;
166827
+ }
166828
+ };
166829
+ }
166818
166830
  var batteryConfig = {
166819
166831
  getBatteryPercent: (_entity, agent) => {
166820
166832
  const homeAssistant = agent.get(HomeAssistantEntityBehavior);
@@ -166827,16 +166839,6 @@ var batteryConfig = {
166827
166839
  return null;
166828
166840
  }
166829
166841
  };
166830
- var TemperatureSubType = TemperatureSensorDevice.with(
166831
- IdentifyServer2,
166832
- HomeAssistantEntityBehavior,
166833
- TemperatureMeasurementServer2(temperatureConfig)
166834
- );
166835
- var HumiditySubType = HumiditySensorDevice.with(
166836
- IdentifyServer2,
166837
- HomeAssistantEntityBehavior,
166838
- HumidityMeasurementServer(humidityConfig)
166839
- );
166840
166842
  function createEndpointId2(entityId, customName) {
166841
166843
  const baseName = customName || entityId;
166842
166844
  return baseName.replace(/\./g, "_").replace(/\s+/g, "_");
@@ -166856,9 +166858,9 @@ function buildEntityPayload(registry2, entityId) {
166856
166858
  var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends Endpoint {
166857
166859
  entityId;
166858
166860
  mappedEntityIds;
166859
- subEndpoints = /* @__PURE__ */ new Map();
166861
+ trackedEntityIds;
166860
166862
  lastStates = /* @__PURE__ */ new Map();
166861
- debouncedUpdates = /* @__PURE__ */ new Map();
166863
+ debouncedFlush;
166862
166864
  static async create(config10) {
166863
166865
  const { registry: registry2, primaryEntityId } = config10;
166864
166866
  const primaryPayload = buildEntityPayload(registry2, primaryEntityId);
@@ -166897,6 +166899,20 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166897
166899
  if (hasFilterLife) {
166898
166900
  parentType = parentType.with(AirPurifierHepaFilterMonitoringServer);
166899
166901
  }
166902
+ if (config10.temperatureEntityId) {
166903
+ parentType = parentType.with(
166904
+ TemperatureMeasurementServer2(
166905
+ createTemperatureConfig(config10.temperatureEntityId)
166906
+ )
166907
+ );
166908
+ }
166909
+ if (config10.humidityEntityId) {
166910
+ parentType = parentType.with(
166911
+ HumidityMeasurementServer(
166912
+ createHumidityConfig(config10.humidityEntityId)
166913
+ )
166914
+ );
166915
+ }
166900
166916
  const mapping = {
166901
166917
  entityId: primaryEntityId,
166902
166918
  ...config10.batteryEntityId ? { batteryEntity: config10.batteryEntityId } : {},
@@ -166914,37 +166930,6 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166914
166930
  );
166915
166931
  }
166916
166932
  const endpointId = createEndpointId2(primaryEntityId, config10.customName);
166917
- const parts = [];
166918
- const subEndpointMap = /* @__PURE__ */ new Map();
166919
- if (config10.temperatureEntityId) {
166920
- const tempPayload = buildEntityPayload(
166921
- registry2,
166922
- config10.temperatureEntityId
166923
- );
166924
- if (tempPayload) {
166925
- const tempSub = new Endpoint(
166926
- TemperatureSubType.set({
166927
- homeAssistantEntity: { entity: tempPayload }
166928
- }),
166929
- { id: `${endpointId}_temp` }
166930
- );
166931
- parts.push(tempSub);
166932
- subEndpointMap.set(config10.temperatureEntityId, tempSub);
166933
- }
166934
- }
166935
- if (config10.humidityEntityId) {
166936
- const humPayload = buildEntityPayload(registry2, config10.humidityEntityId);
166937
- if (humPayload) {
166938
- const humSub = new Endpoint(
166939
- HumiditySubType.set({
166940
- homeAssistantEntity: { entity: humPayload }
166941
- }),
166942
- { id: `${endpointId}_humidity` }
166943
- );
166944
- parts.push(humSub);
166945
- subEndpointMap.set(config10.humidityEntityId, humSub);
166946
- }
166947
- }
166948
166933
  const parentTypeWithState = parentType.set({
166949
166934
  homeAssistantEntity: {
166950
166935
  entity: primaryPayload,
@@ -166952,14 +166937,17 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166952
166937
  mapping
166953
166938
  }
166954
166939
  });
166955
- const mappedIds = [...subEndpointMap.keys()];
166940
+ const trackedEntityIds = [primaryEntityId];
166941
+ if (config10.temperatureEntityId)
166942
+ trackedEntityIds.push(config10.temperatureEntityId);
166943
+ if (config10.humidityEntityId) trackedEntityIds.push(config10.humidityEntityId);
166944
+ const mappedIds = trackedEntityIds.filter((id) => id !== primaryEntityId);
166956
166945
  const endpoint = new _ComposedAirPurifierEndpoint(
166957
166946
  parentTypeWithState,
166958
166947
  primaryEntityId,
166959
166948
  endpointId,
166960
- parts,
166961
- mappedIds,
166962
- subEndpointMap
166949
+ trackedEntityIds,
166950
+ mappedIds
166963
166951
  );
166964
166952
  const clusterLabels = [
166965
166953
  "AirPurifier",
@@ -166970,47 +166958,46 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166970
166958
  logger162.info(`Created air purifier ${primaryEntityId}: ${clusterLabels}`);
166971
166959
  return endpoint;
166972
166960
  }
166973
- constructor(type, entityId, id, parts, mappedEntityIds, subEndpoints) {
166974
- super(type, { id, parts });
166961
+ constructor(type, entityId, id, trackedEntityIds, mappedEntityIds) {
166962
+ super(type, { id });
166975
166963
  this.entityId = entityId;
166964
+ this.trackedEntityIds = trackedEntityIds;
166976
166965
  this.mappedEntityIds = mappedEntityIds;
166977
- this.subEndpoints = subEndpoints;
166978
166966
  }
166979
166967
  async updateStates(states) {
166980
- this.scheduleUpdate(this, this.entityId, states);
166981
- for (const [entityId, sub] of this.subEndpoints) {
166982
- this.scheduleUpdate(sub, entityId, states);
166968
+ let anyChanged = false;
166969
+ for (const entityId of this.trackedEntityIds) {
166970
+ const state = states[entityId];
166971
+ if (!state) continue;
166972
+ const stateJson = JSON.stringify({
166973
+ s: state.state,
166974
+ a: state.attributes
166975
+ });
166976
+ if (this.lastStates.get(entityId) !== stateJson) {
166977
+ this.lastStates.set(entityId, stateJson);
166978
+ anyChanged = true;
166979
+ }
166983
166980
  }
166984
- }
166985
- scheduleUpdate(endpoint, entityId, states) {
166986
- const state = states[entityId];
166987
- if (!state) return;
166988
- const key = endpoint === this ? `_parent_:${entityId}` : entityId;
166989
- const stateJson = JSON.stringify({
166990
- s: state.state,
166991
- a: state.attributes
166992
- });
166993
- if (this.lastStates.get(key) === stateJson) return;
166994
- this.lastStates.set(key, stateJson);
166995
- let debouncedFn = this.debouncedUpdates.get(key);
166996
- if (!debouncedFn) {
166997
- debouncedFn = debounce2(
166998
- (ep, s) => this.flushUpdate(ep, s),
166981
+ if (!anyChanged) return;
166982
+ const primaryState = states[this.entityId];
166983
+ if (!primaryState) return;
166984
+ if (!this.debouncedFlush) {
166985
+ this.debouncedFlush = debounce2(
166986
+ (s) => this.flushUpdate(s),
166999
166987
  50
167000
166988
  );
167001
- this.debouncedUpdates.set(key, debouncedFn);
167002
166989
  }
167003
- debouncedFn(endpoint, state);
166990
+ this.debouncedFlush(primaryState);
167004
166991
  }
167005
- async flushUpdate(endpoint, state) {
166992
+ async flushUpdate(state) {
167006
166993
  try {
167007
- await endpoint.construction.ready;
166994
+ await this.construction.ready;
167008
166995
  } catch {
167009
166996
  return;
167010
166997
  }
167011
166998
  try {
167012
- const current = endpoint.stateOf(HomeAssistantEntityBehavior).entity;
167013
- await endpoint.setStateOf(HomeAssistantEntityBehavior, {
166999
+ const current = this.stateOf(HomeAssistantEntityBehavior).entity;
167000
+ await this.setStateOf(HomeAssistantEntityBehavior, {
167014
167001
  entity: { ...current, state: { ...state } }
167015
167002
  });
167016
167003
  } catch (error) {
@@ -167027,9 +167014,7 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
167027
167014
  }
167028
167015
  }
167029
167016
  async delete() {
167030
- for (const fn of this.debouncedUpdates.values()) {
167031
- fn.clear();
167032
- }
167017
+ this.debouncedFlush?.clear();
167033
167018
  await super.delete();
167034
167019
  }
167035
167020
  };
@@ -167114,7 +167099,7 @@ function PressureMeasurementServer2(config10) {
167114
167099
 
167115
167100
  // src/matter/endpoints/composed/composed-sensor-endpoint.ts
167116
167101
  var logger164 = Logger.get("ComposedSensorEndpoint");
167117
- var temperatureConfig2 = {
167102
+ var temperatureConfig = {
167118
167103
  getValue(entity, agent) {
167119
167104
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
167120
167105
  const state = entity.state;
@@ -167127,7 +167112,7 @@ var temperatureConfig2 = {
167127
167112
  );
167128
167113
  }
167129
167114
  };
167130
- var humidityConfig2 = {
167115
+ var humidityConfig = {
167131
167116
  getValue({ state }) {
167132
167117
  if (state == null || Number.isNaN(+state)) return null;
167133
167118
  return +state;
@@ -167154,15 +167139,15 @@ var batteryConfig2 = {
167154
167139
  return null;
167155
167140
  }
167156
167141
  };
167157
- var TemperatureSubType2 = TemperatureSensorDevice.with(
167142
+ var TemperatureSubType = TemperatureSensorDevice.with(
167158
167143
  IdentifyServer2,
167159
167144
  HomeAssistantEntityBehavior,
167160
- TemperatureMeasurementServer2(temperatureConfig2)
167145
+ TemperatureMeasurementServer2(temperatureConfig)
167161
167146
  );
167162
- var HumiditySubType2 = HumiditySensorDevice.with(
167147
+ var HumiditySubType = HumiditySensorDevice.with(
167163
167148
  IdentifyServer2,
167164
167149
  HomeAssistantEntityBehavior,
167165
- HumidityMeasurementServer(humidityConfig2)
167150
+ HumidityMeasurementServer(humidityConfig)
167166
167151
  );
167167
167152
  var PressureSubType = PressureSensorDevice.with(
167168
167153
  IdentifyServer2,
@@ -167218,7 +167203,7 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
167218
167203
  const endpointId = createEndpointId3(primaryEntityId, config10.customName);
167219
167204
  const parts = [];
167220
167205
  const tempSub = new Endpoint(
167221
- TemperatureSubType2.set({
167206
+ TemperatureSubType.set({
167222
167207
  homeAssistantEntity: { entity: primaryPayload }
167223
167208
  }),
167224
167209
  { id: `${endpointId}_temp` }
@@ -167229,7 +167214,7 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
167229
167214
  const humPayload = buildEntityPayload2(registry2, config10.humidityEntityId);
167230
167215
  if (humPayload) {
167231
167216
  humSub = new Endpoint(
167232
- HumiditySubType2.set({
167217
+ HumiditySubType.set({
167233
167218
  homeAssistantEntity: { entity: humPayload }
167234
167219
  }),
167235
167220
  { id: `${endpointId}_humidity` }
@@ -168069,7 +168054,7 @@ var ClimateFanControlServer = FanControlServer2(config3).with(
168069
168054
  );
168070
168055
 
168071
168056
  // src/matter/endpoints/legacy/climate/behaviors/climate-humidity-measurement-server.ts
168072
- var humidityConfig3 = {
168057
+ var humidityConfig2 = {
168073
168058
  getValue(entity) {
168074
168059
  const attributes7 = entity.attributes;
168075
168060
  const humidity = attributes7.current_humidity;
@@ -168079,7 +168064,7 @@ var humidityConfig3 = {
168079
168064
  return +humidity;
168080
168065
  }
168081
168066
  };
168082
- var ClimateHumidityMeasurementServer = HumidityMeasurementServer(humidityConfig3);
168067
+ var ClimateHumidityMeasurementServer = HumidityMeasurementServer(humidityConfig2);
168083
168068
 
168084
168069
  // src/matter/endpoints/legacy/climate/behaviors/climate-on-off-server.ts
168085
168070
  var ClimateOnOffServer = OnOffServer2({
@@ -173128,7 +173113,7 @@ var Pm25SensorType = AirQualitySensorDevice.with(
173128
173113
 
173129
173114
  // src/matter/endpoints/legacy/sensor/devices/temperature-humidity-sensor.ts
173130
173115
  init_home_assistant_entity_behavior();
173131
- var temperatureConfig3 = {
173116
+ var temperatureConfig2 = {
173132
173117
  getValue(entity, agent) {
173133
173118
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
173134
173119
  const state = entity.state;
@@ -173143,7 +173128,7 @@ var temperatureConfig3 = {
173143
173128
  );
173144
173129
  }
173145
173130
  };
173146
- var humidityConfig4 = {
173131
+ var humidityConfig3 = {
173147
173132
  getValue(_entity, agent) {
173148
173133
  const homeAssistant = agent.get(HomeAssistantEntityBehavior);
173149
173134
  const humidityEntity = homeAssistant.state.mapping?.humidityEntity;
@@ -173193,38 +173178,38 @@ var TemperatureHumiditySensorType = TemperatureSensorDevice.with(
173193
173178
  BasicInformationServer2,
173194
173179
  IdentifyServer2,
173195
173180
  HomeAssistantEntityBehavior,
173196
- TemperatureMeasurementServer2(temperatureConfig3),
173197
- HumidityMeasurementServer(humidityConfig4)
173181
+ TemperatureMeasurementServer2(temperatureConfig2),
173182
+ HumidityMeasurementServer(humidityConfig3)
173198
173183
  );
173199
173184
  var TemperatureHumiditySensorWithBatteryType = TemperatureSensorDevice.with(
173200
173185
  BasicInformationServer2,
173201
173186
  IdentifyServer2,
173202
173187
  HomeAssistantEntityBehavior,
173203
- TemperatureMeasurementServer2(temperatureConfig3),
173204
- HumidityMeasurementServer(humidityConfig4),
173188
+ TemperatureMeasurementServer2(temperatureConfig2),
173189
+ HumidityMeasurementServer(humidityConfig3),
173205
173190
  PowerSourceServer2(batteryConfig4)
173206
173191
  );
173207
173192
  var TemperatureHumidityPressureSensorType = TemperatureSensorDevice.with(
173208
173193
  BasicInformationServer2,
173209
173194
  IdentifyServer2,
173210
173195
  HomeAssistantEntityBehavior,
173211
- TemperatureMeasurementServer2(temperatureConfig3),
173212
- HumidityMeasurementServer(humidityConfig4),
173196
+ TemperatureMeasurementServer2(temperatureConfig2),
173197
+ HumidityMeasurementServer(humidityConfig3),
173213
173198
  PressureMeasurementServer2(pressureConfig2)
173214
173199
  );
173215
173200
  var TemperatureHumidityPressureSensorWithBatteryType = TemperatureSensorDevice.with(
173216
173201
  BasicInformationServer2,
173217
173202
  IdentifyServer2,
173218
173203
  HomeAssistantEntityBehavior,
173219
- TemperatureMeasurementServer2(temperatureConfig3),
173220
- HumidityMeasurementServer(humidityConfig4),
173204
+ TemperatureMeasurementServer2(temperatureConfig2),
173205
+ HumidityMeasurementServer(humidityConfig3),
173221
173206
  PressureMeasurementServer2(pressureConfig2),
173222
173207
  PowerSourceServer2(batteryConfig4)
173223
173208
  );
173224
173209
 
173225
173210
  // src/matter/endpoints/legacy/sensor/devices/temperature-pressure-sensor.ts
173226
173211
  init_home_assistant_entity_behavior();
173227
- var temperatureConfig4 = {
173212
+ var temperatureConfig3 = {
173228
173213
  getValue(entity, agent) {
173229
173214
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
173230
173215
  const state = entity.state;
@@ -173275,14 +173260,14 @@ var TemperaturePressureSensorType = TemperatureSensorDevice.with(
173275
173260
  BasicInformationServer2,
173276
173261
  IdentifyServer2,
173277
173262
  HomeAssistantEntityBehavior,
173278
- TemperatureMeasurementServer2(temperatureConfig4),
173263
+ TemperatureMeasurementServer2(temperatureConfig3),
173279
173264
  PressureMeasurementServer2(pressureConfig3)
173280
173265
  );
173281
173266
  var TemperaturePressureSensorWithBatteryType = TemperatureSensorDevice.with(
173282
173267
  BasicInformationServer2,
173283
173268
  IdentifyServer2,
173284
173269
  HomeAssistantEntityBehavior,
173285
- TemperatureMeasurementServer2(temperatureConfig4),
173270
+ TemperatureMeasurementServer2(temperatureConfig3),
173286
173271
  PressureMeasurementServer2(pressureConfig3),
173287
173272
  PowerSourceServer2(batteryConfig5)
173288
173273
  );