@riddix/hamh 2.1.0-alpha.418 → 2.1.0-alpha.420

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.
@@ -149857,8 +149857,9 @@ var WebSocketApi = class {
149857
149857
  setDiagnosticService(service) {
149858
149858
  this.diagnosticService = service;
149859
149859
  }
149860
- attach(server) {
149861
- this.wss = new WebSocketServer2({ server, path: "/api/ws" });
149860
+ attach(server, basePath = "/") {
149861
+ const wsPath = `${basePath === "/" ? "" : basePath}/api/ws`;
149862
+ this.wss = new WebSocketServer2({ server, path: wsPath });
149862
149863
  this.wss.on("connection", (ws2) => {
149863
149864
  this.clients.add(ws2);
149864
149865
  this.log.debug(`WebSocket client connected. Total: ${this.clients.size}`);
@@ -149899,7 +149900,7 @@ var WebSocketApi = class {
149899
149900
  this.pingInterval = setInterval(() => {
149900
149901
  this.broadcast({ type: "ping" });
149901
149902
  }, 3e4);
149902
- this.log.info("WebSocket server attached at /api/ws");
149903
+ this.log.info(`WebSocket server attached at ${wsPath}`);
149903
149904
  }
149904
149905
  handleMessage(ws2, message) {
149905
149906
  switch (message.type) {
@@ -150062,7 +150063,15 @@ var WebApi = class extends Service {
150062
150063
  })
150063
150064
  );
150064
150065
  }
150065
- this.app = express14().use(...middlewares).use("/api", api).use(webUi(this.props.webUiDist));
150066
+ const appRouter = express14.Router();
150067
+ appRouter.use(...middlewares).use("/api", api).use(webUi(this.props.webUiDist));
150068
+ this.app = express14();
150069
+ const basePath = this.props.basePath;
150070
+ if (basePath !== "/") {
150071
+ this.log.info(`Base path configured: ${basePath}`);
150072
+ this.app.get("/", (_req, res) => res.redirect(basePath));
150073
+ }
150074
+ this.app.use(basePath, appRouter);
150066
150075
  }
150067
150076
  async dispose() {
150068
150077
  this.wsApi.close();
@@ -150101,7 +150110,7 @@ var WebApi = class extends Service {
150101
150110
  resolve4(server);
150102
150111
  });
150103
150112
  });
150104
- this.wsApi.attach(this.server);
150113
+ this.wsApi.attach(this.server, this.props.basePath);
150105
150114
  }
150106
150115
  };
150107
150116
 
@@ -150492,6 +150501,7 @@ var Options = class {
150492
150501
  webUiDist: this.startOptions.webUiDist,
150493
150502
  version: resolveAppVersion(),
150494
150503
  storageLocation: this.resolveStorageLocation(),
150504
+ basePath: normalizeBasePath(this.startOptions.httpBasePath),
150495
150505
  auth
150496
150506
  };
150497
150507
  }
@@ -150514,6 +150524,16 @@ var Options = class {
150514
150524
  };
150515
150525
  }
150516
150526
  };
150527
+ function normalizeBasePath(val) {
150528
+ let p = val?.trim() ?? "/";
150529
+ if (!p.startsWith("/")) {
150530
+ p = `/${p}`;
150531
+ }
150532
+ if (p.length > 1 && p.endsWith("/")) {
150533
+ p = p.slice(0, -1);
150534
+ }
150535
+ return p;
150536
+ }
150517
150537
  function notEmpty(val) {
150518
150538
  const value = val?.trim();
150519
150539
  if (value == null || value.length === 0) {
@@ -169073,6 +169093,21 @@ function FanDevice2(homeAssistantEntity) {
169073
169093
  );
169074
169094
  const presetModes = attributes7.preset_modes ?? [];
169075
169095
  const speedPresets = presetModes.filter((m) => m.toLowerCase() !== "auto");
169096
+ if (!hasSetSpeed && speedPresets.length === 0) {
169097
+ const onOffDevice = hasBattery ? OnOffPlugInUnitDevice.with(
169098
+ IdentifyServer2,
169099
+ BasicInformationServer2,
169100
+ HomeAssistantEntityBehavior,
169101
+ FanOnOffServer,
169102
+ FanPowerSourceServer
169103
+ ) : OnOffPlugInUnitDevice.with(
169104
+ IdentifyServer2,
169105
+ BasicInformationServer2,
169106
+ HomeAssistantEntityBehavior,
169107
+ FanOnOffServer
169108
+ );
169109
+ return onOffDevice.set({ homeAssistantEntity });
169110
+ }
169076
169111
  const features2 = /* @__PURE__ */ new Set();
169077
169112
  if (hasSetSpeed || speedPresets.length > 0) {
169078
169113
  features2.add("MultiSpeed");
@@ -176988,6 +177023,9 @@ function startOptionsBuilder(yargs2) {
176988
177023
  }).option("http-auth-password", {
176989
177024
  type: "string",
176990
177025
  description: "Password for HTTP basic authentication (optional)"
177026
+ }).option("http-base-path", {
177027
+ type: "string",
177028
+ description: "Base path for the web interface and API when served behind a reverse proxy under a subfolder (e.g. /matter). Defaults to /"
176991
177029
  }).demandOption(["home-assistant-url", "home-assistant-access-token"]);
176992
177030
  }
176993
177031