@matter/node 0.16.0-alpha.0-20251101-70c8d51d7 → 0.16.0-alpha.0-20251103-b47ffa15b

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 (159) hide show
  1. package/dist/cjs/behavior/Behavior.d.ts +2 -2
  2. package/dist/cjs/behavior/Behavior.d.ts.map +1 -1
  3. package/dist/cjs/behavior/Behavior.js +1 -1
  4. package/dist/cjs/behavior/Behavior.js.map +1 -1
  5. package/dist/cjs/behavior/Events.js.map +1 -1
  6. package/dist/cjs/behavior/cluster/ClusterBehavior.d.ts +3 -2
  7. package/dist/cjs/behavior/cluster/ClusterBehavior.d.ts.map +1 -1
  8. package/dist/cjs/behavior/cluster/ClusterBehavior.js.map +1 -1
  9. package/dist/cjs/behavior/cluster/ClusterBehaviorUtil.js +1 -1
  10. package/dist/cjs/behavior/cluster/ClusterBehaviorUtil.js.map +1 -1
  11. package/dist/cjs/behavior/internal/BehaviorBacking.js +1 -1
  12. package/dist/cjs/behavior/internal/BehaviorBacking.js.map +1 -1
  13. package/dist/cjs/behavior/system/mqtt/MqttInterface.js +1 -1
  14. package/dist/cjs/behavior/system/mqtt/MqttInterface.js.map +1 -1
  15. package/dist/cjs/behaviors/basic-information/BasicInformationServer.d.ts +2 -2
  16. package/dist/cjs/behaviors/basic-information/BasicInformationServer.d.ts.map +1 -1
  17. package/dist/cjs/behaviors/basic-information/BasicInformationServer.js +0 -3
  18. package/dist/cjs/behaviors/basic-information/BasicInformationServer.js.map +1 -1
  19. package/dist/cjs/behaviors/bridged-device-basic-information/BridgedDeviceBasicInformationServer.d.ts +1 -1
  20. package/dist/cjs/behaviors/bridged-device-basic-information/BridgedDeviceBasicInformationServer.d.ts.map +1 -1
  21. package/dist/cjs/behaviors/color-control/ColorControlServer.d.ts +3 -3
  22. package/dist/cjs/behaviors/color-control/ColorControlServer.d.ts.map +1 -1
  23. package/dist/cjs/behaviors/color-control/ColorControlServer.js +118 -3
  24. package/dist/cjs/behaviors/color-control/ColorControlServer.js.map +1 -1
  25. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +1 -1
  26. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  27. package/dist/cjs/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  28. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.d.ts +1 -1
  29. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  30. package/dist/cjs/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  31. package/dist/cjs/behaviors/groups/GroupsServer.d.ts.map +1 -1
  32. package/dist/cjs/behaviors/groups/GroupsServer.js +9 -1
  33. package/dist/cjs/behaviors/groups/GroupsServer.js.map +1 -1
  34. package/dist/cjs/behaviors/level-control/LevelControlServer.d.ts +5 -5
  35. package/dist/cjs/behaviors/level-control/LevelControlServer.d.ts.map +1 -1
  36. package/dist/cjs/behaviors/level-control/LevelControlServer.js +54 -27
  37. package/dist/cjs/behaviors/level-control/LevelControlServer.js.map +1 -1
  38. package/dist/cjs/behaviors/on-off/OnOffServer.d.ts +3 -6
  39. package/dist/cjs/behaviors/on-off/OnOffServer.d.ts.map +1 -1
  40. package/dist/cjs/behaviors/on-off/OnOffServer.js +59 -7
  41. package/dist/cjs/behaviors/on-off/OnOffServer.js.map +1 -1
  42. package/dist/cjs/behaviors/scenes-management/ScenesManagementServer.d.ts +122 -3
  43. package/dist/cjs/behaviors/scenes-management/ScenesManagementServer.d.ts.map +1 -1
  44. package/dist/cjs/behaviors/scenes-management/ScenesManagementServer.js +909 -1
  45. package/dist/cjs/behaviors/scenes-management/ScenesManagementServer.js.map +2 -2
  46. package/dist/cjs/behaviors/switch/SwitchServer.d.ts +1 -1
  47. package/dist/cjs/behaviors/switch/SwitchServer.d.ts.map +1 -1
  48. package/dist/cjs/behaviors/switch/SwitchServer.js.map +1 -1
  49. package/dist/cjs/behaviors/thermostat/AtomicWriteHandler.js +2 -2
  50. package/dist/cjs/behaviors/thermostat/AtomicWriteHandler.js.map +1 -1
  51. package/dist/cjs/behaviors/thermostat/ThermostatServer.d.ts +1 -1
  52. package/dist/cjs/behaviors/thermostat/ThermostatServer.d.ts.map +1 -1
  53. package/dist/cjs/behaviors/thermostat/ThermostatServer.js.map +1 -1
  54. package/dist/cjs/devices/color-temperature-light.d.ts +4 -4
  55. package/dist/cjs/devices/dimmable-light.d.ts +4 -4
  56. package/dist/cjs/devices/dimmable-plug-in-unit.d.ts +4 -4
  57. package/dist/cjs/devices/extended-color-light.d.ts +4 -4
  58. package/dist/cjs/devices/mounted-dimmable-load-control.d.ts +4 -4
  59. package/dist/cjs/devices/mounted-on-off-control.d.ts +4 -4
  60. package/dist/cjs/devices/on-off-light.d.ts +4 -4
  61. package/dist/cjs/devices/on-off-plug-in-unit.d.ts +4 -4
  62. package/dist/cjs/endpoint/Agent.d.ts +5 -0
  63. package/dist/cjs/endpoint/Agent.d.ts.map +1 -1
  64. package/dist/cjs/endpoint/Agent.js +9 -0
  65. package/dist/cjs/endpoint/Agent.js.map +1 -1
  66. package/dist/cjs/endpoint/properties/Behaviors.js +1 -1
  67. package/dist/cjs/endpoint/properties/Behaviors.js.map +1 -1
  68. package/dist/cjs/node/integration/ProtocolService.js +1 -1
  69. package/dist/cjs/node/integration/ProtocolService.js.map +1 -1
  70. package/dist/esm/behavior/Behavior.d.ts +2 -2
  71. package/dist/esm/behavior/Behavior.d.ts.map +1 -1
  72. package/dist/esm/behavior/Behavior.js +1 -1
  73. package/dist/esm/behavior/Behavior.js.map +1 -1
  74. package/dist/esm/behavior/Events.js.map +1 -1
  75. package/dist/esm/behavior/cluster/ClusterBehavior.d.ts +3 -2
  76. package/dist/esm/behavior/cluster/ClusterBehavior.d.ts.map +1 -1
  77. package/dist/esm/behavior/cluster/ClusterBehavior.js.map +1 -1
  78. package/dist/esm/behavior/cluster/ClusterBehaviorUtil.js +1 -1
  79. package/dist/esm/behavior/cluster/ClusterBehaviorUtil.js.map +1 -1
  80. package/dist/esm/behavior/internal/BehaviorBacking.js +1 -1
  81. package/dist/esm/behavior/internal/BehaviorBacking.js.map +1 -1
  82. package/dist/esm/behavior/system/mqtt/MqttInterface.js +1 -1
  83. package/dist/esm/behavior/system/mqtt/MqttInterface.js.map +1 -1
  84. package/dist/esm/behaviors/basic-information/BasicInformationServer.d.ts +2 -2
  85. package/dist/esm/behaviors/basic-information/BasicInformationServer.d.ts.map +1 -1
  86. package/dist/esm/behaviors/basic-information/BasicInformationServer.js +1 -4
  87. package/dist/esm/behaviors/basic-information/BasicInformationServer.js.map +1 -1
  88. package/dist/esm/behaviors/bridged-device-basic-information/BridgedDeviceBasicInformationServer.d.ts +1 -1
  89. package/dist/esm/behaviors/bridged-device-basic-information/BridgedDeviceBasicInformationServer.d.ts.map +1 -1
  90. package/dist/esm/behaviors/color-control/ColorControlServer.d.ts +3 -3
  91. package/dist/esm/behaviors/color-control/ColorControlServer.d.ts.map +1 -1
  92. package/dist/esm/behaviors/color-control/ColorControlServer.js +118 -3
  93. package/dist/esm/behaviors/color-control/ColorControlServer.js.map +1 -1
  94. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts +1 -1
  95. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.d.ts.map +1 -1
  96. package/dist/esm/behaviors/general-diagnostics/GeneralDiagnosticsServer.js.map +1 -1
  97. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.d.ts +1 -1
  98. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.d.ts.map +1 -1
  99. package/dist/esm/behaviors/group-key-management/GroupKeyManagementServer.js.map +1 -1
  100. package/dist/esm/behaviors/groups/GroupsServer.d.ts.map +1 -1
  101. package/dist/esm/behaviors/groups/GroupsServer.js +9 -1
  102. package/dist/esm/behaviors/groups/GroupsServer.js.map +1 -1
  103. package/dist/esm/behaviors/level-control/LevelControlServer.d.ts +5 -5
  104. package/dist/esm/behaviors/level-control/LevelControlServer.d.ts.map +1 -1
  105. package/dist/esm/behaviors/level-control/LevelControlServer.js +55 -28
  106. package/dist/esm/behaviors/level-control/LevelControlServer.js.map +1 -1
  107. package/dist/esm/behaviors/on-off/OnOffServer.d.ts +3 -6
  108. package/dist/esm/behaviors/on-off/OnOffServer.d.ts.map +1 -1
  109. package/dist/esm/behaviors/on-off/OnOffServer.js +59 -7
  110. package/dist/esm/behaviors/on-off/OnOffServer.js.map +1 -1
  111. package/dist/esm/behaviors/scenes-management/ScenesManagementServer.d.ts +122 -3
  112. package/dist/esm/behaviors/scenes-management/ScenesManagementServer.d.ts.map +1 -1
  113. package/dist/esm/behaviors/scenes-management/ScenesManagementServer.js +960 -1
  114. package/dist/esm/behaviors/scenes-management/ScenesManagementServer.js.map +2 -2
  115. package/dist/esm/behaviors/switch/SwitchServer.d.ts +1 -1
  116. package/dist/esm/behaviors/switch/SwitchServer.d.ts.map +1 -1
  117. package/dist/esm/behaviors/switch/SwitchServer.js.map +1 -1
  118. package/dist/esm/behaviors/thermostat/AtomicWriteHandler.js +2 -2
  119. package/dist/esm/behaviors/thermostat/AtomicWriteHandler.js.map +1 -1
  120. package/dist/esm/behaviors/thermostat/ThermostatServer.d.ts +1 -1
  121. package/dist/esm/behaviors/thermostat/ThermostatServer.d.ts.map +1 -1
  122. package/dist/esm/behaviors/thermostat/ThermostatServer.js.map +1 -1
  123. package/dist/esm/devices/color-temperature-light.d.ts +4 -4
  124. package/dist/esm/devices/dimmable-light.d.ts +4 -4
  125. package/dist/esm/devices/dimmable-plug-in-unit.d.ts +4 -4
  126. package/dist/esm/devices/extended-color-light.d.ts +4 -4
  127. package/dist/esm/devices/mounted-dimmable-load-control.d.ts +4 -4
  128. package/dist/esm/devices/mounted-on-off-control.d.ts +4 -4
  129. package/dist/esm/devices/on-off-light.d.ts +4 -4
  130. package/dist/esm/devices/on-off-plug-in-unit.d.ts +4 -4
  131. package/dist/esm/endpoint/Agent.d.ts +5 -0
  132. package/dist/esm/endpoint/Agent.d.ts.map +1 -1
  133. package/dist/esm/endpoint/Agent.js +9 -0
  134. package/dist/esm/endpoint/Agent.js.map +1 -1
  135. package/dist/esm/endpoint/properties/Behaviors.js +1 -1
  136. package/dist/esm/endpoint/properties/Behaviors.js.map +1 -1
  137. package/dist/esm/node/integration/ProtocolService.js +1 -1
  138. package/dist/esm/node/integration/ProtocolService.js.map +1 -1
  139. package/package.json +7 -7
  140. package/src/behavior/Behavior.ts +2 -2
  141. package/src/behavior/Events.ts +1 -1
  142. package/src/behavior/cluster/ClusterBehavior.ts +4 -2
  143. package/src/behavior/cluster/ClusterBehaviorUtil.ts +1 -1
  144. package/src/behavior/internal/BehaviorBacking.ts +1 -1
  145. package/src/behavior/system/mqtt/MqttInterface.ts +1 -1
  146. package/src/behaviors/basic-information/BasicInformationServer.ts +3 -7
  147. package/src/behaviors/color-control/ColorControlServer.ts +132 -3
  148. package/src/behaviors/general-diagnostics/GeneralDiagnosticsServer.ts +1 -1
  149. package/src/behaviors/group-key-management/GroupKeyManagementServer.ts +2 -2
  150. package/src/behaviors/groups/GroupsServer.ts +13 -1
  151. package/src/behaviors/level-control/LevelControlServer.ts +72 -29
  152. package/src/behaviors/on-off/OnOffServer.ts +78 -9
  153. package/src/behaviors/scenes-management/ScenesManagementServer.ts +1123 -3
  154. package/src/behaviors/switch/SwitchServer.ts +1 -1
  155. package/src/behaviors/thermostat/AtomicWriteHandler.ts +4 -4
  156. package/src/behaviors/thermostat/ThermostatServer.ts +1 -1
  157. package/src/endpoint/Agent.ts +10 -0
  158. package/src/endpoint/properties/Behaviors.ts +1 -1
  159. package/src/node/integration/ProtocolService.ts +1 -1
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
13
  var __export = (target, all) => {
7
14
  for (var name in all)
8
15
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,17 +23,918 @@ var __copyProps = (to, from, except, desc) => {
16
23
  return to;
17
24
  };
18
25
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)];
27
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
28
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
29
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
30
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
31
+ var __runInitializers = (array, flags, self, value) => {
32
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
33
+ return value;
34
+ };
35
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
36
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
37
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
38
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
39
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
40
+ return __privateGet(this, extra);
41
+ }, set [name](x) {
42
+ return __privateSet(this, extra, x);
43
+ } }, name));
44
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
45
+ for (var i = decorators.length - 1; i >= 0; i--) {
46
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
47
+ if (k) {
48
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
49
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
50
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
51
+ }
52
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
53
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
54
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
55
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
56
+ }
57
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
58
+ };
59
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
60
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
61
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
62
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
63
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
64
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
19
65
  var ScenesManagementServer_exports = {};
20
66
  __export(ScenesManagementServer_exports, {
67
+ DataTypeToSceneAttributeDataMap: () => DataTypeToSceneAttributeDataMap,
21
68
  ScenesManagementServer: () => ScenesManagementServer
22
69
  });
23
70
  module.exports = __toCommonJS(ScenesManagementServer_exports);
71
+ var import_ClusterBehavior = require("#behavior/cluster/ClusterBehavior.js");
72
+ var import_scenes_management = require("#clusters/scenes-management");
73
+ var import_general = require("#general");
74
+ var import_model = require("#model");
75
+ var import_protocol = require("#protocol");
76
+ var import_types = require("#types");
77
+ var import_general2 = require("@matter/general");
24
78
  var import_ScenesManagementBehavior = require("./ScenesManagementBehavior.js");
25
79
  /**
26
80
  * @license
27
81
  * Copyright 2022-2025 Matter.js Authors
28
82
  * SPDX-License-Identifier: Apache-2.0
29
83
  */
30
- class ScenesManagementServer extends import_ScenesManagementBehavior.ScenesManagementBehavior {
84
+ const logger = import_general.Logger.get("ScenesManagementServer");
85
+ const UNDEFINED_SCENE_ID = 255;
86
+ const GLOBAL_SCENE_ID = 0;
87
+ const UNDEFINED_GROUP = (0, import_types.GroupId)(0);
88
+ var AttributeValuePairDataFields = /* @__PURE__ */ ((AttributeValuePairDataFields2) => {
89
+ AttributeValuePairDataFields2["ValueUnsigned8"] = "valueUnsigned8";
90
+ AttributeValuePairDataFields2["ValueSigned8"] = "valueSigned8";
91
+ AttributeValuePairDataFields2["ValueUnsigned16"] = "valueUnsigned16";
92
+ AttributeValuePairDataFields2["ValueSigned16"] = "valueSigned16";
93
+ AttributeValuePairDataFields2["ValueUnsigned32"] = "valueUnsigned32";
94
+ AttributeValuePairDataFields2["ValueSigned32"] = "valueSigned32";
95
+ AttributeValuePairDataFields2["ValueUnsigned64"] = "valueUnsigned64";
96
+ AttributeValuePairDataFields2["ValueSigned64"] = "valueSigned64";
97
+ return AttributeValuePairDataFields2;
98
+ })(AttributeValuePairDataFields || {});
99
+ const DataTypeToSceneAttributeDataMap = {
100
+ [import_model.bool.name]: "valueUnsigned8" /* ValueUnsigned8 */,
101
+ [import_model.map8.name]: "valueUnsigned8" /* ValueUnsigned8 */,
102
+ [import_model.uint8.name]: "valueUnsigned8" /* ValueUnsigned8 */,
103
+ [import_model.int8.name]: "valueSigned8" /* ValueSigned8 */,
104
+ [import_model.uint16.name]: "valueUnsigned16" /* ValueUnsigned16 */,
105
+ [import_model.map16.name]: "valueUnsigned16" /* ValueUnsigned16 */,
106
+ [import_model.int16.name]: "valueSigned16" /* ValueSigned16 */,
107
+ [import_model.uint24.name]: "valueUnsigned32" /* ValueUnsigned32 */,
108
+ [import_model.uint32.name]: "valueUnsigned32" /* ValueUnsigned32 */,
109
+ [import_model.map32.name]: "valueUnsigned32" /* ValueUnsigned32 */,
110
+ [import_model.int32.name]: "valueSigned32" /* ValueSigned32 */,
111
+ [import_model.uint40.name]: "valueUnsigned64" /* ValueUnsigned64 */,
112
+ [import_model.uint48.name]: "valueUnsigned64" /* ValueUnsigned64 */,
113
+ [import_model.uint56.name]: "valueUnsigned64" /* ValueUnsigned64 */,
114
+ [import_model.uint64.name]: "valueUnsigned64" /* ValueUnsigned64 */,
115
+ [import_model.map64.name]: "valueUnsigned64" /* ValueUnsigned64 */,
116
+ [import_model.int40.name]: "valueSigned64" /* ValueSigned64 */,
117
+ [import_model.int48.name]: "valueSigned64" /* ValueSigned64 */,
118
+ [import_model.int56.name]: "valueSigned64" /* ValueSigned64 */,
119
+ [import_model.int64.name]: "valueSigned64" /* ValueSigned64 */
120
+ };
121
+ import_scenes_management.ScenesManagement.Cluster.commands = {
122
+ ...import_scenes_management.ScenesManagement.Cluster.commands,
123
+ addScene: (0, import_types.Command)(
124
+ 0,
125
+ (0, import_types.TlvObject)({
126
+ groupId: (0, import_types.TlvField)(0, import_types.TlvGroupId),
127
+ sceneId: (0, import_types.TlvField)(1, import_types.TlvUInt8),
128
+ transitionTime: (0, import_types.TlvField)(2, import_types.TlvUInt32),
129
+ sceneName: (0, import_types.TlvField)(3, import_types.TlvString),
130
+ extensionFieldSetStructs: (0, import_types.TlvField)(4, (0, import_types.TlvArray)(import_scenes_management.ScenesManagement.TlvExtensionFieldSet))
131
+ }),
132
+ 0,
133
+ import_scenes_management.ScenesManagement.TlvAddSceneResponse,
134
+ { invokeAcl: import_model.AccessLevel.Manage }
135
+ ),
136
+ viewScene: (0, import_types.Command)(
137
+ 1,
138
+ (0, import_types.TlvObject)({
139
+ groupId: (0, import_types.TlvField)(0, import_types.TlvGroupId),
140
+ sceneId: (0, import_types.TlvField)(1, import_types.TlvUInt8)
141
+ }),
142
+ 1,
143
+ import_scenes_management.ScenesManagement.TlvViewSceneResponse
144
+ ),
145
+ removeScene: (0, import_types.Command)(
146
+ 2,
147
+ (0, import_types.TlvObject)({
148
+ groupId: (0, import_types.TlvField)(0, import_types.TlvGroupId),
149
+ sceneId: (0, import_types.TlvField)(1, import_types.TlvUInt8)
150
+ }),
151
+ 2,
152
+ import_scenes_management.ScenesManagement.TlvRemoveSceneResponse,
153
+ { invokeAcl: import_model.AccessLevel.Manage }
154
+ ),
155
+ storeScene: (0, import_types.Command)(
156
+ 4,
157
+ (0, import_types.TlvObject)({
158
+ groupId: (0, import_types.TlvField)(0, import_types.TlvGroupId),
159
+ sceneId: (0, import_types.TlvField)(1, import_types.TlvUInt8)
160
+ }),
161
+ 4,
162
+ import_scenes_management.ScenesManagement.TlvStoreSceneResponse,
163
+ {
164
+ invokeAcl: import_model.AccessLevel.Manage
165
+ }
166
+ ),
167
+ copyScene: (0, import_types.OptionalCommand)(
168
+ 64,
169
+ (0, import_types.TlvObject)({
170
+ mode: (0, import_types.TlvField)(0, (0, import_types.TlvBitmap)(import_types.TlvUInt8, import_scenes_management.ScenesManagement.CopyMode)),
171
+ groupIdentifierFrom: (0, import_types.TlvField)(1, import_types.TlvGroupId),
172
+ sceneIdentifierFrom: (0, import_types.TlvField)(2, import_types.TlvUInt8),
173
+ groupIdentifierTo: (0, import_types.TlvField)(3, import_types.TlvGroupId),
174
+ sceneIdentifierTo: (0, import_types.TlvField)(4, import_types.TlvUInt8)
175
+ }),
176
+ 64,
177
+ import_scenes_management.ScenesManagement.TlvCopySceneResponse,
178
+ {
179
+ invokeAcl: import_model.AccessLevel.Manage
180
+ }
181
+ )
182
+ };
183
+ const ScenesManagementBase = import_ScenesManagementBehavior.ScenesManagementBehavior.with(import_scenes_management.ScenesManagement.Feature.SceneNames);
184
+ class ScenesManagementServer extends ScenesManagementBase {
185
+ initialize() {
186
+ if (!this.state.sceneTableSize) {
187
+ this.state.sceneTableSize = 128;
188
+ }
189
+ const fabricManager = this.endpoint.env.get(import_protocol.FabricManager);
190
+ this.#initializeFabricSceneInfo(fabricManager);
191
+ this.reactTo(fabricManager.events.deleted, this.#handleDeleteFabric);
192
+ }
193
+ /**
194
+ * Handles removal of one group in a fabric.
195
+ * This method is called by the GroupsServer implementation and also internally by this cluster.
196
+ */
197
+ removeScenesForGroupOnFabric(fabricIndex, groupId2) {
198
+ this.state.sceneTable = (0, import_general.deepCopy)(this.state.sceneTable).filter(
199
+ (s) => !(s.fabricIndex === fabricIndex && s.sceneGroupId === groupId2)
200
+ );
201
+ if (this.internal.monitorSceneAttributesForFabric === fabricIndex) {
202
+ const fabricSceneInfo = this.#fabricSceneInfoForFabric(fabricIndex);
203
+ if (fabricSceneInfo !== void 0) {
204
+ if (fabricSceneInfo.currentGroup === groupId2 && fabricSceneInfo.sceneValid) {
205
+ fabricSceneInfo.sceneValid = false;
206
+ this.internal.monitorSceneAttributesForFabric = null;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ /** Handles removal of all groups in a fabric. This method is called by the GroupsServer implementation. */
212
+ removeScenesForAllGroupsForFabric(fabricIndex) {
213
+ this.state.sceneTable = (0, import_general.deepCopy)(this.state.sceneTable).filter((s) => s.fabricIndex !== fabricIndex);
214
+ this.#invalidateFabricSceneInfoForFabric(fabricIndex);
215
+ }
216
+ /** Validates the groupId and sceneId parameters of scene commands and returns convenient data for further processing */
217
+ #assertSceneCommandParameter(groupIdToValidate, sceneId) {
218
+ (0, import_protocol.assertRemoteActor)(this.context);
219
+ const fabric = this.context.session.associatedFabric;
220
+ const fabricIndex = fabric.fabricIndex;
221
+ const isGroupSession = import_protocol.GroupSession.is(this.context.session);
222
+ let groupId2 = void 0;
223
+ if (isGroupSession && groupIdToValidate === 0) {
224
+ throw new import_types.StatusResponse.InvalidCommandError(`GroupId cannot be 0 in a Group Session`);
225
+ }
226
+ if (groupIdToValidate === 0 || this.#groupExistentInFabric(fabric, groupIdToValidate)) {
227
+ groupId2 = groupIdToValidate;
228
+ }
229
+ const existingSceneIndex = groupId2 !== void 0 && sceneId !== void 0 ? this.#sceneIndexForId(fabricIndex, sceneId, groupId2) : -1;
230
+ return {
231
+ fabric,
232
+ fabricIndex,
233
+ groupId: groupId2,
234
+ existingSceneIndex
235
+ };
236
+ }
237
+ /**
238
+ * Adds or replaces a scene entry in the scene table.
239
+ * If existingSceneIndex is -1, a new entry is added, else replaces the existing entry at that index.
240
+ * It also checks if the scene is allowed to be added depending on the fabric scene capacity.
241
+ *
242
+ * @returns The AddSceneResponse compatible response of the action
243
+ */
244
+ #addOrReplaceSceneEntry(sceneData, existingSceneIndex = -1) {
245
+ const { fabricIndex, sceneGroupId: groupId2, sceneId } = sceneData;
246
+ if (existingSceneIndex === -1) {
247
+ if (this.#scenesForFabric(fabricIndex).length >= this.#fabricSceneCapacity) {
248
+ return { status: import_types.Status.ResourceExhausted, groupId: groupId2, sceneId };
249
+ }
250
+ this.state.sceneTable.push(sceneData);
251
+ logger.debug(`Added scene ${sceneId} in group ${groupId2} for fabric ${fabricIndex}`);
252
+ this.#updateFabricSceneInfoCountsForFabric(fabricIndex);
253
+ } else {
254
+ this.state.sceneTable[existingSceneIndex] = sceneData;
255
+ logger.debug(`Updated scene ${sceneId} in group ${groupId2} for fabric ${fabricIndex}`);
256
+ }
257
+ return { status: import_types.Status.Success, groupId: groupId2, sceneId };
258
+ }
259
+ /** Implements the AddScene command */
260
+ addScene({
261
+ groupId: reqGroupId,
262
+ sceneId,
263
+ sceneName,
264
+ transitionTime,
265
+ extensionFieldSetStructs
266
+ }) {
267
+ if (sceneId > 254 || transitionTime > 6e7) {
268
+ return { status: import_types.Status.ConstraintError, groupId: reqGroupId, sceneId };
269
+ }
270
+ const { fabricIndex, groupId: groupId2, existingSceneIndex } = this.#assertSceneCommandParameter(reqGroupId, sceneId);
271
+ if (groupId2 === void 0) {
272
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId, sceneId };
273
+ }
274
+ const sceneValues = this.#decodeExtensionFieldSets(extensionFieldSetStructs);
275
+ if (sceneValues === void 0) {
276
+ return { status: import_types.Status.InvalidCommand, groupId: groupId2, sceneId };
277
+ }
278
+ return this.#addOrReplaceSceneEntry(
279
+ {
280
+ sceneGroupId: groupId2,
281
+ sceneId,
282
+ sceneName,
283
+ sceneTransitionTime: transitionTime,
284
+ sceneValues,
285
+ fabricIndex
286
+ },
287
+ existingSceneIndex
288
+ );
289
+ }
290
+ /** Implements the ViewScene command */
291
+ viewScene({
292
+ groupId: reqGroupId,
293
+ sceneId
294
+ }) {
295
+ if (sceneId > 254) {
296
+ return { status: import_types.Status.ConstraintError, groupId: reqGroupId, sceneId };
297
+ }
298
+ const { groupId: groupId2, existingSceneIndex } = this.#assertSceneCommandParameter(reqGroupId, sceneId);
299
+ if (groupId2 === void 0) {
300
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId, sceneId };
301
+ }
302
+ if (existingSceneIndex === -1) {
303
+ return { status: import_types.Status.NotFound, groupId: groupId2, sceneId };
304
+ }
305
+ const scene = this.state.sceneTable[existingSceneIndex];
306
+ return {
307
+ status: import_types.Status.Success,
308
+ groupId: scene.sceneGroupId,
309
+ sceneId: scene.sceneId,
310
+ sceneName: scene.sceneName,
311
+ transitionTime: scene.sceneTransitionTime,
312
+ extensionFieldSetStructs: this.#encodeExtensionFieldSets(scene.sceneValues)
313
+ };
314
+ }
315
+ /** Implements the RemoveScene command */
316
+ removeScene({
317
+ groupId: reqGroupId,
318
+ sceneId
319
+ }) {
320
+ if (sceneId > 254) {
321
+ return { status: import_types.Status.ConstraintError, groupId: reqGroupId, sceneId };
322
+ }
323
+ const { groupId: groupId2, existingSceneIndex, fabricIndex } = this.#assertSceneCommandParameter(reqGroupId, sceneId);
324
+ if (groupId2 === void 0) {
325
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId, sceneId };
326
+ }
327
+ if (existingSceneIndex === -1) {
328
+ return { status: import_types.Status.NotFound, groupId: groupId2, sceneId };
329
+ }
330
+ this.state.sceneTable.splice(existingSceneIndex, 1);
331
+ if (this.internal.monitorSceneAttributesForFabric === fabricIndex) {
332
+ const info = this.#fabricSceneInfoForFabric(fabricIndex);
333
+ if (info) {
334
+ if (info.currentGroup === groupId2 && info.currentScene === sceneId && info.sceneValid) {
335
+ info.sceneValid = false;
336
+ this.internal.monitorSceneAttributesForFabric = null;
337
+ }
338
+ }
339
+ }
340
+ return { status: import_types.Status.Success, groupId: groupId2, sceneId };
341
+ }
342
+ /** Implements the RemoveAllScenes command */
343
+ removeAllScenes({
344
+ groupId: reqGroupId
345
+ }) {
346
+ const { groupId: groupId2, fabricIndex } = this.#assertSceneCommandParameter(reqGroupId);
347
+ if (groupId2 === void 0) {
348
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId };
349
+ }
350
+ this.removeScenesForGroupOnFabric(fabricIndex, groupId2);
351
+ return { status: import_types.Status.Success, groupId: groupId2 };
352
+ }
353
+ /** Implements the StoreScene command */
354
+ storeScene({
355
+ groupId: reqGroupId,
356
+ sceneId
357
+ }) {
358
+ if (sceneId > 254) {
359
+ return { status: import_types.Status.ConstraintError, groupId: reqGroupId, sceneId };
360
+ }
361
+ const { groupId: groupId2, existingSceneIndex, fabricIndex } = this.#assertSceneCommandParameter(reqGroupId, sceneId);
362
+ if (groupId2 === void 0) {
363
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId, sceneId };
364
+ }
365
+ const sceneValues = this.#collectSceneAttributeValues();
366
+ let result;
367
+ if (existingSceneIndex !== -1) {
368
+ const scene = this.state.sceneTable[existingSceneIndex];
369
+ scene.sceneValues = sceneValues;
370
+ result = this.#addOrReplaceSceneEntry(scene, existingSceneIndex);
371
+ } else {
372
+ result = this.#addOrReplaceSceneEntry({
373
+ sceneGroupId: groupId2,
374
+ sceneId,
375
+ sceneName: "",
376
+ sceneTransitionTime: 0,
377
+ sceneValues,
378
+ fabricIndex
379
+ });
380
+ }
381
+ if (result.status === import_types.Status.Success) {
382
+ this.#activateSceneInFabricSceneInfo(fabricIndex, groupId2, sceneId);
383
+ }
384
+ return result;
385
+ }
386
+ /** Implements the RecallScene command */
387
+ async recallScene({ groupId: reqGroupId, sceneId, transitionTime }) {
388
+ if (sceneId > 254) {
389
+ throw new import_types.StatusResponse.ConstraintErrorError(`SceneId ${sceneId} exceeds maximum`);
390
+ }
391
+ if (transitionTime !== null && transitionTime !== void 0 && transitionTime > 6e7) {
392
+ throw new import_types.StatusResponse.ConstraintErrorError(`TransitionTime ${transitionTime} exceeds maximum`);
393
+ }
394
+ const { groupId: groupId2, existingSceneIndex, fabricIndex } = this.#assertSceneCommandParameter(reqGroupId, sceneId);
395
+ if (groupId2 === void 0) {
396
+ throw new import_types.StatusResponse.InvalidCommandError(`Invalid groupId ${reqGroupId}`);
397
+ }
398
+ if (existingSceneIndex === -1) {
399
+ throw new import_types.StatusResponse.NotFoundError(`SceneId ${sceneId} in groupId ${groupId2} not found`);
400
+ }
401
+ const scene = this.state.sceneTable[existingSceneIndex];
402
+ await this.#applySceneAttributeValues(scene.sceneValues, transitionTime);
403
+ this.#activateSceneInFabricSceneInfo(fabricIndex, groupId2, sceneId);
404
+ }
405
+ /** Implements the GetSceneMembership command */
406
+ getSceneMembership({
407
+ groupId: reqGroupId
408
+ }) {
409
+ const { groupId: groupId2, fabricIndex } = this.#assertSceneCommandParameter(reqGroupId);
410
+ if (groupId2 === void 0) {
411
+ return { status: import_types.Status.InvalidCommand, groupId: reqGroupId, capacity: null };
412
+ }
413
+ const capacity = Math.max(
414
+ Math.min(this.#fabricSceneCapacity - this.#scenesForFabric(fabricIndex).length, 254),
415
+ 0
416
+ );
417
+ return {
418
+ status: import_types.Status.Success,
419
+ groupId: groupId2,
420
+ sceneList: this.#scenesForGroup(fabricIndex, groupId2).map(({ sceneId }) => sceneId),
421
+ capacity
422
+ };
423
+ }
424
+ /** Implements the CopyScene command */
425
+ copyScene({
426
+ mode,
427
+ groupIdentifierFrom,
428
+ sceneIdentifierFrom,
429
+ groupIdentifierTo,
430
+ sceneIdentifierTo
431
+ }) {
432
+ const {
433
+ fabricIndex,
434
+ groupId: fromGroupId,
435
+ existingSceneIndex: fromSceneIndex
436
+ } = this.#assertSceneCommandParameter(groupIdentifierFrom, sceneIdentifierFrom);
437
+ const { groupId: toGroupId, existingSceneIndex: toSceneIndex } = this.#assertSceneCommandParameter(
438
+ groupIdentifierTo,
439
+ sceneIdentifierTo
440
+ );
441
+ if (fromGroupId === void 0 || toGroupId === void 0) {
442
+ return { status: import_types.Status.InvalidCommand, groupIdentifierFrom, sceneIdentifierFrom };
443
+ }
444
+ if (mode.copyAllScenes) {
445
+ const groupScenes = (0, import_general.deepCopy)(this.#scenesForGroup(fabricIndex, fromGroupId));
446
+ for (const scene2 of groupScenes) {
447
+ scene2.sceneGroupId = toGroupId;
448
+ const { status } = this.#addOrReplaceSceneEntry(
449
+ scene2,
450
+ this.#sceneIndexForId(fabricIndex, scene2.sceneId, toGroupId)
451
+ );
452
+ if (status !== import_types.Status.Success) {
453
+ return {
454
+ status,
455
+ groupIdentifierFrom,
456
+ sceneIdentifierFrom
457
+ };
458
+ }
459
+ }
460
+ return {
461
+ status: import_types.Status.Success,
462
+ groupIdentifierFrom,
463
+ sceneIdentifierFrom
464
+ };
465
+ }
466
+ if (sceneIdentifierTo > 254 || sceneIdentifierFrom > 254) {
467
+ return { status: import_types.Status.ConstraintError, groupIdentifierFrom, sceneIdentifierFrom };
468
+ }
469
+ if (fromSceneIndex === -1) {
470
+ return { status: import_types.Status.NotFound, groupIdentifierFrom, sceneIdentifierFrom };
471
+ }
472
+ const scene = (0, import_general.deepCopy)(this.state.sceneTable[fromSceneIndex]);
473
+ scene.sceneGroupId = groupIdentifierTo;
474
+ scene.sceneId = sceneIdentifierTo;
475
+ const result = this.#addOrReplaceSceneEntry(scene, toSceneIndex);
476
+ return {
477
+ status: result.status,
478
+ groupIdentifierFrom,
479
+ sceneIdentifierFrom
480
+ };
481
+ }
482
+ /** Close the observers */
483
+ async [Symbol.asyncDispose]() {
484
+ this.internal.endpointSceneAttributeObservers.close();
485
+ }
486
+ /** Method used by the OnOff cluster to recall the global scene */
487
+ async recallGlobalScene(fabricIndex) {
488
+ const existingSceneIndex = this.#sceneIndexForId(fabricIndex, GLOBAL_SCENE_ID, UNDEFINED_GROUP);
489
+ if (existingSceneIndex === -1) {
490
+ return;
491
+ }
492
+ const scene = this.state.sceneTable[existingSceneIndex];
493
+ await this.#applySceneAttributeValues(scene.sceneValues, scene.sceneTransitionTime);
494
+ this.#activateSceneInFabricSceneInfo(fabricIndex, UNDEFINED_GROUP, GLOBAL_SCENE_ID);
495
+ }
496
+ /** Method used by the OnOff cluster to store the global scene */
497
+ storeGlobalScene(fabricIndex) {
498
+ const sceneValues = this.#collectSceneAttributeValues();
499
+ const existingSceneIndex = this.#sceneIndexForId(fabricIndex, GLOBAL_SCENE_ID, UNDEFINED_GROUP);
500
+ if (existingSceneIndex === -1) {
501
+ this.#addOrReplaceSceneEntry({
502
+ sceneGroupId: UNDEFINED_GROUP,
503
+ sceneId: GLOBAL_SCENE_ID,
504
+ sceneName: "Global Scene",
505
+ sceneTransitionTime: 0,
506
+ sceneValues,
507
+ fabricIndex
508
+ });
509
+ } else {
510
+ const scene = this.state.sceneTable[existingSceneIndex];
511
+ scene.sceneValues = sceneValues;
512
+ this.#addOrReplaceSceneEntry(scene, existingSceneIndex);
513
+ }
514
+ }
515
+ /**
516
+ * Decodes an ExtensionFieldSet struct into SceneAttributeData format including validation.
517
+ * Returns undefined if the data are considered invalid according to the Spec/SDK.
518
+ */
519
+ #decodeExtensionFieldSets(fieldSet = []) {
520
+ const result = {};
521
+ for (const { clusterId, attributeValueList } of fieldSet) {
522
+ const sceneClusterDetails = this.internal.endpointSceneableBehaviors.get("id", clusterId);
523
+ if (sceneClusterDetails === void 0) {
524
+ continue;
525
+ }
526
+ const clusterName = sceneClusterDetails.name;
527
+ if (result[clusterName]) {
528
+ delete result[clusterName];
529
+ }
530
+ for (const attributeValue of attributeValueList) {
531
+ const { attributeId } = attributeValue;
532
+ const attributeDetails = sceneClusterDetails.attributes.get("id", attributeId);
533
+ if (attributeDetails === void 0) {
534
+ return void 0;
535
+ }
536
+ const value = this.#decodeValueFromAttributeValuePair(attributeValue, attributeDetails);
537
+ if (value == void 0) {
538
+ return void 0;
539
+ }
540
+ result[clusterName] = result[clusterName] || {};
541
+ result[clusterName][attributeDetails.name] = value;
542
+ }
543
+ }
544
+ return result;
545
+ }
546
+ /**
547
+ * Decodes and validates a single AttributeValuePair into the actual attribute value including validation.
548
+ */
549
+ #decodeValueFromAttributeValuePair(attributeValuePair, { schema, type, mappedType, nullable }) {
550
+ let fieldCount = 0;
551
+ for (const value2 of Object.values(attributeValuePair)) {
552
+ if (value2 !== void 0) {
553
+ fieldCount++;
554
+ }
555
+ }
556
+ if (fieldCount !== 2) {
557
+ logger.warn(
558
+ `AttributeValuePair has invalid number (${fieldCount}) of fields (${(0, import_general.serialize)(attributeValuePair)})`
559
+ );
560
+ return void 0;
561
+ }
562
+ const value = attributeValuePair[mappedType];
563
+ if (value === void 0) {
564
+ logger.warn(
565
+ `AttributeValuePair missing value for mappedType ${mappedType} (${(0, import_general.serialize)(attributeValuePair)})`
566
+ );
567
+ return void 0;
568
+ }
569
+ if (typeof value !== "number" && typeof value !== "bigint") {
570
+ logger.warn(
571
+ `AttributeValuePair has invalid non-numeric value for mappedType ${mappedType} (${(0, import_general.serialize)(attributeValuePair)})`
572
+ // Should never happen
573
+ );
574
+ return void 0;
575
+ }
576
+ if (type === import_model.bool.name) {
577
+ let boolValue;
578
+ if (value === 0 || value === 1) {
579
+ boolValue = !!value;
580
+ } else if (nullable) {
581
+ boolValue = null;
582
+ } else {
583
+ boolValue = false;
584
+ }
585
+ schema.validate(boolValue);
586
+ return boolValue;
587
+ }
588
+ try {
589
+ schema.validate(value);
590
+ return value;
591
+ } catch (error) {
592
+ import_types.ValidationOutOfBoundsError.accept(error);
593
+ }
594
+ if (nullable) {
595
+ return null;
596
+ }
597
+ if (!(schema instanceof import_types.TlvNumericSchema) || schema.min === void 0 || schema.max === void 0) {
598
+ throw new import_general.InternalError(`Attribute schema for non-boolean non-nullable attribute is not TlvNumericSchema`);
599
+ }
600
+ const effectiveMin = schema.min;
601
+ const effectiveMax = schema.max;
602
+ let minDiff = BigInt(value) - BigInt(effectiveMin);
603
+ if (minDiff < 0) {
604
+ minDiff = -minDiff;
605
+ }
606
+ let maxDiff = BigInt(value) - BigInt(effectiveMax);
607
+ if (maxDiff < 0) {
608
+ maxDiff = -maxDiff;
609
+ }
610
+ let closestValue = effectiveMin;
611
+ if (maxDiff < minDiff || maxDiff === minDiff && effectiveMax < closestValue) {
612
+ closestValue = effectiveMax;
613
+ }
614
+ schema.validate(closestValue);
615
+ return closestValue;
616
+ }
617
+ /** Encode the SceneAttributeData into ExtensionFieldSet structs for command responses */
618
+ #encodeExtensionFieldSets(sceneValues) {
619
+ const extensionFieldSetStructs = new Array();
620
+ for (const [clusterName, clusterAttributes] of Object.entries(sceneValues)) {
621
+ const clusterData = this.internal.endpointSceneableBehaviors.get("name", clusterName);
622
+ if (clusterData === void 0) {
623
+ throw new import_general.InternalError(
624
+ `Scene Attribute cluster ${clusterName} not found on Endpoint ${this.endpoint.id} during encoding`
625
+ );
626
+ }
627
+ const attributeValueList = new Array();
628
+ for (const [attributeName, value] of Object.entries(clusterAttributes)) {
629
+ const attributeDetails = clusterData.attributes.get("name", attributeName);
630
+ if (attributeDetails !== void 0) {
631
+ const encodedData = this.#encodeSceneAttributeValue(attributeDetails, value);
632
+ if (encodedData !== void 0) {
633
+ attributeValueList.push(encodedData);
634
+ }
635
+ }
636
+ }
637
+ if (attributeValueList.length) {
638
+ extensionFieldSetStructs.push({
639
+ clusterId: clusterData.id,
640
+ attributeValueList
641
+ });
642
+ }
643
+ }
644
+ return extensionFieldSetStructs;
645
+ }
646
+ /** Encodes a single attribute value into an AttributeValuePair for command responses */
647
+ #encodeSceneAttributeValue({ id: attributeId, schema, type, mappedType }, value) {
648
+ if (type === import_model.bool.name) {
649
+ if (value === null) {
650
+ return { attributeId, [mappedType]: 255 };
651
+ }
652
+ return { attributeId, [mappedType]: value ? 1 : 0 };
653
+ }
654
+ if (value !== null) {
655
+ return { attributeId, [mappedType]: value };
656
+ }
657
+ if (!(schema instanceof import_types.NullableSchema)) {
658
+ throw new import_general.InternalError(`Attribute schema for non-nullable attribute is not NullableSchema`);
659
+ }
660
+ if (!(schema.schema instanceof import_types.TlvNumericSchema)) {
661
+ throw new import_general.InternalError(`Underlying schema for non-nullable attribute is not TlvNumericSchema`);
662
+ }
663
+ if (schema.schema.baseTypeMin === 0 && schema.schema.max < schema.schema.baseTypeMax) {
664
+ return { attributeId, [mappedType]: schema.schema.baseTypeMax };
665
+ } else if (schema.schema.baseTypeMin < 0 && schema.schema.min > schema.schema.baseTypeMin) {
666
+ return { attributeId, [mappedType]: schema.schema.baseTypeMin };
667
+ } else {
668
+ logger.warn(
669
+ `Cannot determine out-of-bounds value for attribute schema, returning min value of datatype schema`
670
+ );
671
+ }
672
+ }
673
+ /** Collects the current values of all sceneable attributes on the endpoint */
674
+ #collectSceneAttributeValues() {
675
+ const sceneValues = {};
676
+ this.endpoint.act((agent) => {
677
+ for (const { name: clusterName, attributes } of this.internal.endpointSceneableBehaviors) {
678
+ const clusterState = agent[clusterName].state;
679
+ for (const attribute of attributes) {
680
+ const attributeName = attribute.name;
681
+ const currentValue = clusterState[attributeName];
682
+ if (currentValue !== void 0) {
683
+ sceneValues[clusterName] = sceneValues[clusterName] || {};
684
+ sceneValues[clusterName][attributeName] = (0, import_general.deepCopy)(currentValue);
685
+ }
686
+ }
687
+ }
688
+ });
689
+ logger.debug(`Collected scene attribute values on Endpoint ${this.endpoint.id}: ${(0, import_general.serialize)(sceneValues)}`);
690
+ return sceneValues;
691
+ }
692
+ /**
693
+ * Main method for Clusters to Register themselves with their "Apply Scenes Callback".
694
+ *
695
+ * @param behavior ClusterBehavior implementing a cluster with sceneable attributes
696
+ * @param applyFunc Function that applies scene values for that cluster
697
+ */
698
+ implementScenes(behavior, applyFunc) {
699
+ const type = behavior.type;
700
+ if (!import_ClusterBehavior.ClusterBehavior.is(type) || !type.schema || !type.schema.id) {
701
+ return;
702
+ }
703
+ const clusterName = (0, import_general.camelize)(type.schema.name);
704
+ const clusterId = (0, import_types.ClusterId)(type.schema.id);
705
+ let sceneClusterDetails;
706
+ for (const attribute of type.schema.conformant.attributes) {
707
+ if (!attribute.effectiveQuality.scene) {
708
+ continue;
709
+ }
710
+ const attributeId = (0, import_types.AttributeId)(attribute.id);
711
+ const attributeName = (0, import_general.camelize)(attribute.name);
712
+ const event = this.endpoint.events[clusterName]?.[`${attributeName}$Changed`];
713
+ const hasValue = this.endpoint.state[clusterName]?.[attributeName] !== void 0;
714
+ if (!hasValue || !event) {
715
+ continue;
716
+ }
717
+ if (!sceneClusterDetails) {
718
+ sceneClusterDetails = this.internal.endpointSceneableBehaviors.get("id", clusterId) ?? {
719
+ id: clusterId,
720
+ name: clusterName,
721
+ attributes: new import_general.BasicSet(),
722
+ clusterBehaviorType: type,
723
+ applyFunc
724
+ };
725
+ }
726
+ const attrType = attribute.primitiveBase?.name;
727
+ if (attrType === void 0 || DataTypeToSceneAttributeDataMap[attrType] === void 0) {
728
+ logger.warn(
729
+ `Scene Attribute ${attribute.name} on Cluster ${clusterName} has unsupported datatype ${attrType} for scene management on Endpoint ${this.endpoint.id}`
730
+ );
731
+ continue;
732
+ }
733
+ sceneClusterDetails.attributes.add({
734
+ id: attributeId,
735
+ name: attributeName,
736
+ schema: type.cluster.attributes[attributeName].schema,
737
+ type: attrType,
738
+ mappedType: DataTypeToSceneAttributeDataMap[attrType],
739
+ nullable: !!attribute.effectiveQuality.nullable
740
+ });
741
+ }
742
+ if (sceneClusterDetails) {
743
+ logger.info(
744
+ `Registered ${sceneClusterDetails.attributes.size} scene attributes for Cluster ${clusterName} on Endpoint ${this.endpoint.id}`
745
+ );
746
+ this.internal.endpointSceneableBehaviors.add(sceneClusterDetails);
747
+ }
748
+ }
749
+ /** Apply scene attribute values in the various clusters on the endpoint. */
750
+ #applySceneAttributeValues(sceneValues, transitionTime = null) {
751
+ logger.debug(`Recalling scene on Endpoint ${this.endpoint.id} with values: ${(0, import_general.serialize)(sceneValues)}`);
752
+ const agent = this.endpoint.agentFor(this.context);
753
+ const promises = [];
754
+ for (const [clusterName, clusterAttributes] of Object.entries(sceneValues)) {
755
+ const { applyFunc, clusterBehaviorType } = this.internal.endpointSceneableBehaviors.get("name", clusterName) ?? {};
756
+ if (applyFunc && clusterBehaviorType) {
757
+ const result = applyFunc.call(agent.get(clusterBehaviorType), clusterAttributes, transitionTime ?? 0);
758
+ if (import_general2.MaybePromise.is(result)) {
759
+ promises.push(result);
760
+ }
761
+ } else {
762
+ logger.warn(
763
+ `No scenes implementation found for cluster ${clusterName} on Endpoint ${this.endpoint.id} during scene recall. Values are ignored`
764
+ );
765
+ }
766
+ }
767
+ if (promises.length) {
768
+ return Promise.all(promises).then(
769
+ () => void 0,
770
+ (error) => logger.warn(`Error applying scene attribute values on Endpoint ${this.endpoint.id}:`, error)
771
+ );
772
+ }
773
+ }
774
+ #groupExistentInFabric(fabric, groupId2) {
775
+ return fabric.groups.groupKeyIdMap.has(groupId2);
776
+ }
777
+ /**
778
+ * The Scene Table capacity for a given fabric SHALL be less than half (rounded down towards 0) of the Scene Table
779
+ * entries (as indicated in the SceneTableSize attribute), with a maximum of 253 entries
780
+ */
781
+ get #fabricSceneCapacity() {
782
+ return Math.min(Math.floor((this.state.sceneTableSize - 1) / 2), 253);
783
+ }
784
+ #scenesForGroup(fabricIndex, groupId2) {
785
+ return this.state.sceneTable.filter((s) => s.fabricIndex === fabricIndex && s.sceneGroupId === groupId2);
786
+ }
787
+ #scenesForFabric(fabricIndex) {
788
+ return this.state.sceneTable.filter((s) => s.fabricIndex === fabricIndex);
789
+ }
790
+ #sceneIndexForId(fabricIndex, sceneId, groupId2) {
791
+ return this.state.sceneTable.findIndex(
792
+ (s) => s.fabricIndex === fabricIndex && s.sceneId === sceneId && s.sceneGroupId === groupId2
793
+ );
794
+ }
795
+ #fabricSceneInfoForFabric(fabricIndex) {
796
+ return this.state.fabricSceneInfo.find((f) => f.fabricIndex === fabricIndex);
797
+ }
798
+ /** If the fabric is the one that currently has a valid scene being monitored, invalidate it. */
799
+ #invalidateFabricSceneInfoForFabric(fabricIndex) {
800
+ if (this.internal.monitorSceneAttributesForFabric !== fabricIndex) {
801
+ return;
802
+ }
803
+ const infoEntry = this.#fabricSceneInfoForFabric(fabricIndex);
804
+ if (infoEntry && infoEntry.sceneValid) {
805
+ infoEntry.sceneValid = false;
806
+ }
807
+ this.internal.monitorSceneAttributesForFabric = null;
808
+ }
809
+ /**
810
+ * Invalidate all fabric scene info entries.
811
+ * Method will be called by relevant clusters when commands change the state.
812
+ */
813
+ makeAllFabricSceneInfoEntriesInvalid() {
814
+ if (this.internal.monitorSceneAttributesForFabric === null) {
815
+ return;
816
+ }
817
+ const infoEntry = this.#fabricSceneInfoForFabric(this.internal.monitorSceneAttributesForFabric);
818
+ if (infoEntry && infoEntry.sceneValid) {
819
+ infoEntry.sceneValid = false;
820
+ }
821
+ this.internal.monitorSceneAttributesForFabric = null;
822
+ }
823
+ /** Initializes the fabric scene info entries based on existing fabrics and scene table. */
824
+ #initializeFabricSceneInfo(fabric) {
825
+ const existingEntries = /* @__PURE__ */ new Map();
826
+ for (const entry of this.state.fabricSceneInfo) {
827
+ existingEntries.set(entry.fabricIndex, entry);
828
+ }
829
+ const list = new Array();
830
+ for (const { fabricIndex } of fabric.fabrics) {
831
+ const entry = existingEntries.get(fabricIndex) ?? {
832
+ sceneCount: 0,
833
+ // Will be updated before it is set
834
+ currentScene: UNDEFINED_SCENE_ID,
835
+ currentGroup: UNDEFINED_GROUP,
836
+ sceneValid: false,
837
+ remainingCapacity: 0,
838
+ // Will be updated before it is set
839
+ fabricIndex
840
+ };
841
+ entry.sceneValid = false;
842
+ const { sceneCount, remainingCapacity } = this.#countsForFabric(fabricIndex);
843
+ entry.sceneCount = sceneCount;
844
+ entry.remainingCapacity = remainingCapacity;
845
+ list.push(entry);
846
+ }
847
+ this.state.fabricSceneInfo = list;
848
+ }
849
+ /** Updates the scene count and remaining capacity for a given fabric index */
850
+ #updateFabricSceneInfoCountsForFabric(fabricIndex) {
851
+ const infoEntryIndex = this.state.fabricSceneInfo.findIndex((f) => f.fabricIndex === fabricIndex);
852
+ const entry = infoEntryIndex !== -1 ? this.state.fabricSceneInfo[infoEntryIndex] : {
853
+ sceneCount: 0,
854
+ // Will be updated before it is set
855
+ currentScene: UNDEFINED_SCENE_ID,
856
+ currentGroup: UNDEFINED_GROUP,
857
+ sceneValid: false,
858
+ remainingCapacity: 0,
859
+ // Will be updated before it is set
860
+ fabricIndex
861
+ };
862
+ const { sceneCount, remainingCapacity } = this.#countsForFabric(fabricIndex);
863
+ entry.sceneCount = sceneCount;
864
+ entry.remainingCapacity = remainingCapacity;
865
+ if (infoEntryIndex === -1) {
866
+ this.state.fabricSceneInfo.push(entry);
867
+ } else {
868
+ this.state.fabricSceneInfo[infoEntryIndex] = entry;
869
+ }
870
+ }
871
+ #countsForFabric(fabricIndex) {
872
+ const sceneCount = this.#scenesForFabric(fabricIndex).length;
873
+ return {
874
+ sceneCount,
875
+ remainingCapacity: Math.max(this.#fabricSceneCapacity - sceneCount, 0)
876
+ };
877
+ }
878
+ /** Activates the given scene in the fabric scene info, invalidating all others. */
879
+ #activateSceneInFabricSceneInfo(fabricIndex, groupId2, sceneId) {
880
+ for (const infoEntry of this.state.fabricSceneInfo) {
881
+ if (infoEntry.fabricIndex === fabricIndex) {
882
+ infoEntry.currentGroup = groupId2;
883
+ infoEntry.currentScene = sceneId;
884
+ infoEntry.sceneValid = true;
885
+ this.internal.monitorSceneAttributesForFabric = fabricIndex;
886
+ } else if (infoEntry.sceneValid) {
887
+ infoEntry.sceneValid = false;
888
+ }
889
+ }
890
+ }
891
+ /** Removes all scenes for a given fabric when the fabric is deleted */
892
+ #handleDeleteFabric({ fabricIndex }) {
893
+ if (this.internal.monitorSceneAttributesForFabric === fabricIndex) {
894
+ this.internal.monitorSceneAttributesForFabric = null;
895
+ }
896
+ }
31
897
  }
898
+ ((ScenesManagementServer2) => {
899
+ var _fabricIndex_dec, _sceneValues_dec, _sceneTransitionTime_dec, _sceneName_dec, _sceneId_dec, _sceneGroupId_dec, _init, _sceneTable_dec, _a, _init2;
900
+ _sceneGroupId_dec = [(0, import_model.field)(import_model.groupId, import_model.mandatory)], _sceneId_dec = [(0, import_model.field)(import_model.uint8.extend({ constraint: "max 254" }), import_model.mandatory)], _sceneName_dec = [(0, import_model.field)(import_model.string.extend({ constraint: "max 16" }))], _sceneTransitionTime_dec = [(0, import_model.field)(import_model.uint32.extend({ constraint: "max 60000000" }), import_model.mandatory)], _sceneValues_dec = [(0, import_model.field)(import_model.any, import_model.mandatory)], _fabricIndex_dec = [(0, import_model.field)(import_model.fabricIdx, import_model.mandatory)];
901
+ class ScenesTableEntry {
902
+ constructor() {
903
+ __publicField(this, "sceneGroupId", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
904
+ __publicField(this, "sceneId", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
905
+ __publicField(this, "sceneName", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
906
+ __publicField(this, "sceneTransitionTime", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
907
+ __publicField(this, "sceneValues", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
908
+ __publicField(this, "fabricIndex", __runInitializers(_init, 28, this)), __runInitializers(_init, 31, this);
909
+ }
910
+ }
911
+ _init = __decoratorStart(null);
912
+ __decorateElement(_init, 5, "sceneGroupId", _sceneGroupId_dec, ScenesTableEntry);
913
+ __decorateElement(_init, 5, "sceneId", _sceneId_dec, ScenesTableEntry);
914
+ __decorateElement(_init, 5, "sceneName", _sceneName_dec, ScenesTableEntry);
915
+ __decorateElement(_init, 5, "sceneTransitionTime", _sceneTransitionTime_dec, ScenesTableEntry);
916
+ __decorateElement(_init, 5, "sceneValues", _sceneValues_dec, ScenesTableEntry);
917
+ __decorateElement(_init, 5, "fabricIndex", _fabricIndex_dec, ScenesTableEntry);
918
+ __decoratorMetadata(_init, ScenesTableEntry);
919
+ ScenesManagementServer2.ScenesTableEntry = ScenesTableEntry;
920
+ class State extends (_a = ScenesManagementBase.State, _sceneTable_dec = [(0, import_model.field)((0, import_model.listOf)(ScenesTableEntry), import_model.nonvolatile, import_model.mandatory)], _a) {
921
+ constructor() {
922
+ super(...arguments);
923
+ __publicField(this, "sceneTable", __runInitializers(_init2, 8, this, new Array())), __runInitializers(_init2, 11, this);
924
+ }
925
+ }
926
+ _init2 = __decoratorStart(_a);
927
+ __decorateElement(_init2, 5, "sceneTable", _sceneTable_dec, State);
928
+ __decoratorMetadata(_init2, State);
929
+ ScenesManagementServer2.State = State;
930
+ class Internal {
931
+ /** ObserverGroup for all $Changed events of sceneable attributes */
932
+ endpointSceneAttributeObservers = new import_general.ObserverGroup();
933
+ /** Fabric index where a scene is currently valid, if any */
934
+ monitorSceneAttributesForFabric = null;
935
+ /** Map of sceneable behaviors/clusters and their sceneable attributes on the endpoint */
936
+ endpointSceneableBehaviors = new import_general.BasicSet();
937
+ }
938
+ ScenesManagementServer2.Internal = Internal;
939
+ })(ScenesManagementServer || (ScenesManagementServer = {}));
32
940
  //# sourceMappingURL=ScenesManagementServer.js.map