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