@riddix/hamh 2.1.0-alpha.410 → 2.1.0-alpha.411

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.
@@ -166140,25 +166140,35 @@ var FanOnOffServer = OnOffServer2({
166140
166140
 
166141
166141
  // src/matter/endpoints/composed/composed-air-purifier-endpoint.ts
166142
166142
  var logger159 = Logger.get("ComposedAirPurifierEndpoint");
166143
- var temperatureConfig = {
166144
- getValue(entity, agent) {
166145
- const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
166146
- const state = entity.state;
166147
- const attributes7 = entity.attributes;
166148
- const temperature3 = state == null || Number.isNaN(+state) ? null : +state;
166149
- if (temperature3 == null) return void 0;
166150
- return Temperature.withUnit(
166151
- temperature3,
166152
- attributes7.unit_of_measurement ?? fallbackUnit
166153
- );
166154
- }
166155
- };
166156
- var humidityConfig = {
166157
- getValue({ state }) {
166158
- if (state == null || Number.isNaN(+state)) return null;
166159
- return +state;
166160
- }
166161
- };
166143
+ function createTemperatureConfig(temperatureEntityId) {
166144
+ return {
166145
+ getValue(_entity, agent) {
166146
+ const stateProvider = agent.env.get(EntityStateProvider);
166147
+ const tempState = stateProvider.getState(temperatureEntityId);
166148
+ if (!tempState) return void 0;
166149
+ const temperature3 = Number.parseFloat(tempState.state);
166150
+ if (Number.isNaN(temperature3)) return void 0;
166151
+ const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
166152
+ const attrs = tempState.attributes;
166153
+ return Temperature.withUnit(
166154
+ temperature3,
166155
+ attrs.unit_of_measurement ?? fallbackUnit
166156
+ );
166157
+ }
166158
+ };
166159
+ }
166160
+ function createHumidityConfig(humidityEntityId) {
166161
+ return {
166162
+ getValue(_entity, agent) {
166163
+ const stateProvider = agent.env.get(EntityStateProvider);
166164
+ const humState = stateProvider.getState(humidityEntityId);
166165
+ if (!humState) return null;
166166
+ const humidity = Number.parseFloat(humState.state);
166167
+ if (Number.isNaN(humidity)) return null;
166168
+ return humidity;
166169
+ }
166170
+ };
166171
+ }
166162
166172
  var batteryConfig = {
166163
166173
  getBatteryPercent: (_entity, agent) => {
166164
166174
  const homeAssistant = agent.get(HomeAssistantEntityBehavior);
@@ -166171,16 +166181,6 @@ var batteryConfig = {
166171
166181
  return null;
166172
166182
  }
166173
166183
  };
166174
- var TemperatureSubType = TemperatureSensorDevice.with(
166175
- IdentifyServer2,
166176
- HomeAssistantEntityBehavior,
166177
- TemperatureMeasurementServer2(temperatureConfig)
166178
- );
166179
- var HumiditySubType = HumiditySensorDevice.with(
166180
- IdentifyServer2,
166181
- HomeAssistantEntityBehavior,
166182
- HumidityMeasurementServer(humidityConfig)
166183
- );
166184
166184
  function createEndpointId2(entityId, customName) {
166185
166185
  const baseName = customName || entityId;
166186
166186
  return baseName.replace(/\./g, "_").replace(/\s+/g, "_");
@@ -166199,9 +166199,9 @@ function buildEntityPayload(registry2, entityId) {
166199
166199
  }
166200
166200
  var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends Endpoint {
166201
166201
  entityId;
166202
- subEndpoints = /* @__PURE__ */ new Map();
166202
+ trackedEntityIds;
166203
166203
  lastStates = /* @__PURE__ */ new Map();
166204
- debouncedUpdates = /* @__PURE__ */ new Map();
166204
+ debouncedFlush;
166205
166205
  static async create(config10) {
166206
166206
  const { registry: registry2, primaryEntityId } = config10;
166207
166207
  const primaryPayload = buildEntityPayload(registry2, primaryEntityId);
@@ -166240,6 +166240,20 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166240
166240
  if (hasFilterLife) {
166241
166241
  parentType = parentType.with(AirPurifierHepaFilterMonitoringServer);
166242
166242
  }
166243
+ if (config10.temperatureEntityId) {
166244
+ parentType = parentType.with(
166245
+ TemperatureMeasurementServer2(
166246
+ createTemperatureConfig(config10.temperatureEntityId)
166247
+ )
166248
+ );
166249
+ }
166250
+ if (config10.humidityEntityId) {
166251
+ parentType = parentType.with(
166252
+ HumidityMeasurementServer(
166253
+ createHumidityConfig(config10.humidityEntityId)
166254
+ )
166255
+ );
166256
+ }
166243
166257
  const mapping = {
166244
166258
  entityId: primaryEntityId,
166245
166259
  ...config10.batteryEntityId ? { batteryEntity: config10.batteryEntityId } : {},
@@ -166257,39 +166271,6 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166257
166271
  );
166258
166272
  }
166259
166273
  const endpointId = createEndpointId2(primaryEntityId, config10.customName);
166260
- const parts = [];
166261
- const subEndpointMap = /* @__PURE__ */ new Map();
166262
- let tempSub;
166263
- if (config10.temperatureEntityId) {
166264
- const tempPayload = buildEntityPayload(
166265
- registry2,
166266
- config10.temperatureEntityId
166267
- );
166268
- if (tempPayload) {
166269
- tempSub = new Endpoint(
166270
- TemperatureSubType.set({
166271
- homeAssistantEntity: { entity: tempPayload }
166272
- }),
166273
- { id: `${endpointId}_temp` }
166274
- );
166275
- parts.push(tempSub);
166276
- subEndpointMap.set(config10.temperatureEntityId, tempSub);
166277
- }
166278
- }
166279
- let humSub;
166280
- if (config10.humidityEntityId) {
166281
- const humPayload = buildEntityPayload(registry2, config10.humidityEntityId);
166282
- if (humPayload) {
166283
- humSub = new Endpoint(
166284
- HumiditySubType.set({
166285
- homeAssistantEntity: { entity: humPayload }
166286
- }),
166287
- { id: `${endpointId}_humidity` }
166288
- );
166289
- parts.push(humSub);
166290
- subEndpointMap.set(config10.humidityEntityId, humSub);
166291
- }
166292
- }
166293
166274
  const parentTypeWithState = parentType.set({
166294
166275
  homeAssistantEntity: {
166295
166276
  entity: primaryPayload,
@@ -166297,66 +166278,65 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166297
166278
  mapping
166298
166279
  }
166299
166280
  });
166281
+ const trackedEntityIds = [primaryEntityId];
166282
+ if (config10.temperatureEntityId)
166283
+ trackedEntityIds.push(config10.temperatureEntityId);
166284
+ if (config10.humidityEntityId) trackedEntityIds.push(config10.humidityEntityId);
166300
166285
  const endpoint = new _ComposedAirPurifierEndpoint(
166301
166286
  parentTypeWithState,
166302
166287
  primaryEntityId,
166303
166288
  endpointId,
166304
- parts
166289
+ trackedEntityIds
166305
166290
  );
166306
- for (const [entityId, sub] of subEndpointMap) {
166307
- endpoint.subEndpoints.set(entityId, sub);
166308
- }
166309
- const subLabels = [
166310
- "AirPurifier(parent)",
166311
- tempSub ? "+Temp" : "",
166312
- humSub ? "+Hum" : "",
166291
+ const clusterLabels = [
166292
+ "AirPurifier",
166293
+ config10.temperatureEntityId ? "+Temp" : "",
166294
+ config10.humidityEntityId ? "+Hum" : "",
166313
166295
  config10.batteryEntityId ? "+Bat" : ""
166314
166296
  ].filter(Boolean).join("");
166315
- logger159.info(
166316
- `Created composed air purifier ${primaryEntityId} with ${parts.length} sub-endpoint(s): ${subLabels}`
166317
- );
166297
+ logger159.info(`Created air purifier ${primaryEntityId}: ${clusterLabels}`);
166318
166298
  return endpoint;
166319
166299
  }
166320
- constructor(type, entityId, id, parts) {
166321
- super(type, { id, parts });
166300
+ constructor(type, entityId, id, trackedEntityIds) {
166301
+ super(type, { id });
166322
166302
  this.entityId = entityId;
166303
+ this.trackedEntityIds = trackedEntityIds;
166323
166304
  }
166324
166305
  async updateStates(states) {
166325
- this.scheduleUpdate(this, this.entityId, states);
166326
- for (const [entityId, sub] of this.subEndpoints) {
166327
- this.scheduleUpdate(sub, entityId, states);
166306
+ let anyChanged = false;
166307
+ for (const entityId of this.trackedEntityIds) {
166308
+ const state = states[entityId];
166309
+ if (!state) continue;
166310
+ const stateJson = JSON.stringify({
166311
+ s: state.state,
166312
+ a: state.attributes
166313
+ });
166314
+ if (this.lastStates.get(entityId) !== stateJson) {
166315
+ this.lastStates.set(entityId, stateJson);
166316
+ anyChanged = true;
166317
+ }
166328
166318
  }
166329
- }
166330
- scheduleUpdate(endpoint, entityId, states) {
166331
- const state = states[entityId];
166332
- if (!state) return;
166333
- const key = endpoint === this ? `_parent_:${entityId}` : entityId;
166334
- const stateJson = JSON.stringify({
166335
- s: state.state,
166336
- a: state.attributes
166337
- });
166338
- if (this.lastStates.get(key) === stateJson) return;
166339
- this.lastStates.set(key, stateJson);
166340
- let debouncedFn = this.debouncedUpdates.get(key);
166341
- if (!debouncedFn) {
166342
- debouncedFn = debounce2(
166343
- (ep, s) => this.flushUpdate(ep, s),
166319
+ if (!anyChanged) return;
166320
+ const primaryState = states[this.entityId];
166321
+ if (!primaryState) return;
166322
+ if (!this.debouncedFlush) {
166323
+ this.debouncedFlush = debounce2(
166324
+ (s) => this.flushUpdate(s),
166344
166325
  50
166345
166326
  );
166346
- this.debouncedUpdates.set(key, debouncedFn);
166347
166327
  }
166348
- debouncedFn(endpoint, state);
166328
+ this.debouncedFlush(primaryState);
166349
166329
  }
166350
- async flushUpdate(endpoint, state) {
166330
+ async flushUpdate(state) {
166351
166331
  try {
166352
- await endpoint.construction.ready;
166332
+ await this.construction.ready;
166353
166333
  } catch {
166354
166334
  return;
166355
166335
  }
166356
166336
  try {
166357
- const current = endpoint.stateOf(HomeAssistantEntityBehavior).entity;
166358
- await endpoint.setStateOf(HomeAssistantEntityBehavior, {
166359
- entity: { ...current, state }
166337
+ const current = this.stateOf(HomeAssistantEntityBehavior).entity;
166338
+ await this.setStateOf(HomeAssistantEntityBehavior, {
166339
+ entity: { ...current, state: { ...state } }
166360
166340
  });
166361
166341
  } catch (error) {
166362
166342
  if (error instanceof TransactionDestroyedError || error instanceof DestroyedDependencyError) {
@@ -166372,9 +166352,7 @@ var ComposedAirPurifierEndpoint = class _ComposedAirPurifierEndpoint extends End
166372
166352
  }
166373
166353
  }
166374
166354
  async delete() {
166375
- for (const fn of this.debouncedUpdates.values()) {
166376
- fn.clear();
166377
- }
166355
+ this.debouncedFlush?.clear();
166378
166356
  await super.delete();
166379
166357
  }
166380
166358
  };
@@ -166459,7 +166437,7 @@ function PressureMeasurementServer2(config10) {
166459
166437
 
166460
166438
  // src/matter/endpoints/composed/composed-sensor-endpoint.ts
166461
166439
  var logger161 = Logger.get("ComposedSensorEndpoint");
166462
- var temperatureConfig2 = {
166440
+ var temperatureConfig = {
166463
166441
  getValue(entity, agent) {
166464
166442
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
166465
166443
  const state = entity.state;
@@ -166472,7 +166450,7 @@ var temperatureConfig2 = {
166472
166450
  );
166473
166451
  }
166474
166452
  };
166475
- var humidityConfig2 = {
166453
+ var humidityConfig = {
166476
166454
  getValue({ state }) {
166477
166455
  if (state == null || Number.isNaN(+state)) return null;
166478
166456
  return +state;
@@ -166499,15 +166477,15 @@ var batteryConfig2 = {
166499
166477
  return null;
166500
166478
  }
166501
166479
  };
166502
- var TemperatureSubType2 = TemperatureSensorDevice.with(
166480
+ var TemperatureSubType = TemperatureSensorDevice.with(
166503
166481
  IdentifyServer2,
166504
166482
  HomeAssistantEntityBehavior,
166505
- TemperatureMeasurementServer2(temperatureConfig2)
166483
+ TemperatureMeasurementServer2(temperatureConfig)
166506
166484
  );
166507
- var HumiditySubType2 = HumiditySensorDevice.with(
166485
+ var HumiditySubType = HumiditySensorDevice.with(
166508
166486
  IdentifyServer2,
166509
166487
  HomeAssistantEntityBehavior,
166510
- HumidityMeasurementServer(humidityConfig2)
166488
+ HumidityMeasurementServer(humidityConfig)
166511
166489
  );
166512
166490
  var PressureSubType = PressureSensorDevice.with(
166513
166491
  IdentifyServer2,
@@ -166562,7 +166540,7 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166562
166540
  const endpointId = createEndpointId3(primaryEntityId, config10.customName);
166563
166541
  const parts = [];
166564
166542
  const tempSub = new Endpoint(
166565
- TemperatureSubType2.set({
166543
+ TemperatureSubType.set({
166566
166544
  homeAssistantEntity: { entity: primaryPayload }
166567
166545
  }),
166568
166546
  { id: `${endpointId}_temp` }
@@ -166573,7 +166551,7 @@ var ComposedSensorEndpoint = class _ComposedSensorEndpoint extends Endpoint {
166573
166551
  const humPayload = buildEntityPayload2(registry2, config10.humidityEntityId);
166574
166552
  if (humPayload) {
166575
166553
  humSub = new Endpoint(
166576
- HumiditySubType2.set({
166554
+ HumiditySubType.set({
166577
166555
  homeAssistantEntity: { entity: humPayload }
166578
166556
  }),
166579
166557
  { id: `${endpointId}_humidity` }
@@ -167399,7 +167377,7 @@ var ClimateFanControlServer = FanControlServer2(config3).with(
167399
167377
  );
167400
167378
 
167401
167379
  // src/matter/endpoints/legacy/climate/behaviors/climate-humidity-measurement-server.ts
167402
- var humidityConfig3 = {
167380
+ var humidityConfig2 = {
167403
167381
  getValue(entity) {
167404
167382
  const attributes7 = entity.attributes;
167405
167383
  const humidity = attributes7.current_humidity;
@@ -167409,7 +167387,7 @@ var humidityConfig3 = {
167409
167387
  return +humidity;
167410
167388
  }
167411
167389
  };
167412
- var ClimateHumidityMeasurementServer = HumidityMeasurementServer(humidityConfig3);
167390
+ var ClimateHumidityMeasurementServer = HumidityMeasurementServer(humidityConfig2);
167413
167391
 
167414
167392
  // src/matter/endpoints/legacy/climate/behaviors/climate-on-off-server.ts
167415
167393
  var ClimateOnOffServer = OnOffServer2({
@@ -171693,7 +171671,7 @@ var Pm25SensorType = AirQualitySensorDevice.with(
171693
171671
 
171694
171672
  // src/matter/endpoints/legacy/sensor/devices/temperature-humidity-sensor.ts
171695
171673
  init_home_assistant_entity_behavior();
171696
- var temperatureConfig3 = {
171674
+ var temperatureConfig2 = {
171697
171675
  getValue(entity, agent) {
171698
171676
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
171699
171677
  const state = entity.state;
@@ -171708,7 +171686,7 @@ var temperatureConfig3 = {
171708
171686
  );
171709
171687
  }
171710
171688
  };
171711
- var humidityConfig4 = {
171689
+ var humidityConfig3 = {
171712
171690
  getValue(_entity, agent) {
171713
171691
  const homeAssistant = agent.get(HomeAssistantEntityBehavior);
171714
171692
  const humidityEntity = homeAssistant.state.mapping?.humidityEntity;
@@ -171758,38 +171736,38 @@ var TemperatureHumiditySensorType = TemperatureSensorDevice.with(
171758
171736
  BasicInformationServer2,
171759
171737
  IdentifyServer2,
171760
171738
  HomeAssistantEntityBehavior,
171761
- TemperatureMeasurementServer2(temperatureConfig3),
171762
- HumidityMeasurementServer(humidityConfig4)
171739
+ TemperatureMeasurementServer2(temperatureConfig2),
171740
+ HumidityMeasurementServer(humidityConfig3)
171763
171741
  );
171764
171742
  var TemperatureHumiditySensorWithBatteryType = TemperatureSensorDevice.with(
171765
171743
  BasicInformationServer2,
171766
171744
  IdentifyServer2,
171767
171745
  HomeAssistantEntityBehavior,
171768
- TemperatureMeasurementServer2(temperatureConfig3),
171769
- HumidityMeasurementServer(humidityConfig4),
171746
+ TemperatureMeasurementServer2(temperatureConfig2),
171747
+ HumidityMeasurementServer(humidityConfig3),
171770
171748
  PowerSourceServer2(batteryConfig4)
171771
171749
  );
171772
171750
  var TemperatureHumidityPressureSensorType = TemperatureSensorDevice.with(
171773
171751
  BasicInformationServer2,
171774
171752
  IdentifyServer2,
171775
171753
  HomeAssistantEntityBehavior,
171776
- TemperatureMeasurementServer2(temperatureConfig3),
171777
- HumidityMeasurementServer(humidityConfig4),
171754
+ TemperatureMeasurementServer2(temperatureConfig2),
171755
+ HumidityMeasurementServer(humidityConfig3),
171778
171756
  PressureMeasurementServer2(pressureConfig2)
171779
171757
  );
171780
171758
  var TemperatureHumidityPressureSensorWithBatteryType = TemperatureSensorDevice.with(
171781
171759
  BasicInformationServer2,
171782
171760
  IdentifyServer2,
171783
171761
  HomeAssistantEntityBehavior,
171784
- TemperatureMeasurementServer2(temperatureConfig3),
171785
- HumidityMeasurementServer(humidityConfig4),
171762
+ TemperatureMeasurementServer2(temperatureConfig2),
171763
+ HumidityMeasurementServer(humidityConfig3),
171786
171764
  PressureMeasurementServer2(pressureConfig2),
171787
171765
  PowerSourceServer2(batteryConfig4)
171788
171766
  );
171789
171767
 
171790
171768
  // src/matter/endpoints/legacy/sensor/devices/temperature-pressure-sensor.ts
171791
171769
  init_home_assistant_entity_behavior();
171792
- var temperatureConfig4 = {
171770
+ var temperatureConfig3 = {
171793
171771
  getValue(entity, agent) {
171794
171772
  const fallbackUnit = agent.env.get(HomeAssistantConfig).unitSystem.temperature;
171795
171773
  const state = entity.state;
@@ -171840,14 +171818,14 @@ var TemperaturePressureSensorType = TemperatureSensorDevice.with(
171840
171818
  BasicInformationServer2,
171841
171819
  IdentifyServer2,
171842
171820
  HomeAssistantEntityBehavior,
171843
- TemperatureMeasurementServer2(temperatureConfig4),
171821
+ TemperatureMeasurementServer2(temperatureConfig3),
171844
171822
  PressureMeasurementServer2(pressureConfig3)
171845
171823
  );
171846
171824
  var TemperaturePressureSensorWithBatteryType = TemperatureSensorDevice.with(
171847
171825
  BasicInformationServer2,
171848
171826
  IdentifyServer2,
171849
171827
  HomeAssistantEntityBehavior,
171850
- TemperatureMeasurementServer2(temperatureConfig4),
171828
+ TemperatureMeasurementServer2(temperatureConfig3),
171851
171829
  PressureMeasurementServer2(pressureConfig3),
171852
171830
  PowerSourceServer2(batteryConfig5)
171853
171831
  );