@attraccess/plugin-wago 0.1.0-nightly.951.1 → 0.1.0-nightly.953.1

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.
Files changed (2) hide show
  1. package/dist/index.js +38 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -51671,6 +51671,13 @@ var CONFIGURATION_CAPABILITY = `configuration-v${CONFIGURATION_PROTOCOL_VERSION}
51671
51671
  var REQUIRED_CAPABILITIES = ["claim", "heartbeat", CONFIGURATION_CAPABILITY];
51672
51672
  var SUPPORTED_PROTOCOL_MAJOR = 1;
51673
51673
  function parseAnnouncement(payload) {
51674
+ const heartbeat = parseHeartbeat(payload);
51675
+ const input = JSON.parse(payload.toString("utf8"));
51676
+ if (typeof input.pairingCode !== "string" || !input.pairingCode.trim())
51677
+ throw new Error("announcement pairingCode is required");
51678
+ return { ...heartbeat, pairingCode: input.pairingCode.trim() };
51679
+ }
51680
+ function parseHeartbeat(payload) {
51674
51681
  let value;
51675
51682
  try {
51676
51683
  value = JSON.parse(payload.toString("utf8"));
@@ -51679,7 +51686,7 @@ function parseAnnouncement(payload) {
51679
51686
  }
51680
51687
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("announcement must be an object");
51681
51688
  const input = value;
51682
- const required = ["hardwareId", "pairingCode", "protocolVersion", "runtimeVersion"];
51689
+ const required = ["hardwareId", "protocolVersion", "runtimeVersion"];
51683
51690
  for (const key of required)
51684
51691
  if (typeof input[key] !== "string" || !input[key].trim()) throw new Error(`announcement ${key} is required`);
51685
51692
  if (!Array.isArray(input.capabilities) || input.capabilities.some((item) => typeof item !== "string"))
@@ -51688,7 +51695,6 @@ function parseAnnouncement(payload) {
51688
51695
  throw new Error("announcement sequence must be a non-negative integer");
51689
51696
  return {
51690
51697
  hardwareId: input.hardwareId.trim(),
51691
- pairingCode: input.pairingCode.trim(),
51692
51698
  enrollmentSecret: typeof input.enrollmentSecret === "string" ? input.enrollmentSecret.trim() : void 0,
51693
51699
  fingerprint: typeof input.fingerprint === "string" ? input.fingerprint.trim() : void 0,
51694
51700
  protocolVersion: input.protocolVersion.trim(),
@@ -52445,7 +52451,18 @@ var WagoCommandHandler = class {
52445
52451
  const revision = controllerId ? await this.dependencies.appliedRevision(controllerId) : null;
52446
52452
  const snapshot = revision ? JSON.parse(revision.snapshot) : null;
52447
52453
  const channelId = typeof config.channelId === "string" ? config.channelId : void 0;
52448
- const channel = snapshot?.logicalChannels.find((item) => item.id === channelId);
52454
+ const outputChannels = snapshot?.logicalChannels.filter((item) => item.capabilities.includes("output")) ?? [];
52455
+ let names = {};
52456
+ if (controllerId) {
52457
+ const draft = await this.dependencies.context.getRepository(WagoConfigurationDraft).findOneBy({ controllerId });
52458
+ try {
52459
+ const draftMatchesAppliedRevision = typeof draft?.snapshot === "string" && configurationHash(JSON.parse(draft.snapshot)) === revision?.contentHash;
52460
+ const storedNames = draftMatchesAppliedRevision && JSON.parse(draft?.presetProvenance ?? "null")?.editor?.names;
52461
+ if (storedNames && typeof storedNames === "object" && !Array.isArray(storedNames)) names = storedNames;
52462
+ } catch {
52463
+ }
52464
+ }
52465
+ const channel = outputChannels.find((item) => item.id === channelId);
52449
52466
  const references = channelId && controllerId ? await this.references(controllerId, channelId, resourceId) : [];
52450
52467
  const properties = {
52451
52468
  controllerId: {
@@ -52456,16 +52473,20 @@ var WagoCommandHandler = class {
52456
52473
  const: controller.id,
52457
52474
  title: controller.name ?? controller.hardwareId
52458
52475
  })),
52459
- refreshesSchema: true
52476
+ refreshesSchema: true,
52477
+ description: controllerId && !revision ? "Publish a configuration and wait for the controller to apply it before authoring commands." : void 0
52460
52478
  }
52461
52479
  };
52462
52480
  if (controllerId && revision && snapshot) {
52463
52481
  properties.channelId = {
52464
52482
  type: "string",
52465
52483
  title: "Logical Channel",
52466
- oneOf: snapshot.logicalChannels.map((item) => ({ const: item.id, title: `${item.id} (${item.profile})` })),
52484
+ oneOf: outputChannels.map((item) => ({
52485
+ const: item.id,
52486
+ title: typeof names[item.id] === "string" ? names[item.id] : `${item.id} (${item.profile})`
52487
+ })),
52467
52488
  refreshesSchema: true,
52468
- helpText: references.length ? `Also controlled by resource flow node${references.length === 1 ? "" : "s"}: ${references.join(", ")}. Reuse is allowed.` : void 0
52489
+ description: references.length ? `Also controlled by resource flow node${references.length === 1 ? "" : "s"}: ${references.join(", ")}. Reuse is allowed.` : outputChannels.length ? void 0 : "This applied configuration has no output channels. Add an output and publish it first."
52469
52490
  };
52470
52491
  }
52471
52492
  if (channel) {
@@ -52474,7 +52495,7 @@ var WagoCommandHandler = class {
52474
52495
  ...channel.capabilities.includes("pulse") ? [{ const: "pulse", title: "Pulse" }] : []
52475
52496
  ] : [];
52476
52497
  properties.action = { type: "string", title: "Operation", oneOf: actions, refreshesSchema: true };
52477
- if (config.action === "set") properties.value = { type: "boolean", title: "State" };
52498
+ if (config.action === "set") properties.value = { type: "boolean", title: "State", default: false };
52478
52499
  properties.expectedConfigurationRevision = {
52479
52500
  type: "number",
52480
52501
  title: "Configuration revision",
@@ -52515,7 +52536,15 @@ var WagoCommandHandler = class {
52515
52536
  dynamic: true,
52516
52537
  type: "object",
52517
52538
  properties,
52518
- required: Object.keys(properties).filter((key) => key !== "value")
52539
+ required: [
52540
+ .../* @__PURE__ */ new Set([
52541
+ "controllerId",
52542
+ "channelId",
52543
+ "action",
52544
+ "expectedConfigurationRevision",
52545
+ ...Object.keys(properties)
52546
+ ])
52547
+ ]
52519
52548
  };
52520
52549
  }
52521
52550
  async validate(config, validationContext = /* @__PURE__ */ new Map()) {
@@ -53429,7 +53458,7 @@ var WagoService = class {
53429
53458
  async onHeartbeat(hardwareId, payload) {
53430
53459
  let heartbeat;
53431
53460
  try {
53432
- heartbeat = parseAnnouncement(payload);
53461
+ heartbeat = parseHeartbeat(payload);
53433
53462
  } catch (error) {
53434
53463
  this.context.logger.warn(
53435
53464
  `Ignoring invalid WAGO heartbeat: ${error instanceof Error ? error.message : String(error)}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attraccess/plugin-wago",
3
- "version": "0.1.0-nightly.951.1",
3
+ "version": "0.1.0-nightly.953.1",
4
4
  "description": "Official Attraccess integration for WAGO CC100 controllers.",
5
5
  "keywords": [
6
6
  "attraccess-plugin",