@riddix/hamh 2.1.0-alpha.467 → 2.1.0-alpha.469

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