@riddix/hamh 2.1.0-alpha.475 → 2.1.0-alpha.477

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.
@@ -149842,7 +149842,7 @@ import express13 from "express";
149842
149842
 
149843
149843
  // src/plugins/plugin-installer.ts
149844
149844
  init_esm();
149845
- import { exec } from "node:child_process";
149845
+ import { execFile } from "node:child_process";
149846
149846
  import * as fs4 from "node:fs";
149847
149847
  import * as path4 from "node:path";
149848
149848
  var logger142 = Logger.get("PluginInstaller");
@@ -149887,8 +149887,9 @@ var PluginInstaller = class {
149887
149887
  }
149888
149888
  logger142.info(`Installing plugin: ${packageName}`);
149889
149889
  return new Promise((resolve4) => {
149890
- exec(
149891
- `npm install ${packageName} --save`,
149890
+ execFile(
149891
+ "npm",
149892
+ ["install", packageName, "--save"],
149892
149893
  {
149893
149894
  cwd: this.pluginDir,
149894
149895
  timeout: 12e4,
@@ -149930,8 +149931,9 @@ var PluginInstaller = class {
149930
149931
  }
149931
149932
  logger142.info(`Uninstalling plugin: ${packageName}`);
149932
149933
  return new Promise((resolve4) => {
149933
- exec(
149934
- `npm uninstall ${packageName} --save`,
149934
+ execFile(
149935
+ "npm",
149936
+ ["uninstall", packageName, "--save"],
149935
149937
  {
149936
149938
  cwd: this.pluginDir,
149937
149939
  timeout: 6e4
@@ -150326,12 +150328,12 @@ function settingsApi(settingsStorage, envAuth) {
150326
150328
 
150327
150329
  // src/api/system-api.ts
150328
150330
  init_esm();
150329
- import { exec as exec2 } from "node:child_process";
150331
+ import { exec } from "node:child_process";
150330
150332
  import os2 from "node:os";
150331
150333
  import { promisify } from "node:util";
150332
150334
  import v8 from "node:v8";
150333
150335
  import express14 from "express";
150334
- var execAsync = promisify(exec2);
150336
+ var execAsync = promisify(exec);
150335
150337
  var logger144 = Logger.get("SystemApi");
150336
150338
  function detectEnvironment2() {
150337
150339
  if (process.env.SUPERVISOR_TOKEN || process.env.HASSIO_TOKEN) {
@@ -164192,14 +164194,17 @@ var SafePluginRunner = class {
164192
164194
  );
164193
164195
  return void 0;
164194
164196
  }
164197
+ const timeout = this.createTimeout(pluginName, operation, timeoutMs);
164195
164198
  try {
164196
164199
  const result = await Promise.race([
164197
164200
  Promise.resolve().then(fn),
164198
- this.createTimeout(pluginName, operation, timeoutMs)
164201
+ timeout.promise
164199
164202
  ]);
164203
+ timeout.clear();
164200
164204
  state.failures = 0;
164201
164205
  return result;
164202
164206
  } catch (error) {
164207
+ timeout.clear();
164203
164208
  state.failures++;
164204
164209
  state.lastError = error instanceof Error ? error.message : String(error);
164205
164210
  logger158.error(
@@ -164247,8 +164252,9 @@ var SafePluginRunner = class {
164247
164252
  return new Map(this.states);
164248
164253
  }
164249
164254
  createTimeout(pluginName, operation, timeoutMs) {
164250
- return new Promise((_, reject) => {
164251
- setTimeout(() => {
164255
+ let timer;
164256
+ const promise = new Promise((_, reject) => {
164257
+ timer = setTimeout(() => {
164252
164258
  reject(
164253
164259
  new Error(
164254
164260
  `Plugin "${pluginName}" timed out during ${operation} after ${timeoutMs}ms`
@@ -164256,6 +164262,7 @@ var SafePluginRunner = class {
164256
164262
  );
164257
164263
  }, timeoutMs);
164258
164264
  });
164265
+ return { promise, clear: () => clearTimeout(timer) };
164259
164266
  }
164260
164267
  };
164261
164268
 
@@ -170972,9 +170979,14 @@ var LightOnOffServer = OnOffServer2({
170972
170979
  turnOn: (_value, agent) => {
170973
170980
  const entityId = agent.get(HomeAssistantEntityBehavior).entityId;
170974
170981
  const staged = consumePendingColorStaging(entityId);
170982
+ if (entityId.startsWith("light.")) {
170983
+ return {
170984
+ action: "light.turn_on",
170985
+ data: staged
170986
+ };
170987
+ }
170975
170988
  return {
170976
- action: "light.turn_on",
170977
- data: staged
170989
+ action: "homeassistant.turn_on"
170978
170990
  };
170979
170991
  },
170980
170992
  turnOff: () => ({
@@ -177310,7 +177322,16 @@ var BridgeEndpointManager = class extends Service {
177310
177322
  );
177311
177323
  return;
177312
177324
  }
177313
- const endpoint = new Endpoint(type, { id: `plugin_${device.id}` });
177325
+ const initialState = {
177326
+ pluginDevice: { device, pluginName }
177327
+ };
177328
+ for (const cluster2 of device.clusters) {
177329
+ initialState[cluster2.clusterId] = cluster2.attributes;
177330
+ }
177331
+ const configuredType = type.set(initialState);
177332
+ const endpoint = new Endpoint(configuredType, {
177333
+ id: `plugin_${device.id}`
177334
+ });
177314
177335
  try {
177315
177336
  await this.root.add(endpoint);
177316
177337
  this.pluginEndpoints.set(device.id, endpoint);
@@ -177338,6 +177359,23 @@ var BridgeEndpointManager = class extends Service {
177338
177359
  this.pluginEndpoints.delete(deviceId);
177339
177360
  }
177340
177361
  };
177362
+ this.pluginManager.onDeviceStateUpdated = (pluginName, deviceId, clusterId3, attributes7) => {
177363
+ const endpoint = this.pluginEndpoints.get(deviceId);
177364
+ if (!endpoint) return;
177365
+ const behaviorType = endpoint.type.behaviors[clusterId3];
177366
+ if (!behaviorType) {
177367
+ this.log.debug(
177368
+ `Plugin "${pluginName}": cluster "${clusterId3}" not found on device "${deviceId}"`
177369
+ );
177370
+ return;
177371
+ }
177372
+ endpoint.setStateOf(behaviorType, attributes7).catch((e) => {
177373
+ this.log.warn(
177374
+ `Plugin "${pluginName}": failed to update "${clusterId3}" on "${deviceId}":`,
177375
+ e
177376
+ );
177377
+ });
177378
+ };
177341
177379
  }
177342
177380
  async startPlugins() {
177343
177381
  if (!this.pluginManager) return;