@camstack/addon-provider-gree 0.2.35 → 0.2.37

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.
package/dist/addon.js CHANGED
@@ -5919,6 +5919,40 @@ var BaseAddon = class {
5919
5919
  deviceSettingsSchema() {
5920
5920
  return null;
5921
5921
  }
5922
+ /**
5923
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5924
+ * ARE the configuration of its integration.
5925
+ *
5926
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5927
+ * operator should find on the addon's integration page (System →
5928
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5929
+ * addon. Empty (the default) means the addon has no integration-level
5930
+ * settings and no such surface is offered — this is opt-in, because whether
5931
+ * an addon's configuration IS its integration's configuration depends on the
5932
+ * nature of the integration.
5933
+ *
5934
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5935
+ * the ONE global schema, in the ONE addon store, written by the ONE
5936
+ * `updateGlobalSettings` path. There is deliberately no
5937
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5938
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5939
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5940
+ *
5941
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5942
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5943
+ * removed with the reason recorded at
5944
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5945
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5946
+ * marker sprinkled across sections also has to borrow a field that already
5947
+ * means something else; borrowing `section.tab` put the literal word
5948
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5949
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5950
+ * supersedes D268). One declaration, in one place, next to the schema whose
5951
+ * ids it names.
5952
+ */
5953
+ integrationSettingSections() {
5954
+ return [];
5955
+ }
5922
5956
  async getGlobalSettings(overlay, cap, nodeId) {
5923
5957
  const schema = this.globalSettingsSchema(cap);
5924
5958
  if (!schema) return { sections: [] };
@@ -5929,6 +5963,55 @@ var BaseAddon = class {
5929
5963
  } : projected);
5930
5964
  }
5931
5965
  /**
5966
+ * The integration-level view of this addon's settings: exactly the sections
5967
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
5968
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
5969
+ *
5970
+ * Returns `null` when the addon declared nothing — an addon that opts out has
5971
+ * no integration settings surface at all, rather than an empty one that reads
5972
+ * as a failed load.
5973
+ *
5974
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
5975
+ * and not in whichever UI happens to render this:
5976
+ *
5977
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
5978
+ * shown here is the same field, with the same bare key, that the addon's
5979
+ * own page shows. There is no integration-specific writer — callers save
5980
+ * through `updateGlobalSettings` — so a second store key is unreachable,
5981
+ * not merely discouraged.
5982
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
5983
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
5984
+ * such a field silently picked would be a wrong answer for the operator
5985
+ * who opened the page (D266).
5986
+ * 3. **No silent typo.** A declared id that names no section throws. The
5987
+ * alternative — skip it — turns a rename into a surface that quietly
5988
+ * empties, which looks exactly like an addon with nothing to configure.
5989
+ */
5990
+ async getIntegrationSettings(nodeId) {
5991
+ const declared = this.integrationSettingSections();
5992
+ if (declared.length === 0) return null;
5993
+ const schema = this.globalSettingsSchema();
5994
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
5995
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
5996
+ const sections = [];
5997
+ for (const id of declared) {
5998
+ const section = byId.get(id);
5999
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
6000
+ const fields = dropPerNodeFields(section.fields);
6001
+ if (fields.length === 0) continue;
6002
+ sections.push({
6003
+ ...section,
6004
+ fields
6005
+ });
6006
+ }
6007
+ if (sections.length === 0) return null;
6008
+ const projected = await this.resolveGlobalStore(nodeId);
6009
+ return hydrateSchema({
6010
+ ...schema,
6011
+ sections
6012
+ }, projected);
6013
+ }
6014
+ /**
5932
6015
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5933
6016
  * every `perNode: true` field carries THAT node's scoped value on its bare
5934
6017
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6232,6 +6315,41 @@ var BaseAddon = class {
6232
6315
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6233
6316
  * don't declare `perNode` and are excluded by the `in` narrowing.
6234
6317
  */
6318
+ /**
6319
+ * The same fields with every `perNode: true` one removed, recursing into layout
6320
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6321
+ * with no child is dropped rather than rendered empty.
6322
+ *
6323
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6324
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6325
+ */
6326
+ function dropPerNodeFields(fields) {
6327
+ const kept = [];
6328
+ for (const field of fields) {
6329
+ if (field.type === "group") {
6330
+ const inner = dropPerNodeFields(field.fields);
6331
+ if (inner.length > 0) kept.push({
6332
+ ...field,
6333
+ fields: inner
6334
+ });
6335
+ continue;
6336
+ }
6337
+ if (field.type === "sub-tabs") {
6338
+ const tabs = field.tabs.map((tab) => ({
6339
+ ...tab,
6340
+ fields: dropPerNodeFields(tab.fields)
6341
+ })).filter((tab) => tab.fields.length > 0);
6342
+ if (tabs.length > 0) kept.push({
6343
+ ...field,
6344
+ tabs
6345
+ });
6346
+ continue;
6347
+ }
6348
+ if ("perNode" in field && field.perNode === true) continue;
6349
+ kept.push(field);
6350
+ }
6351
+ return kept;
6352
+ }
6235
6353
  function collectPerNodeFieldKeys(fields) {
6236
6354
  const collected = [];
6237
6355
  for (const field of fields) {
@@ -9401,6 +9519,9 @@ method(object({
9401
9519
  kind: "mutation",
9402
9520
  auth: "admin"
9403
9521
  }), method(object({
9522
+ addonId: string(),
9523
+ nodeId: string().optional()
9524
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9404
9525
  addonId: string(),
9405
9526
  deviceId: number(),
9406
9527
  nodeId: string().optional()
@@ -31494,6 +31615,12 @@ Object.freeze({
31494
31615
  addonId: null,
31495
31616
  access: "view"
31496
31617
  },
31618
+ "addonSettings.getIntegrationSettings": {
31619
+ capName: "addon-settings",
31620
+ capScope: "system",
31621
+ addonId: null,
31622
+ access: "view"
31623
+ },
31497
31624
  "addonSettings.updateDeviceSettings": {
31498
31625
  capName: "addon-settings",
31499
31626
  capScope: "system",
package/dist/addon.mjs CHANGED
@@ -5918,6 +5918,40 @@ var BaseAddon = class {
5918
5918
  deviceSettingsSchema() {
5919
5919
  return null;
5920
5920
  }
5921
+ /**
5922
+ * INTEGRATION-LEVEL SETTINGS — declare which of this addon's global sections
5923
+ * ARE the configuration of its integration.
5924
+ *
5925
+ * Return the `ConfigSection.id`s, from {@link globalSettingsSchema}, that an
5926
+ * operator should find on the addon's integration page (System →
5927
+ * Integrations → <name>) rather than only in the cluster-wide list of every
5928
+ * addon. Empty (the default) means the addon has no integration-level
5929
+ * settings and no such surface is offered — this is opt-in, because whether
5930
+ * an addon's configuration IS its integration's configuration depends on the
5931
+ * nature of the integration.
5932
+ *
5933
+ * WHAT THIS IS NOT. It is not a scope. The selected sections keep living in
5934
+ * the ONE global schema, in the ONE addon store, written by the ONE
5935
+ * `updateGlobalSettings` path. There is deliberately no
5936
+ * `updateIntegrationSettings`: a second write path is how a surface acquires
5937
+ * a second store key, and this repo has shipped that twice (`btmPath@hub`,
5938
+ * D266). Selecting sections cannot introduce a key that selecting cannot.
5939
+ *
5940
+ * WHY IT IS A LIST OF SECTION IDS AND NOT A MARKER ON THE SECTION.
5941
+ * `ConfigFieldBase` used to carry `scope?: 'device' | 'global'` and it was
5942
+ * removed with the reason recorded at
5943
+ * `packages/types/src/interfaces/config-ui.ts:249` — *"a field's scope is
5944
+ * determined by WHICH schema it lives in, not by a field-level marker."* A
5945
+ * marker sprinkled across sections also has to borrow a field that already
5946
+ * means something else; borrowing `section.tab` put the literal word
5947
+ * "integration" into an operator-facing tab bar, because `tab` means "how to
5948
+ * GROUP this visually" and cannot also mean "where this lives" (D269
5949
+ * supersedes D268). One declaration, in one place, next to the schema whose
5950
+ * ids it names.
5951
+ */
5952
+ integrationSettingSections() {
5953
+ return [];
5954
+ }
5921
5955
  async getGlobalSettings(overlay, cap, nodeId) {
5922
5956
  const schema = this.globalSettingsSchema(cap);
5923
5957
  if (!schema) return { sections: [] };
@@ -5928,6 +5962,55 @@ var BaseAddon = class {
5928
5962
  } : projected);
5929
5963
  }
5930
5964
  /**
5965
+ * The integration-level view of this addon's settings: exactly the sections
5966
+ * named by {@link integrationSettingSections}, hydrated from the SAME store
5967
+ * `getGlobalSettings` reads, and narrowed to cluster-scoped fields.
5968
+ *
5969
+ * Returns `null` when the addon declared nothing — an addon that opts out has
5970
+ * no integration settings surface at all, rather than an empty one that reads
5971
+ * as a failed load.
5972
+ *
5973
+ * Three properties hold BY CONSTRUCTION, which is why they are here in core
5974
+ * and not in whichever UI happens to render this:
5975
+ *
5976
+ * 1. **One key.** The payload is a SUBSET of the global schema, so a field
5977
+ * shown here is the same field, with the same bare key, that the addon's
5978
+ * own page shows. There is no integration-specific writer — callers save
5979
+ * through `updateGlobalSettings` — so a second store key is unreachable,
5980
+ * not merely discouraged.
5981
+ * 2. **No node scope.** `perNode: true` fields are DROPPED. Their store key
5982
+ * is `<key>@<nodeId>` and an integration is not a node; whichever node
5983
+ * such a field silently picked would be a wrong answer for the operator
5984
+ * who opened the page (D266).
5985
+ * 3. **No silent typo.** A declared id that names no section throws. The
5986
+ * alternative — skip it — turns a rename into a surface that quietly
5987
+ * empties, which looks exactly like an addon with nothing to configure.
5988
+ */
5989
+ async getIntegrationSettings(nodeId) {
5990
+ const declared = this.integrationSettingSections();
5991
+ if (declared.length === 0) return null;
5992
+ const schema = this.globalSettingsSchema();
5993
+ if (!schema) throw new Error(`${this.constructor.name}: integrationSettingSections() names [${declared.join(", ")}] but globalSettingsSchema() returns null.`);
5994
+ const byId = new Map(schema.sections.map((section) => [section.id, section]));
5995
+ const sections = [];
5996
+ for (const id of declared) {
5997
+ const section = byId.get(id);
5998
+ if (!section) throw new Error(`${this.constructor.name}: integrationSettingSections() names unknown section "${id}". Known sections: [${[...byId.keys()].join(", ")}].`);
5999
+ const fields = dropPerNodeFields(section.fields);
6000
+ if (fields.length === 0) continue;
6001
+ sections.push({
6002
+ ...section,
6003
+ fields
6004
+ });
6005
+ }
6006
+ if (sections.length === 0) return null;
6007
+ const projected = await this.resolveGlobalStore(nodeId);
6008
+ return hydrateSchema({
6009
+ ...schema,
6010
+ sections
6011
+ }, projected);
6012
+ }
6013
+ /**
5931
6014
  * The raw addon store PROJECTED onto the target node's bare per-node keys:
5932
6015
  * every `perNode: true` field carries THAT node's scoped value on its bare
5933
6016
  * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
@@ -6231,6 +6314,41 @@ var BaseAddon = class {
6231
6314
  * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6232
6315
  * don't declare `perNode` and are excluded by the `in` narrowing.
6233
6316
  */
6317
+ /**
6318
+ * The same fields with every `perNode: true` one removed, recursing into layout
6319
+ * containers exactly as {@link collectPerNodeFieldKeys} does. A container left
6320
+ * with no child is dropped rather than rendered empty.
6321
+ *
6322
+ * Used by `getIntegrationSettings`: an integration is not a node, so a field
6323
+ * whose store key is `<key>@<nodeId>` has no node to belong to there.
6324
+ */
6325
+ function dropPerNodeFields(fields) {
6326
+ const kept = [];
6327
+ for (const field of fields) {
6328
+ if (field.type === "group") {
6329
+ const inner = dropPerNodeFields(field.fields);
6330
+ if (inner.length > 0) kept.push({
6331
+ ...field,
6332
+ fields: inner
6333
+ });
6334
+ continue;
6335
+ }
6336
+ if (field.type === "sub-tabs") {
6337
+ const tabs = field.tabs.map((tab) => ({
6338
+ ...tab,
6339
+ fields: dropPerNodeFields(tab.fields)
6340
+ })).filter((tab) => tab.fields.length > 0);
6341
+ if (tabs.length > 0) kept.push({
6342
+ ...field,
6343
+ tabs
6344
+ });
6345
+ continue;
6346
+ }
6347
+ if ("perNode" in field && field.perNode === true) continue;
6348
+ kept.push(field);
6349
+ }
6350
+ return kept;
6351
+ }
6234
6352
  function collectPerNodeFieldKeys(fields) {
6235
6353
  const collected = [];
6236
6354
  for (const field of fields) {
@@ -9400,6 +9518,9 @@ method(object({
9400
9518
  kind: "mutation",
9401
9519
  auth: "admin"
9402
9520
  }), method(object({
9521
+ addonId: string(),
9522
+ nodeId: string().optional()
9523
+ }), SettingsSchemaWithValuesSchema.nullable()), method(object({
9403
9524
  addonId: string(),
9404
9525
  deviceId: number(),
9405
9526
  nodeId: string().optional()
@@ -31493,6 +31614,12 @@ Object.freeze({
31493
31614
  addonId: null,
31494
31615
  access: "view"
31495
31616
  },
31617
+ "addonSettings.getIntegrationSettings": {
31618
+ capName: "addon-settings",
31619
+ capScope: "system",
31620
+ addonId: null,
31621
+ access: "view"
31622
+ },
31496
31623
  "addonSettings.updateDeviceSettings": {
31497
31624
  capName: "addon-settings",
31498
31625
  capScope: "system",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-gree",
3
- "version": "0.2.35",
3
+ "version": "0.2.37",
4
4
  "description": "Gree air-conditioner device-provider addon for CamStack — wraps the @apocaliss92/nodegree local-UDP client (LAN discovery + AES control), exposing climate-control and fan-control",
5
5
  "keywords": [
6
6
  "camstack",