@nebulahome/integration-sdk 1.4.0 → 1.6.0

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.
@@ -6,6 +6,15 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
+ var __exportAll = (all, no_symbols) => {
10
+ let target = {};
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ return target;
17
+ };
9
18
  var __copyProps = (to, from, except, desc) => {
10
19
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
20
  key = keys[i];
@@ -21,4 +30,4 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
30
  enumerable: true
22
31
  }) : target, mod));
23
32
  //#endregion
24
- export { __toESM as n, __commonJSMin as t };
33
+ export { __exportAll as n, __toESM as r, __commonJSMin as t };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ //#endregion
2
3
  //#region ../contracts/dist/capabilities.d.ts
3
4
  /** Every capability an entity may declare. */
4
5
  declare const CAPABILITIES: readonly ["on_off", "level", "color_hs", "color_temp", "cover", "lock", "thermostat", "sensor_numeric", "sensor_binary", "sensor_text", "media_player", "camera", "button", "update", "lawn_mower", "select", "number", "vacuum", "image", "custom"];
@@ -162,6 +163,78 @@ type JsonObject = {
162
163
  /** Any value that survives a JSON round trip unchanged. */
163
164
  type JsonValue = string | number | boolean | null | JsonValue[] | JsonObject;
164
165
  //#endregion
166
+ //#region ../contracts/dist/bluetooth.d.ts
167
+ /** How a scanner listens: passive only hears, active also asks devices for more. */
168
+ declare const BLUETOOTH_SCAN_MODES: readonly ["passive", "active"];
169
+ /** How a scanner listens. */
170
+ type BluetoothScanMode = (typeof BLUETOOTH_SCAN_MODES)[number];
171
+ /**
172
+ * One advertisement a scanner heard: what a proxy reports through `sdk.bluetooth.scanner`, and
173
+ * what the local adapter's D-Bus signals are turned into.
174
+ */
175
+ declare const bluetoothAdvertSchema: z.ZodObject<{
176
+ address: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
177
+ addressType: z.ZodEnum<{
178
+ public: "public";
179
+ random: "random";
180
+ }>;
181
+ rssi: z.ZodInt;
182
+ name: z.ZodOptional<z.ZodString>;
183
+ manufacturerData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
184
+ serviceData: z.ZodOptional<z.ZodRecord<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
185
+ serviceUuids: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>;
186
+ at: z.ZodUnion<readonly [z.ZodDate, z.ZodPipe<z.ZodISODateTime, z.ZodTransform<Date, string>>]>;
187
+ }, z.core.$strip>;
188
+ /** One advertisement heard, as written. */
189
+ type BluetoothAdvertInput = z.input<typeof bluetoothAdvertSchema>;
190
+ /** One advertisement heard. */
191
+ type BluetoothAdvert = z.output<typeof bluetoothAdvertSchema>;
192
+ /**
193
+ * What a device that can be a proxy declares in its profile: the scan modes it can run.
194
+ */
195
+ declare const bluetoothProxyProfileSchema: z.ZodObject<{
196
+ modes: z.ZodArray<z.ZodEnum<{
197
+ passive: "passive";
198
+ active: "active";
199
+ }>>;
200
+ }, z.core.$strict>;
201
+ /** What a device that can be a proxy declares. */
202
+ type BluetoothProxyProfile = z.output<typeof bluetoothProxyProfileSchema>;
203
+ /** Arguments of `bluetooth-proxy.install`. */
204
+ declare const bluetoothProxyInstallArgsSchema: z.ZodObject<{
205
+ mode: z.ZodEnum<{
206
+ passive: "passive";
207
+ active: "active";
208
+ }>;
209
+ }, z.core.$strip>;
210
+ /** Arguments of `bluetooth-proxy.install`: the mode to scan in. */
211
+ type BluetoothProxyInstallArgs = z.output<typeof bluetoothProxyInstallArgsSchema>;
212
+ /** Arguments of `bluetooth-proxy.filter`. */
213
+ declare const bluetoothProxyFilterArgsSchema: z.ZodObject<{
214
+ addresses: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>]>;
215
+ }, z.core.$strip>;
216
+ /** Arguments of `bluetooth-proxy.filter`: the addresses to forward, upper case, or `all`. */
217
+ type BluetoothProxyFilterArgs = z.output<typeof bluetoothProxyFilterArgsSchema>;
218
+ /** What `bluetooth-proxy.state` answers: a device that can be a proxy, and whether it is one. */
219
+ declare const bluetoothProxyStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
220
+ eligible: z.ZodLiteral<true>;
221
+ installed: z.ZodBoolean;
222
+ version: z.ZodOptional<z.ZodString>;
223
+ shipped: z.ZodString;
224
+ running: z.ZodBoolean;
225
+ }, z.core.$strip>, z.ZodObject<{
226
+ eligible: z.ZodLiteral<false>;
227
+ reason: z.ZodEnum<{
228
+ gen1: "gen1";
229
+ battery: "battery";
230
+ firmware: "firmware";
231
+ "no-bluetooth": "no-bluetooth";
232
+ }>;
233
+ update: z.ZodOptional<z.ZodBoolean>;
234
+ }, z.core.$strip>], "eligible">;
235
+ /** Whether a device can be a proxy, and whether it is. */
236
+ type BluetoothProxyState = z.output<typeof bluetoothProxyStateSchema>;
237
+ //#endregion
165
238
  //#region ../contracts/dist/entity-id.d.ts
166
239
  /** The kinds of thing an entity can be. The domain is the part before the dot. */
167
240
  declare const ENTITY_DOMAINS: readonly ["light", "switch", "sensor", "binary_sensor", "cover", "lock", "climate", "media_player", "camera", "button", "update", "lawn_mower", "select", "number", "vacuum", "image", "custom", "alias"];
@@ -202,21 +275,21 @@ declare const declaredCapabilitiesSchema: z.ZodRecord<z.ZodEnum<{
202
275
  custom: "custom";
203
276
  image: "image";
204
277
  level: "level";
205
- select: "select";
206
- button: "button";
207
- sensor_numeric: "sensor_numeric";
208
- sensor_text: "sensor_text";
209
- sensor_binary: "sensor_binary";
210
278
  on_off: "on_off";
211
279
  color_hs: "color_hs";
212
280
  color_temp: "color_temp";
213
281
  cover: "cover";
214
282
  lock: "lock";
215
283
  thermostat: "thermostat";
284
+ sensor_numeric: "sensor_numeric";
285
+ sensor_binary: "sensor_binary";
286
+ sensor_text: "sensor_text";
216
287
  media_player: "media_player";
217
288
  camera: "camera";
289
+ button: "button";
218
290
  update: "update";
219
291
  lawn_mower: "lawn_mower";
292
+ select: "select";
220
293
  vacuum: "vacuum";
221
294
  }> & z.core.$partial, z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
222
295
  /** What an entity declares it can do, with the device's own limits for each. */
@@ -388,6 +461,117 @@ declare const stateReportSchema: z.ZodObject<{
388
461
  /** What an adapter publishes when a device reports. */
389
462
  type StateReport = z.output<typeof stateReportSchema>;
390
463
  //#endregion
464
+ //#region ../contracts/dist/infrared.d.ts
465
+ /** What a code is sent as: infrared, or radio on 433 MHz. */
466
+ declare const INFRARED_SIGNALS: readonly ["ir", "rf"];
467
+ /** What a code is sent as. */
468
+ type InfraredSignal = (typeof INFRARED_SIGNALS)[number];
469
+ /** The protocols the codec recognises a code as; one it does not is raw timings. */
470
+ declare const INFRARED_PROTOCOLS: readonly ["nec", "nec-ext", "samsung32", "sirc", "sirc15", "sirc20", "rc5"];
471
+ /** A protocol the codec recognises. */
472
+ type InfraredProtocolName = (typeof INFRARED_PROTOCOLS)[number];
473
+ /** A code recognised as a protocol: its address and command. */
474
+ declare const infraredProtocolSchema: z.ZodObject<{
475
+ name: z.ZodEnum<{
476
+ nec: "nec";
477
+ "nec-ext": "nec-ext";
478
+ samsung32: "samsung32";
479
+ sirc: "sirc";
480
+ sirc15: "sirc15";
481
+ sirc20: "sirc20";
482
+ rc5: "rc5";
483
+ }>;
484
+ address: z.ZodInt;
485
+ command: z.ZodInt;
486
+ }, z.core.$strip>;
487
+ /** A code recognised as a protocol. */
488
+ type InfraredProtocol = z.output<typeof infraredProtocolSchema>;
489
+ /**
490
+ * A code, whichever blaster learned it: the pulses in microseconds, a mark then a space in turn,
491
+ * starting with a mark; the carrier an IR code is modulated on (0 for RF, which is on-off keyed);
492
+ * an RF code's frequency; and the protocol, when the codec recognises one.
493
+ */
494
+ declare const infraredCodeSchema: z.ZodObject<{
495
+ signal: z.ZodEnum<{
496
+ ir: "ir";
497
+ rf: "rf";
498
+ }>;
499
+ carrierHz: z.ZodInt;
500
+ frequencyHz: z.ZodOptional<z.ZodInt>;
501
+ pulses: z.ZodArray<z.ZodInt>;
502
+ protocol: z.ZodOptional<z.ZodObject<{
503
+ name: z.ZodEnum<{
504
+ nec: "nec";
505
+ "nec-ext": "nec-ext";
506
+ samsung32: "samsung32";
507
+ sirc: "sirc";
508
+ sirc15: "sirc15";
509
+ sirc20: "sirc20";
510
+ rc5: "rc5";
511
+ }>;
512
+ address: z.ZodInt;
513
+ command: z.ZodInt;
514
+ }, z.core.$strip>>;
515
+ }, z.core.$strip>;
516
+ /** A code. */
517
+ type InfraredCode = z.output<typeof infraredCodeSchema>;
518
+ /** What a blaster declares in its profile: the signals it sends, and whether it can learn. */
519
+ declare const infraredProfileSchema: z.ZodObject<{
520
+ signals: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"ir">], null>, z.ZodTuple<[z.ZodLiteral<"ir">, z.ZodLiteral<"rf">], null>]>;
521
+ receives: z.ZodBoolean;
522
+ }, z.core.$strict>;
523
+ /** What a blaster declares. */
524
+ type InfraredProfile = z.output<typeof infraredProfileSchema>;
525
+ /** Arguments of `infrared.send` ({@link INFRARED_OPS}, in `reserved-ops.ts`). */
526
+ declare const infraredSendArgsSchema: z.ZodObject<{
527
+ code: z.ZodObject<{
528
+ signal: z.ZodEnum<{
529
+ ir: "ir";
530
+ rf: "rf";
531
+ }>;
532
+ carrierHz: z.ZodInt;
533
+ frequencyHz: z.ZodOptional<z.ZodInt>;
534
+ pulses: z.ZodArray<z.ZodInt>;
535
+ protocol: z.ZodOptional<z.ZodObject<{
536
+ name: z.ZodEnum<{
537
+ nec: "nec";
538
+ "nec-ext": "nec-ext";
539
+ samsung32: "samsung32";
540
+ sirc: "sirc";
541
+ sirc15: "sirc15";
542
+ sirc20: "sirc20";
543
+ rc5: "rc5";
544
+ }>;
545
+ address: z.ZodInt;
546
+ command: z.ZodInt;
547
+ }, z.core.$strip>>;
548
+ }, z.core.$strip>;
549
+ }, z.core.$strip>;
550
+ /** Arguments of `infrared.send`. */
551
+ type InfraredSendArgs = z.output<typeof infraredSendArgsSchema>;
552
+ /** Arguments of `infrared.learn`; it resolves with an {@link infraredCodeSchema}. */
553
+ declare const infraredLearnArgsSchema: z.ZodObject<{
554
+ signal: z.ZodEnum<{
555
+ ir: "ir";
556
+ rf: "rf";
557
+ }>;
558
+ timeoutMs: z.ZodInt;
559
+ }, z.core.$strip>;
560
+ /** Arguments of `infrared.learn`. */
561
+ type InfraredLearnArgs = z.output<typeof infraredLearnArgsSchema>;
562
+ /** Arguments of `infrared.sweep`. */
563
+ declare const infraredSweepArgsSchema: z.ZodObject<{
564
+ timeoutMs: z.ZodInt;
565
+ }, z.core.$strip>;
566
+ /** Arguments of `infrared.sweep`. */
567
+ type InfraredSweepArgs = z.output<typeof infraredSweepArgsSchema>;
568
+ /** What `infrared.sweep` resolves with. */
569
+ declare const infraredSweepResultSchema: z.ZodObject<{
570
+ frequencyHz: z.ZodInt;
571
+ }, z.core.$strip>;
572
+ /** What `infrared.sweep` resolves with. */
573
+ type InfraredSweepResult = z.output<typeof infraredSweepResultSchema>;
574
+ //#endregion
391
575
  //#region ../contracts/dist/integration-setup.d.ts
392
576
  /** Validates one field of a group. */
393
577
  declare const setupFieldSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -488,6 +672,231 @@ declare const setupFieldSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
488
672
  /** One field of a group. */
489
673
  type SetupField = z.output<typeof setupFieldSchema>;
490
674
  //#endregion
675
+ //#region ../contracts/dist/serial.d.ts
676
+ /** What a device of a `serial` driver keeps in its config: its port, and how it is spoken. */
677
+ declare const serialDeviceConfigSchema: z.ZodObject<{
678
+ portId: z.ZodUUID;
679
+ line: z.ZodObject<{
680
+ baudRate: z.ZodInt;
681
+ dataBits: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<5>, z.ZodLiteral<6>, z.ZodLiteral<7>, z.ZodLiteral<8>]>>;
682
+ parity: z.ZodDefault<z.ZodEnum<{
683
+ none: "none";
684
+ even: "even";
685
+ odd: "odd";
686
+ mark: "mark";
687
+ space: "space";
688
+ }>>;
689
+ stopBits: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<1.5>, z.ZodLiteral<2>]>>;
690
+ flowControl: z.ZodDefault<z.ZodEnum<{
691
+ none: "none";
692
+ rtscts: "rtscts";
693
+ xonxoff: "xonxoff";
694
+ }>>;
695
+ }, z.core.$strict>;
696
+ }, z.core.$strict>;
697
+ /** What a device of a `serial` driver keeps in its config. */
698
+ type SerialDeviceConfig = z.output<typeof serialDeviceConfigSchema>;
699
+ /** What a USB adapter says it is, from sysfs; null for what it does not say. */
700
+ declare const serialUsbSchema: z.ZodObject<{
701
+ vendorId: z.ZodString;
702
+ productId: z.ZodString;
703
+ serialNumber: z.ZodNullable<z.ZodString>;
704
+ manufacturer: z.ZodNullable<z.ZodString>;
705
+ product: z.ZodNullable<z.ZodString>;
706
+ }, z.core.$strip>;
707
+ /** What a USB adapter says it is. */
708
+ type SerialUsb = z.output<typeof serialUsbSchema>;
709
+ //#endregion
710
+ //#region ../contracts/dist/serial-line.d.ts
711
+ /**
712
+ * How a port is spoken: the baud rate, and the framing - `9600 8N1` unless said. A driver of kind
713
+ * `serial` gives its defaults in this shape; the owner may change them when adding a device.
714
+ */
715
+ declare const serialLineSchema: z.ZodObject<{
716
+ baudRate: z.ZodInt;
717
+ dataBits: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<5>, z.ZodLiteral<6>, z.ZodLiteral<7>, z.ZodLiteral<8>]>>;
718
+ parity: z.ZodDefault<z.ZodEnum<{
719
+ none: "none";
720
+ even: "even";
721
+ odd: "odd";
722
+ mark: "mark";
723
+ space: "space";
724
+ }>>;
725
+ stopBits: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<1.5>, z.ZodLiteral<2>]>>;
726
+ flowControl: z.ZodDefault<z.ZodEnum<{
727
+ none: "none";
728
+ rtscts: "rtscts";
729
+ xonxoff: "xonxoff";
730
+ }>>;
731
+ }, z.core.$strict>;
732
+ /** How a port is spoken, as written. */
733
+ type SerialLineInput = z.input<typeof serialLineSchema>;
734
+ /** How a port is spoken. */
735
+ type SerialLine = z.output<typeof serialLineSchema>;
736
+ //#endregion
737
+ //#region ../contracts/dist/reserved-ops.d.ts
738
+ /**
739
+ * The ops the hub sends a device that plays a role for one of its brokers - an IR blaster, a
740
+ * Bluetooth proxy - over its instance's connection, as `{ deviceKey, op, args }`, and the GATT ops
741
+ * the platform transport `bluetooth` carries.
742
+ *
743
+ * A module of its own, importing nothing, because an integration's code imports these names
744
+ * through the SDK: the SDK's entry point is bundled into every module an integration builds, and
745
+ * those validate with the hub's zod (`sdk.z`), never one of their own - so nothing that reaches
746
+ * them may import zod. The arguments' schemas stay with their brokers, in `infrared.ts` and
747
+ * `bluetooth.ts`.
748
+ */
749
+ /**
750
+ * The ops the hub sends a blaster over its instance's connection, as `{ deviceKey, op, args }`.
751
+ * Reserved: no integration uses these names for anything else.
752
+ */
753
+ export declare const INFRARED_OPS: {
754
+ /** Sends a code. */
755
+ readonly send: "infrared.send";
756
+ /** Listens for one code: resolves with it, or rejects when nothing came in time. */
757
+ readonly learn: "infrared.learn";
758
+ /** Searches the RF frequency of a button held down: resolves with it. */
759
+ readonly sweep: "infrared.sweep";
760
+ /** Stops a learn or a sweep under way. */
761
+ readonly cancel: "infrared.cancel";
762
+ };
763
+ /**
764
+ * The ops the hub sends a proxy over its instance's connection, as `{ deviceKey, op, args }`.
765
+ * Reserved: no integration uses these names for anything else.
766
+ */
767
+ export declare const BLUETOOTH_PROXY_OPS: {
768
+ /** Whether it can be a proxy and whether it is: answers `bluetoothProxyStateSchema`. */
769
+ readonly state: "bluetooth-proxy.state";
770
+ /** Installs the script, or the one shipped now over an older one, and starts it scanning. */
771
+ readonly install: "bluetooth-proxy.install";
772
+ /** Stops the script and removes it. */
773
+ readonly remove: "bluetooth-proxy.remove";
774
+ /** Which addresses it forwards: the house's, or everything while Nearby is open. */
775
+ readonly filter: "bluetooth-proxy.filter";
776
+ };
777
+ /**
778
+ * The ops the platform transport `bluetooth` carries to a device it connects to, GATT on the local
779
+ * adapter only.
780
+ */
781
+ export declare const BLUETOOTH_GATT_OPS: {
782
+ readonly read: "gatt.read";
783
+ readonly write: "gatt.write";
784
+ readonly notify: "gatt.notify";
785
+ };
786
+ declare namespace infrared_codes_d_exports {
787
+ export { BROADLINK_TICK_US, DEFAULT_IR_CARRIER_HZ, FlipperIrCode, FlipperIrFile, InfraredImportProblem, decodeBroadlink, decodeInfraredProtocol, decodePronto, decodeRawTimings, encodeBroadlink, encodeInfraredProtocol, encodePronto, encodeRawTimings, parseFlipperIr, withInfraredProtocol };
788
+ }
789
+ /** One Broadlink tick: 269/8192 ms, about 32.84 µs. */
790
+ declare const BROADLINK_TICK_US: number;
791
+ /** The carrier an infrared code is on when its format does not say: 38 kHz, as most remotes. */
792
+ declare const DEFAULT_IR_CARRIER_HZ = 38000;
793
+ /**
794
+ * Reads a Broadlink packet, as its app and similar open-source implementations write one: base64
795
+ * of a type byte, a repeat count, the length of what follows, and each pulse in ticks - one byte,
796
+ * or 0x00 and two bytes big-endian for a longer one - closed by 0x0d 0x05.
797
+ *
798
+ * @param text - The base64.
799
+ * @returns The code, its protocol recognised where it can be.
800
+ * @throws {ValidationError} When it is not a packet, or its pulses do not hold.
801
+ */
802
+ declare function decodeBroadlink(text: string): InfraredCode;
803
+ /**
804
+ * Writes a code as a Broadlink packet: sent once, closed by 0x0d 0x05 and filled out to whole
805
+ * 16-byte blocks, as a Broadlink learns one. Radio goes on 315 MHz for a code nearer that than
806
+ * 433.
807
+ *
808
+ * @param code - The code.
809
+ * @returns The base64.
810
+ */
811
+ declare function encodeBroadlink(code: InfraredCode): string;
812
+ /**
813
+ * Reads Pronto hex in its learned form: `0000`, the frequency word, the number of pairs sent once
814
+ * and of those repeated, then each pair's mark and space in periods of the carrier. What is sent
815
+ * once comes first, then the repeated part once.
816
+ *
817
+ * @param text - The words, four hex digits each.
818
+ * @returns The code, its protocol recognised where it can be.
819
+ * @throws {ValidationError} When it is not learned Pronto, or its pulses do not hold.
820
+ */
821
+ declare function decodePronto(text: string): InfraredCode;
822
+ /**
823
+ * Writes a code as learned Pronto hex, every pair sent once; a code ending on a mark gets a pause
824
+ * after it, since Pronto counts pairs.
825
+ *
826
+ * @param code - The code.
827
+ * @returns The words, upper case; null for a radio code, which Pronto cannot carry.
828
+ */
829
+ declare function encodePronto(code: InfraredCode): string | null;
830
+ /**
831
+ * Reads a list of microseconds: unsigned, a mark and a space in turn - `9000 4500 560 …` - or
832
+ * signed, a mark positive and a space negative - `[9000, -4500, 560, …]` - where two of a kind in
833
+ * a row are one pulse and a leading space is dropped. Spaces, commas, semicolons and brackets all
834
+ * separate.
835
+ *
836
+ * @param text - The list.
837
+ * @param carrierHz - The carrier, which a list does not say.
838
+ * @returns The infrared code, its protocol recognised where it can be.
839
+ * @throws {ValidationError} When a value is not a whole number of microseconds above 0.
840
+ */
841
+ declare function decodeRawTimings(text: string, carrierHz?: number): InfraredCode;
842
+ /**
843
+ * Writes a code as a signed list: a mark positive, a space negative.
844
+ *
845
+ * @param code - The code.
846
+ * @returns `9000, -4500, 560, …`.
847
+ */
848
+ declare function encodeRawTimings(code: InfraredCode): string;
849
+ /**
850
+ * Recognises the protocol a train of pulses was sent in.
851
+ *
852
+ * @param pulses - The pulses, a mark first.
853
+ * @returns The protocol with its address and command, or undefined for one not recognised.
854
+ */
855
+ declare function decodeInfraredProtocol(pulses: readonly number[]): InfraredProtocol | undefined;
856
+ /**
857
+ * A code with its protocol, when its pulses are one the codec recognises.
858
+ *
859
+ * @param code - The code.
860
+ * @returns The code, with `protocol` when an infrared code's pulses are recognised.
861
+ */
862
+ declare function withInfraredProtocol(code: InfraredCode): InfraredCode;
863
+ /**
864
+ * Writes a protocol's address and command as a code to send: what a Flipper Zero's `parsed` entry
865
+ * becomes.
866
+ *
867
+ * @param protocol - The protocol, its address and its command.
868
+ * @returns The code, on the protocol's carrier, the protocol beside it.
869
+ * @throws {ValidationError} When the address or the command does not fit the protocol.
870
+ */
871
+ declare function encodeInfraredProtocol(protocol: InfraredProtocol): InfraredCode;
872
+ /** A line of an imported text not understood, and why. */
873
+ type InfraredImportProblem = {
874
+ /** The line, counted from 1; null for a problem of the whole text. */
875
+ readonly line: number | null;
876
+ readonly text: string;
877
+ readonly reason: string;
878
+ };
879
+ /** A code a Flipper Zero file names: its button's name, and the line its entry starts on. */
880
+ type FlipperIrCode = {
881
+ readonly name: string;
882
+ readonly line: number;
883
+ readonly code: InfraredCode;
884
+ };
885
+ /** What reading a Flipper Zero file found: its codes, and the lines it could not use. */
886
+ type FlipperIrFile = {
887
+ readonly codes: FlipperIrCode[];
888
+ readonly problems: InfraredImportProblem[];
889
+ };
890
+ /**
891
+ * Reads a Flipper Zero `.ir` file - one remote's signals, or a library's - every entry a button:
892
+ * `name`, then `type: parsed` with a `protocol`, an `address` and a `command`, or `type: raw` with
893
+ * a `frequency`, a `duty_cycle` and the `data` in microseconds.
894
+ *
895
+ * @param text - The file.
896
+ * @returns The codes, each named as its entry, and every line that could not be used, with why.
897
+ */
898
+ declare function parseFlipperIr(text: string): FlipperIrFile;
899
+ //#endregion
491
900
  //#region ../package-runtime/dist/transport.d.ts
492
901
  /** What an integration asks a transport to do, expressed as data. */
493
902
  type TransportRequest = {
@@ -1164,6 +1573,74 @@ type ModbusSession = {
1164
1573
  };
1165
1574
  /** Opens a session to a Modbus server. */
1166
1575
  type OpenModbus = (server: ModbusServerOptions) => ModbusSession;
1576
+ /**
1577
+ * A serial port held through the Serial broker, which gives every port exactly one holder: bytes
1578
+ * as they come, and bytes to send.
1579
+ *
1580
+ * Once the port is gone - unplugged, closed by the owner from the Brokers page - `onClose` is
1581
+ * called and nothing more arrives; a write then rejects with an error whose `name` is
1582
+ * `SerialClosed`.
1583
+ */
1584
+ type SerialSession = {
1585
+ /**
1586
+ * Sends bytes, resolving once the port took them.
1587
+ *
1588
+ * @throws {Error} `SerialClosed` once the session is closed.
1589
+ */
1590
+ write: (bytes: Uint8Array) => Promise<void>;
1591
+ /**
1592
+ * Hears every chunk the port reads, in order, as it arrives: a chunk is not a message, so a
1593
+ * protocol framed by lines or lengths puts the chunks together itself.
1594
+ *
1595
+ * @returns Stops hearing.
1596
+ */
1597
+ onData: (listener: (bytes: Uint8Array) => void) => () => void;
1598
+ /**
1599
+ * Hears the port go: unplugged, taken back by the owner, or closed here. Called once.
1600
+ *
1601
+ * @returns Stops hearing.
1602
+ */
1603
+ onClose: (listener: (reason: string) => void) => () => void;
1604
+ /** Lets go of the port, so another holder may open it. */
1605
+ close: () => Promise<void>;
1606
+ };
1607
+ /**
1608
+ * Opens a serial port the device holds - the `portId` and `line` its config's `serial` block
1609
+ * carries, as the owner picked them when adding it - through the Serial broker.
1610
+ *
1611
+ * Rejects with an error whose `name` says why: `SerialPortHeld` - another device, a broker, the
1612
+ * console or a container holds it - or `SerialPortMissing` - no such port, or it is not plugged in.
1613
+ */
1614
+ type OpenSerial = (portId: string, line: SerialLineInput) => Promise<SerialSession>;
1615
+ /** Which proxy is reporting: the device it is, as its connection names it. */
1616
+ type BluetoothScannerOptions = {
1617
+ /** The connection the proxy is reached over: its transport's connection key. */
1618
+ readonly key: string;
1619
+ /** The proxy itself, as that connection names its devices. */
1620
+ readonly deviceKey: string;
1621
+ };
1622
+ /**
1623
+ * A Bluetooth proxy's channel to the Bluetooth broker: what it hears goes in here, and the house
1624
+ * sees it as heard by that proxy.
1625
+ */
1626
+ type BluetoothScanner = {
1627
+ /**
1628
+ * Reports advertisements heard - addresses, how loud, what each carries. The broker checks each
1629
+ * and drops one that does not hold; reporting the same one again is how a proxy says it still
1630
+ * hears it.
1631
+ */
1632
+ report: (adverts: readonly BluetoothAdvertInput[]) => void;
1633
+ /** Stops reporting: the proxy is no longer one, or its connection went. */
1634
+ close: () => void;
1635
+ };
1636
+ /** The house's Bluetooth, as a vendor whose devices can be proxies reaches it. */
1637
+ type BundleBluetooth = {
1638
+ /**
1639
+ * Opens a proxy's scanner, for a device whose profile declares `bluetoothProxy`. One per proxy:
1640
+ * opening it again replaces the first.
1641
+ */
1642
+ readonly scanner: (options: BluetoothScannerOptions) => BluetoothScanner;
1643
+ };
1167
1644
  /**
1168
1645
  * The house's MQTT broker, as the hub reaches it: the one the hub runs, with the hub's own
1169
1646
  * username - or the broker `NEBULA_MQTT_URL` names. Read again each time it is needed: a session
@@ -1193,7 +1670,14 @@ type PalettedPicture = {
1193
1670
  /** One index into the palette per pixel, row after row from the top left. */
1194
1671
  readonly pixels: Uint8Array;
1195
1672
  };
1196
- /** What a bundle drawing a picture needs, and could not bring as a dependency. */
1673
+ /**
1674
+ * The platform's infrared codec, `infrared-codes.ts`: Broadlink packets, Pronto hex, raw timings
1675
+ * and Flipper Zero `.ir` files read into the platform's code and written back out, and the
1676
+ * protocols recognised in it. A blaster's integration converts between its own format and the
1677
+ * code the `infrared.*` ops carry with it.
1678
+ */
1679
+ type InfraredCodec = typeof infrared_codes_d_exports;
1680
+ /** What a bundle decoding what its devices send needs, and could not bring as a dependency. */
1197
1681
  type BundleCodecs = {
1198
1682
  /**
1199
1683
  * Unpacks an LZMA stream in the alone format (`.lzma`): a 13-byte header - the properties and
@@ -1202,6 +1686,14 @@ type BundleCodecs = {
1202
1686
  * @throws {Error} When the stream is corrupt.
1203
1687
  */
1204
1688
  readonly lzma: (bytes: Uint8Array) => Buffer;
1689
+ /**
1690
+ * The infrared codec: `decodeBroadlink`, `encodeBroadlink`, `decodePronto`, `encodePronto`,
1691
+ * `decodeRawTimings`, `encodeRawTimings`, `parseFlipperIr`, `decodeInfraredProtocol`,
1692
+ * `encodeInfraredProtocol`, `withInfraredProtocol`. Handed over rather than imported because it
1693
+ * validates with zod, which a bundle's code reaches only as `sdk.z`; a code that does not hold
1694
+ * throws a `ValidationError`.
1695
+ */
1696
+ readonly infrared: InfraredCodec;
1205
1697
  };
1206
1698
  /** Pictures a bundle draws, for an image entity. */
1207
1699
  type BundleImages = {
@@ -1227,6 +1719,10 @@ type BundleSdk = {
1227
1719
  readonly openMqtt: OpenMqtt;
1228
1720
  /** A session to a Modbus server, through the hub's one connection to it. */
1229
1721
  readonly openModbus: OpenModbus;
1722
+ /** A serial port a device of the vendor holds, through the Serial broker. */
1723
+ readonly openSerial: OpenSerial;
1724
+ /** The house's Bluetooth, for a vendor whose devices are proxies. */
1725
+ readonly bluetooth: BundleBluetooth;
1230
1726
  /** How a camera's stream source is written, as defineTransport is for a transport. */
1231
1727
  readonly defineStreamSource: typeof defineStreamSource;
1232
1728
  /** An RTSP session over TCP, yielding a camera's H.264 as it comes. */
@@ -1361,6 +1857,10 @@ type AccountHandle = {
1361
1857
  };
1362
1858
  //#endregion
1363
1859
  //#region ../package-runtime/dist/discovery.d.ts
1860
+ /** What a vendor's `serial` rules read of a port: the USB strings its adapter gives. */
1861
+ type SerialSighting = SerialUsb;
1862
+ /** What a vendor's `bluetooth` rules read: one advertisement a scanner heard. */
1863
+ type BluetoothSighting = BluetoothAdvert;
1364
1864
  /**
1365
1865
  * What a listening source heard: a device, how to reach it, and what it said.
1366
1866
  *
@@ -1494,4 +1994,4 @@ export declare function defineAccountModule(factory: AccountFactory): AccountFac
1494
1994
  */
1495
1995
  export declare function defineStreamModule(factory: StreamFactory): StreamFactory;
1496
1996
  //#endregion
1497
- export type { AccountFactory, AccountHandle, AccountIdentity, AccountModule, AccountModuleStep, AccountStepContext, BundleCodecs, BundleImages, BundleLogFn, BundleLogger, BundleSdk, Claim, CommandTarget, DeviceDescriptor, DeviceInfo, Discovered, DiscoveryListenContext, DiscoverySource, DiscoverySourceFactory, EntityDescriptor, ImageBlob, Integration, IntegrationFactory, ListenerStatus, ManagedMqtt, ManagedMqttOptions, ManagedSocket, ManagedSocketClose, ManagedSocketHeaders, ManagedSocketOptions, ManagedUdpSocket, ManagedUdpSocketOptions, MappingContext, MdnsAnnouncement, OpenMqtt, OpenRtsp, OpenUdpSocket, OpenWebSocket, PaletteColour, PalettedPicture, PassedOverSighting, PlatformMqtt, PlatformServices, ReportedState, RtspFrame, RtspOptions, Sighting, StreamFactory, StreamFrame, StreamRequest, StreamSink, StreamSource, StreamSourceSpec, StreamTrack, Transport, TransportConnection, TransportContext, TransportFactory, TransportInbound, TransportLookContext, TransportRequest, TransportSpec, TransportStatus, TransportSubscription, UdpPeer };
1997
+ export type { AccountFactory, AccountHandle, AccountIdentity, AccountModule, AccountModuleStep, AccountStepContext, BluetoothAdvert, BluetoothAdvertInput, BluetoothProxyFilterArgs, BluetoothProxyInstallArgs, BluetoothProxyProfile, BluetoothProxyState, BluetoothScanMode, BluetoothScanner, BluetoothScannerOptions, BluetoothSighting, BundleBluetooth, BundleCodecs, BundleImages, BundleLogFn, BundleLogger, BundleSdk, Claim, CommandTarget, DeviceDescriptor, DeviceInfo, Discovered, DiscoveryListenContext, DiscoverySource, DiscoverySourceFactory, EntityDescriptor, FlipperIrCode, FlipperIrFile, ImageBlob, InfraredCode, InfraredCodec, InfraredImportProblem, InfraredLearnArgs, InfraredProfile, InfraredProtocol, InfraredProtocolName, InfraredSendArgs, InfraredSignal, InfraredSweepArgs, InfraredSweepResult, Integration, IntegrationFactory, ListenerStatus, ManagedMqtt, ManagedMqttOptions, ManagedSocket, ManagedSocketClose, ManagedSocketHeaders, ManagedSocketOptions, ManagedUdpSocket, ManagedUdpSocketOptions, MappingContext, MdnsAnnouncement, OpenMqtt, OpenRtsp, OpenSerial, OpenUdpSocket, OpenWebSocket, PaletteColour, PalettedPicture, PassedOverSighting, PlatformMqtt, PlatformServices, ReportedState, RtspFrame, RtspOptions, SerialDeviceConfig, SerialLine, SerialLineInput, SerialSession, SerialSighting, Sighting, StreamFactory, StreamFrame, StreamRequest, StreamSink, StreamSource, StreamSourceSpec, StreamTrack, Transport, TransportConnection, TransportContext, TransportFactory, TransportInbound, TransportLookContext, TransportRequest, TransportSpec, TransportStatus, TransportSubscription, UdpPeer };
package/dist/index.js CHANGED
@@ -50,4 +50,54 @@ function defineStreamModule(factory) {
50
50
  return factory;
51
51
  }
52
52
  //#endregion
53
- export { defineAccountModule, defineDiscoveryModule, defineDriverModule, defineStreamModule, defineTransportModule };
53
+ //#region ../contracts/dist/reserved-ops.js
54
+ /**
55
+ * The ops the hub sends a device that plays a role for one of its brokers - an IR blaster, a
56
+ * Bluetooth proxy - over its instance's connection, as `{ deviceKey, op, args }`, and the GATT ops
57
+ * the platform transport `bluetooth` carries.
58
+ *
59
+ * A module of its own, importing nothing, because an integration's code imports these names
60
+ * through the SDK: the SDK's entry point is bundled into every module an integration builds, and
61
+ * those validate with the hub's zod (`sdk.z`), never one of their own - so nothing that reaches
62
+ * them may import zod. The arguments' schemas stay with their brokers, in `infrared.ts` and
63
+ * `bluetooth.ts`.
64
+ */
65
+ /**
66
+ * The ops the hub sends a blaster over its instance's connection, as `{ deviceKey, op, args }`.
67
+ * Reserved: no integration uses these names for anything else.
68
+ */
69
+ const INFRARED_OPS = {
70
+ /** Sends a code. */
71
+ send: "infrared.send",
72
+ /** Listens for one code: resolves with it, or rejects when nothing came in time. */
73
+ learn: "infrared.learn",
74
+ /** Searches the RF frequency of a button held down: resolves with it. */
75
+ sweep: "infrared.sweep",
76
+ /** Stops a learn or a sweep under way. */
77
+ cancel: "infrared.cancel"
78
+ };
79
+ /**
80
+ * The ops the hub sends a proxy over its instance's connection, as `{ deviceKey, op, args }`.
81
+ * Reserved: no integration uses these names for anything else.
82
+ */
83
+ const BLUETOOTH_PROXY_OPS = {
84
+ /** Whether it can be a proxy and whether it is: answers `bluetoothProxyStateSchema`. */
85
+ state: "bluetooth-proxy.state",
86
+ /** Installs the script, or the one shipped now over an older one, and starts it scanning. */
87
+ install: "bluetooth-proxy.install",
88
+ /** Stops the script and removes it. */
89
+ remove: "bluetooth-proxy.remove",
90
+ /** Which addresses it forwards: the house's, or everything while Nearby is open. */
91
+ filter: "bluetooth-proxy.filter"
92
+ };
93
+ /**
94
+ * The ops the platform transport `bluetooth` carries to a device it connects to, GATT on the local
95
+ * adapter only.
96
+ */
97
+ const BLUETOOTH_GATT_OPS = {
98
+ read: "gatt.read",
99
+ write: "gatt.write",
100
+ notify: "gatt.notify"
101
+ };
102
+ //#endregion
103
+ export { BLUETOOTH_GATT_OPS, BLUETOOTH_PROXY_OPS, INFRARED_OPS, defineAccountModule, defineDiscoveryModule, defineDriverModule, defineStreamModule, defineTransportModule };