@riddix/hamh 2.1.0-alpha.526 → 2.1.0-alpha.528

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.
@@ -166283,6 +166283,7 @@ function validatePluginDevice(device) {
166283
166283
  }
166284
166284
  var PluginManager = class {
166285
166285
  instances = /* @__PURE__ */ new Map();
166286
+ domainMappings = /* @__PURE__ */ new Map();
166286
166287
  storageDir;
166287
166288
  bridgeId;
166288
166289
  runner = new SafePluginRunner();
@@ -166414,6 +166415,21 @@ var PluginManager = class {
166414
166415
  clusterId3,
166415
166416
  attributes7
166416
166417
  );
166418
+ },
166419
+ registerDomainMapping: (mapping) => {
166420
+ if (!mapping.domain || typeof mapping.domain !== "string" || !mapping.matterDeviceType || typeof mapping.matterDeviceType !== "string") {
166421
+ pluginLogger.warn("Invalid domain mapping, skipping");
166422
+ return;
166423
+ }
166424
+ if (this.domainMappings.has(mapping.domain)) {
166425
+ pluginLogger.warn(
166426
+ `Domain "${mapping.domain}" already mapped by another plugin, overwriting`
166427
+ );
166428
+ }
166429
+ this.domainMappings.set(mapping.domain, mapping);
166430
+ pluginLogger.info(
166431
+ `Registered domain mapping: ${mapping.domain} \u2192 ${mapping.matterDeviceType}`
166432
+ );
166417
166433
  }
166418
166434
  };
166419
166435
  this.instances.set(plugin.name, {
@@ -166539,6 +166555,9 @@ var PluginManager = class {
166539
166555
  if (!instance) return void 0;
166540
166556
  return instance.plugin.getConfigSchema?.();
166541
166557
  }
166558
+ getDomainMappings() {
166559
+ return new Map(this.domainMappings);
166560
+ }
166542
166561
  async updateConfig(pluginName, config10) {
166543
166562
  const instance = this.instances.get(pluginName);
166544
166563
  if (!instance) return false;
@@ -169227,6 +169246,9 @@ init_esm7();
169227
169246
  import debounce4 from "debounce";
169228
169247
  init_home_assistant_entity_behavior();
169229
169248
 
169249
+ // src/matter/endpoints/legacy/create-legacy-endpoint-type.ts
169250
+ init_esm();
169251
+
169230
169252
  // src/matter/endpoints/legacy/air-purifier/index.ts
169231
169253
  init_dist();
169232
169254
  init_home_assistant_entity_behavior();
@@ -173623,8 +173645,38 @@ var PumpType = PumpDevice.with(
173623
173645
  PumpOnOffServer,
173624
173646
  PumpConfigurationAndControlServer2
173625
173647
  );
173648
+ var PumpWithBatteryType = PumpDevice.with(
173649
+ IdentifyServer2,
173650
+ BasicInformationServer2,
173651
+ HomeAssistantEntityBehavior,
173652
+ PumpOnOffServer,
173653
+ PumpConfigurationAndControlServer2,
173654
+ PowerSourceServer2({
173655
+ getBatteryPercent: (entity, agent) => {
173656
+ const homeAssistant = agent.get(HomeAssistantEntityBehavior);
173657
+ const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
173658
+ if (batteryEntity) {
173659
+ const stateProvider = agent.env.get(EntityStateProvider);
173660
+ const battery = stateProvider.getBatteryPercent(batteryEntity);
173661
+ if (battery != null) {
173662
+ return Math.max(0, Math.min(100, battery));
173663
+ }
173664
+ }
173665
+ const attrs = entity.attributes;
173666
+ const level = attrs.battery_level ?? attrs.battery;
173667
+ if (level == null || Number.isNaN(Number(level))) {
173668
+ return null;
173669
+ }
173670
+ return Number(level);
173671
+ }
173672
+ })
173673
+ );
173626
173674
  function PumpEndpoint(homeAssistantEntity) {
173627
- return PumpType.set({ homeAssistantEntity });
173675
+ const attrs = homeAssistantEntity.entity.state.attributes;
173676
+ const hasBatteryAttr = attrs.battery_level != null || attrs.battery != null;
173677
+ const hasBatteryEntity = !!homeAssistantEntity.mapping?.batteryEntity;
173678
+ const device = hasBatteryAttr || hasBatteryEntity ? PumpWithBatteryType : PumpType;
173679
+ return device.set({ homeAssistantEntity });
173628
173680
  }
173629
173681
 
173630
173682
  // src/matter/endpoints/legacy/remote/index.ts
@@ -177644,8 +177696,37 @@ var ValveEndpointType = WaterValveDevice.with(
177644
177696
  HomeAssistantEntityBehavior,
177645
177697
  ValveServer
177646
177698
  );
177699
+ var ValveWithBatteryEndpointType = WaterValveDevice.with(
177700
+ BasicInformationServer2,
177701
+ IdentifyServer2,
177702
+ HomeAssistantEntityBehavior,
177703
+ ValveServer,
177704
+ PowerSourceServer2({
177705
+ getBatteryPercent: (entity, agent) => {
177706
+ const homeAssistant = agent.get(HomeAssistantEntityBehavior);
177707
+ const batteryEntity = homeAssistant.state.mapping?.batteryEntity;
177708
+ if (batteryEntity) {
177709
+ const stateProvider = agent.env.get(EntityStateProvider);
177710
+ const battery = stateProvider.getBatteryPercent(batteryEntity);
177711
+ if (battery != null) {
177712
+ return Math.max(0, Math.min(100, battery));
177713
+ }
177714
+ }
177715
+ const attrs = entity.attributes;
177716
+ const level = attrs.battery_level ?? attrs.battery;
177717
+ if (level == null || Number.isNaN(Number(level))) {
177718
+ return null;
177719
+ }
177720
+ return Number(level);
177721
+ }
177722
+ })
177723
+ );
177647
177724
  function ValveDevice(homeAssistantEntity) {
177648
- return ValveEndpointType.set({ homeAssistantEntity });
177725
+ const attrs = homeAssistantEntity.entity.state.attributes;
177726
+ const hasBatteryAttr = attrs.battery_level != null || attrs.battery != null;
177727
+ const hasBatteryEntity = !!homeAssistantEntity.mapping?.batteryEntity;
177728
+ const device = hasBatteryAttr || hasBatteryEntity ? ValveWithBatteryEndpointType : ValveEndpointType;
177729
+ return device.set({ homeAssistantEntity });
177649
177730
  }
177650
177731
 
177651
177732
  // src/matter/endpoints/legacy/water-heater/index.ts
@@ -177766,6 +177847,7 @@ function WaterHeaterDevice(homeAssistantEntity) {
177766
177847
  }
177767
177848
 
177768
177849
  // src/matter/endpoints/legacy/create-legacy-endpoint-type.ts
177850
+ var legacyLogger = Logger.get("LegacyEndpointType");
177769
177851
  function createLegacyEndpointType(entity, mapping, areaName, options) {
177770
177852
  const domain = entity.entity_id.split(".")[0];
177771
177853
  const customName = mapping?.customName;
@@ -177785,10 +177867,20 @@ function createLegacyEndpointType(entity, mapping, areaName, options) {
177785
177867
  );
177786
177868
  } else {
177787
177869
  const factory = deviceCtrs[domain];
177788
- if (!factory) {
177870
+ if (factory) {
177871
+ type = factory({ entity, customName, mapping });
177872
+ } else if (options?.pluginDomainMappings?.has(domain)) {
177873
+ const mappedType = options.pluginDomainMappings.get(domain);
177874
+ const mappedFactory = matterDeviceTypeFactories[mappedType];
177875
+ if (mappedFactory) {
177876
+ legacyLogger.info(
177877
+ `Using plugin domain mapping for "${domain}" \u2192 "${mappedType}"`
177878
+ );
177879
+ type = mappedFactory({ entity, customName, mapping });
177880
+ }
177881
+ } else {
177789
177882
  return void 0;
177790
177883
  }
177791
- type = factory({ entity, customName, mapping });
177792
177884
  }
177793
177885
  }
177794
177886
  if (!type) {
@@ -178131,7 +178223,7 @@ var UserComposedEndpoint = class _UserComposedEndpoint extends Endpoint {
178131
178223
  // src/matter/endpoints/legacy/legacy-endpoint.ts
178132
178224
  var logger199 = Logger.get("LegacyEndpoint");
178133
178225
  var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
178134
- static async create(registry2, entityId, mapping) {
178226
+ static async create(registry2, entityId, mapping, pluginDomainMappings) {
178135
178227
  const deviceRegistry = registry2.deviceOf(entityId);
178136
178228
  let state = registry2.initialState(entityId);
178137
178229
  const entity = registry2.entity(entityId);
@@ -178426,7 +178518,8 @@ var LegacyEndpoint = class _LegacyEndpoint extends EntityEndpoint {
178426
178518
  const areaName = registry2.getAreaName(entityId);
178427
178519
  const type = createLegacyEndpointType(payload, effectiveMapping, areaName, {
178428
178520
  vacuumOnOff: registry2.isVacuumOnOffEnabled(),
178429
- cleaningModeOptions
178521
+ cleaningModeOptions,
178522
+ pluginDomainMappings
178430
178523
  });
178431
178524
  if (!type) {
178432
178525
  return;
@@ -178930,6 +179023,16 @@ var BridgeEndpointManager = class extends Service {
178930
179023
  }
178931
179024
  }
178932
179025
  }
179026
+ getPluginDomainMappings() {
179027
+ if (!this.pluginManager) return void 0;
179028
+ const mappings = this.pluginManager.getDomainMappings();
179029
+ if (mappings.size === 0) return void 0;
179030
+ const result = /* @__PURE__ */ new Map();
179031
+ for (const [domain, mapping] of mappings) {
179032
+ result.set(domain, mapping.matterDeviceType);
179033
+ }
179034
+ return result;
179035
+ }
178933
179036
  getEntityMapping(entityId) {
178934
179037
  return this.mappingStorage.getMapping(this.bridgeId, entityId);
178935
179038
  }
@@ -179085,10 +179188,12 @@ var BridgeEndpointManager = class extends Service {
179085
179188
  let endpoint = existingEndpoints.find((e) => e.entityId === entityId);
179086
179189
  if (!endpoint) {
179087
179190
  try {
179191
+ const domainMappings = this.getPluginDomainMappings();
179088
179192
  endpoint = await LegacyEndpoint.create(
179089
179193
  this.registry,
179090
179194
  entityId,
179091
- mapping
179195
+ mapping,
179196
+ domainMappings
179092
179197
  );
179093
179198
  } catch (e) {
179094
179199
  const reason = this.extractErrorReason(e);
@@ -181111,8 +181216,7 @@ process.on("unhandledRejection", (reason) => {
181111
181216
  if (shouldSuppressError(reason)) {
181112
181217
  return;
181113
181218
  }
181114
- console.error("Unhandled rejection:", reason);
181115
- process.exit(1);
181219
+ console.error("Unhandled rejection (process continuing):", reason);
181116
181220
  });
181117
181221
  function registerFinalErrorHandlers() {
181118
181222
  process.removeAllListeners("uncaughtException");
@@ -181138,8 +181242,7 @@ function registerFinalErrorHandlers() {
181138
181242
  console.warn("Suppressed Matter.js internal error:", reason);
181139
181243
  return;
181140
181244
  }
181141
- console.error("Unhandled rejection:", reason);
181142
- process.exit(1);
181245
+ console.error("Unhandled rejection (process continuing):", reason);
181143
181246
  });
181144
181247
  }
181145
181248
  async function startHandler(startOptions, webUiDist) {