@riddix/hamh 2.1.0-alpha.419 → 2.1.0-alpha.421

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) {
@@ -170551,6 +170571,70 @@ var MediaPlayerKeypadInputServer = class extends KeypadInputServer {
170551
170571
  }
170552
170572
  };
170553
170573
 
170574
+ // src/matter/behaviors/media-input-server.ts
170575
+ init_home_assistant_entity_behavior();
170576
+ var MediaInputServerBase = class extends MediaInputServer {
170577
+ async initialize() {
170578
+ await super.initialize();
170579
+ const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
170580
+ this.update(homeAssistant.entity);
170581
+ this.reactTo(homeAssistant.onChange, this.update);
170582
+ }
170583
+ update(entity) {
170584
+ if (!entity.state) {
170585
+ return;
170586
+ }
170587
+ const config10 = this.state.config;
170588
+ let source_idx = 0;
170589
+ const sourceList = config10.getSourceList(entity.state, this.agent)?.sort();
170590
+ const inputList = sourceList?.map((source) => ({
170591
+ index: source_idx++,
170592
+ inputType: MediaInput3.InputType.Other,
170593
+ name: source,
170594
+ description: source
170595
+ }));
170596
+ const currentSource = config10.getCurrentSource(entity.state, this.agent);
170597
+ let currentInput = sourceList?.indexOf(currentSource ?? "");
170598
+ if (currentInput === -1 || currentInput == null) {
170599
+ currentInput = 0;
170600
+ }
170601
+ applyPatchState(this.state, {
170602
+ inputList,
170603
+ currentInput
170604
+ });
170605
+ }
170606
+ selectInput(request) {
170607
+ const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
170608
+ const target = this.state.inputList[request.index];
170609
+ homeAssistant.callAction(
170610
+ this.state.config.selectSource(target.name, this.agent)
170611
+ );
170612
+ }
170613
+ showInputStatus() {
170614
+ }
170615
+ hideInputStatus() {
170616
+ }
170617
+ };
170618
+ ((MediaInputServerBase2) => {
170619
+ class State extends MediaInputServer.State {
170620
+ config;
170621
+ }
170622
+ MediaInputServerBase2.State = State;
170623
+ })(MediaInputServerBase || (MediaInputServerBase = {}));
170624
+ function MediaInputServer2(config10) {
170625
+ return MediaInputServerBase.set({ config: config10 });
170626
+ }
170627
+
170628
+ // src/matter/endpoints/legacy/media-player/behaviors/media-player-media-input-server.ts
170629
+ var MediaPlayerMediaInputServer = MediaInputServer2({
170630
+ getCurrentSource: (entity) => entity.attributes.source,
170631
+ getSourceList: (entity) => entity.attributes.source_list,
170632
+ selectSource: (source) => ({
170633
+ action: "media_player.select_source",
170634
+ data: { source }
170635
+ })
170636
+ });
170637
+
170554
170638
  // src/matter/endpoints/legacy/media-player/behaviors/media-player-media-playback-server.ts
170555
170639
  init_home_assistant_entity_behavior();
170556
170640
  var MediaPlayerMediaPlaybackServer = class extends MediaPlaybackServer {
@@ -170668,6 +170752,9 @@ function VideoPlayerDevice(homeAssistantEntity) {
170668
170752
  if (supportsPlay || supportsPause) {
170669
170753
  device = device.with(MediaPlayerMediaPlaybackServer);
170670
170754
  }
170755
+ if (testBit(supportedFeatures, MediaPlayerDeviceFeature.SELECT_SOURCE)) {
170756
+ device = device.with(MediaPlayerMediaInputServer);
170757
+ }
170671
170758
  return device.set({ homeAssistantEntity });
170672
170759
  }
170673
170760
 
@@ -170794,70 +170881,6 @@ var MediaPlayerLevelControlServer = SpeakerLevelControlServer({
170794
170881
  }
170795
170882
  });
170796
170883
 
170797
- // src/matter/behaviors/media-input-server.ts
170798
- init_home_assistant_entity_behavior();
170799
- var MediaInputServerBase = class extends MediaInputServer {
170800
- async initialize() {
170801
- await super.initialize();
170802
- const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
170803
- this.update(homeAssistant.entity);
170804
- this.reactTo(homeAssistant.onChange, this.update);
170805
- }
170806
- update(entity) {
170807
- if (!entity.state) {
170808
- return;
170809
- }
170810
- const config10 = this.state.config;
170811
- let source_idx = 0;
170812
- const sourceList = config10.getSourceList(entity.state, this.agent)?.sort();
170813
- const inputList = sourceList?.map((source) => ({
170814
- index: source_idx++,
170815
- inputType: MediaInput3.InputType.Other,
170816
- name: source,
170817
- description: source
170818
- }));
170819
- const currentSource = config10.getCurrentSource(entity.state, this.agent);
170820
- let currentInput = sourceList?.indexOf(currentSource ?? "");
170821
- if (currentInput === -1 || currentInput == null) {
170822
- currentInput = 0;
170823
- }
170824
- applyPatchState(this.state, {
170825
- inputList,
170826
- currentInput
170827
- });
170828
- }
170829
- selectInput(request) {
170830
- const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
170831
- const target = this.state.inputList[request.index];
170832
- homeAssistant.callAction(
170833
- this.state.config.selectSource(target.name, this.agent)
170834
- );
170835
- }
170836
- showInputStatus() {
170837
- }
170838
- hideInputStatus() {
170839
- }
170840
- };
170841
- ((MediaInputServerBase2) => {
170842
- class State extends MediaInputServer.State {
170843
- config;
170844
- }
170845
- MediaInputServerBase2.State = State;
170846
- })(MediaInputServerBase || (MediaInputServerBase = {}));
170847
- function MediaInputServer2(config10) {
170848
- return MediaInputServerBase.set({ config: config10 });
170849
- }
170850
-
170851
- // src/matter/endpoints/legacy/media-player/behaviors/media-player-media-input-server.ts
170852
- var MediaPlayerMediaInputServer = MediaInputServer2({
170853
- getCurrentSource: (entity) => entity.attributes.source,
170854
- getSourceList: (entity) => entity.attributes.source_list,
170855
- selectSource: (source) => ({
170856
- action: "media_player.select_source",
170857
- data: { source }
170858
- })
170859
- });
170860
-
170861
170884
  // src/matter/endpoints/legacy/media-player/behaviors/media-player-on-off-server.ts
170862
170885
  var MediaPlayerOnOffServer = OnOffServer2({
170863
170886
  isOn: (state) => {
@@ -177003,6 +177026,9 @@ function startOptionsBuilder(yargs2) {
177003
177026
  }).option("http-auth-password", {
177004
177027
  type: "string",
177005
177028
  description: "Password for HTTP basic authentication (optional)"
177029
+ }).option("http-base-path", {
177030
+ type: "string",
177031
+ description: "Base path for the web interface and API when served behind a reverse proxy under a subfolder (e.g. /matter). Defaults to /"
177006
177032
  }).demandOption(["home-assistant-url", "home-assistant-access-token"]);
177007
177033
  }
177008
177034