esphome-ts 3.4.0-beta.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.
Files changed (61) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +36 -0
  3. package/dist/api/bytePositions.d.ts +8 -0
  4. package/dist/api/bytePositions.js +12 -0
  5. package/dist/api/client.d.ts +21 -0
  6. package/dist/api/client.js +60 -0
  7. package/dist/api/espDevice.d.ts +23 -0
  8. package/dist/api/espDevice.js +76 -0
  9. package/dist/api/espSocket.d.ts +13 -0
  10. package/dist/api/espSocket.js +39 -0
  11. package/dist/api/helpers.d.ts +19 -0
  12. package/dist/api/helpers.js +116 -0
  13. package/dist/api/index.d.ts +9 -0
  14. package/dist/api/index.js +21 -0
  15. package/dist/api/interfaces.d.ts +4 -0
  16. package/dist/api/interfaces.js +2 -0
  17. package/dist/api/protobuf/api.d.ts +922 -0
  18. package/dist/api/protobuf/api.js +6679 -0
  19. package/dist/api/protobuf/api_options.d.ts +24 -0
  20. package/dist/api/protobuf/api_options.js +76 -0
  21. package/dist/api/protobuf/google_descriptor.d.ts +1022 -0
  22. package/dist/api/protobuf/google_descriptor.js +3997 -0
  23. package/dist/api/requestResponseMatching.d.ts +50 -0
  24. package/dist/api/requestResponseMatching.js +54 -0
  25. package/dist/api/responses.d.ts +3 -0
  26. package/dist/api/responses.js +23 -0
  27. package/dist/api/socket.d.ts +29 -0
  28. package/dist/api/socket.js +109 -0
  29. package/dist/api/typeGuards.d.ts +5 -0
  30. package/dist/api/typeGuards.js +7 -0
  31. package/dist/components/base.d.ts +23 -0
  32. package/dist/components/base.js +51 -0
  33. package/dist/components/binarySensor.d.ts +9 -0
  34. package/dist/components/binarySensor.js +19 -0
  35. package/dist/components/binarySensorTypes.d.ts +26 -0
  36. package/dist/components/binarySensorTypes.js +30 -0
  37. package/dist/components/commandInterface.d.ts +4 -0
  38. package/dist/components/commandInterface.js +2 -0
  39. package/dist/components/entities.d.ts +26 -0
  40. package/dist/components/entities.js +2 -0
  41. package/dist/components/fan.d.ts +14 -0
  42. package/dist/components/fan.js +51 -0
  43. package/dist/components/helpers.d.ts +1 -0
  44. package/dist/components/helpers.js +12 -0
  45. package/dist/components/index.d.ts +12 -0
  46. package/dist/components/index.js +24 -0
  47. package/dist/components/interfaces.d.ts +10 -0
  48. package/dist/components/interfaces.js +2 -0
  49. package/dist/components/light.d.ts +22 -0
  50. package/dist/components/light.js +159 -0
  51. package/dist/components/sensor.d.ts +10 -0
  52. package/dist/components/sensor.js +23 -0
  53. package/dist/components/states.d.ts +25 -0
  54. package/dist/components/states.js +2 -0
  55. package/dist/components/switch.d.ts +9 -0
  56. package/dist/components/switch.js +28 -0
  57. package/dist/index.d.ts +2 -0
  58. package/dist/index.js +14 -0
  59. package/dist/run.d.ts +1 -0
  60. package/dist/run.js +16 -0
  61. package/package.json +62 -0
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # esphome-ts
2
+
3
+ This is a client library for use with [esphome](https://esphome.io).
4
+
5
+ ## Example use
6
+
7
+ ```typescript
8
+ import { EspDevice, SwitchComponent } from 'esphome-ts/dist';
9
+ import { filter, tap } from 'rxjs/operators';
10
+
11
+ const device = new EspDevice('my_esp.local');
12
+ device.discovery$
13
+ .pipe(
14
+ filter((value) => value),
15
+ tap(() => {
16
+ const sw = device.components['test_switch'] as SwitchComponent;
17
+ sw.state$.subscribe((value) => {
18
+ console.log(sw.status);
19
+ });
20
+ }),
21
+ )
22
+ .subscribe();
23
+ ```
24
+
25
+ Please see more [here](docs/index.md)
26
+
27
+ ## Contribution
28
+
29
+ Please, feel free to make a PR and contribute to this project. Esphome is a good project, and this expands their
30
+ ecosystem.
31
+
32
+ ## License
33
+
34
+ While this project in general and my contributions (Luca Becker) are licensed under the GPLv3, the `.proto`
35
+ files are licensed under different licenses. Please see those files for their respective licenses. Copies
36
+ of their licenses have been saved in the `licenses` folder.
@@ -0,0 +1,8 @@
1
+ export declare const HEADER_SIZE = 3;
2
+ export declare const HEADER_FIRST_BYTE = 0;
3
+ export declare enum BytePositions {
4
+ ZERO = 0,
5
+ LENGTH = 1,
6
+ TYPE = 2,
7
+ PAYLOAD = 3
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BytePositions = exports.HEADER_FIRST_BYTE = exports.HEADER_SIZE = void 0;
4
+ exports.HEADER_SIZE = 3;
5
+ exports.HEADER_FIRST_BYTE = 0x00;
6
+ var BytePositions;
7
+ (function (BytePositions) {
8
+ BytePositions[BytePositions["ZERO"] = 0] = "ZERO";
9
+ BytePositions[BytePositions["LENGTH"] = 1] = "LENGTH";
10
+ BytePositions[BytePositions["TYPE"] = 2] = "TYPE";
11
+ BytePositions[BytePositions["PAYLOAD"] = 3] = "PAYLOAD";
12
+ })(BytePositions = exports.BytePositions || (exports.BytePositions = {}));
@@ -0,0 +1,21 @@
1
+ import { ConnectRequest, ConnectResponse, DeviceInfoResponse, HelloRequest, HelloResponse, PingResponse } from './protobuf/api';
2
+ import { Observable } from 'rxjs';
3
+ import { Reader } from 'protobufjs/minimal';
4
+ import { EspSocket, ReadData } from './espSocket';
5
+ import { voidMessage } from './protobuf/api_options';
6
+ export interface Decoder<T> {
7
+ decode: (reader: Reader, length?: number) => T;
8
+ }
9
+ export declare const decode: <T>(decoder: Decoder<T>, data: ReadData) => T;
10
+ export declare class Client {
11
+ private readonly socket;
12
+ private readonly subscription;
13
+ constructor(socket: EspSocket);
14
+ terminate(): void;
15
+ hello(request: HelloRequest): Observable<HelloResponse>;
16
+ connect(request: ConnectRequest): Observable<ConnectResponse>;
17
+ ping(): Observable<PingResponse>;
18
+ deviceInfo(): Observable<DeviceInfoResponse>;
19
+ listEntities(): Observable<voidMessage>;
20
+ subscribeStateChange(): Observable<voidMessage>;
21
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Client = exports.decode = void 0;
4
+ const api_1 = require("./protobuf/api");
5
+ const rxjs_1 = require("rxjs");
6
+ const requestResponseMatching_1 = require("./requestResponseMatching");
7
+ const operators_1 = require("rxjs/operators");
8
+ const minimal_1 = require("protobufjs/minimal");
9
+ const api_options_1 = require("./protobuf/api_options");
10
+ const decode = (decoder, data) => {
11
+ return decoder.decode(new minimal_1.Reader(data.payload));
12
+ };
13
+ exports.decode = decode;
14
+ class Client {
15
+ constructor(socket) {
16
+ this.socket = socket;
17
+ this.subscription = new rxjs_1.Subscription();
18
+ this.subscription.add(this.socket.espData$
19
+ .pipe((0, operators_1.tap)((data) => {
20
+ if (data.type === requestResponseMatching_1.MessageTypes.PingRequest) {
21
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.PingResponse, api_1.PingResponse.encode({}).finish());
22
+ }
23
+ }))
24
+ .subscribe());
25
+ }
26
+ terminate() {
27
+ this.subscription.unsubscribe();
28
+ }
29
+ hello(request) {
30
+ const data = api_1.HelloRequest.encode(request).finish();
31
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.HelloRequest, data);
32
+ return this.socket.espData$.pipe((0, operators_1.filter)((value) => value.type === requestResponseMatching_1.MessageTypes.HelloResponse), (0, operators_1.take)(1), (0, operators_1.switchMap)((data) => (0, rxjs_1.of)(api_1.HelloResponse.decode(new minimal_1.Reader(data.payload)))));
33
+ }
34
+ connect(request) {
35
+ const data = api_1.ConnectRequest.encode(request).finish();
36
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.ConnectRequest, data);
37
+ return this.socket.espData$.pipe((0, operators_1.filter)((value) => value.type === requestResponseMatching_1.MessageTypes.ConnectResponse), (0, operators_1.take)(1), (0, operators_1.switchMap)((data) => (0, rxjs_1.of)(api_1.ConnectResponse.decode(new minimal_1.Reader(data.payload)))));
38
+ }
39
+ ping() {
40
+ const data = api_1.PingRequest.encode({}).finish();
41
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.ConnectRequest, data);
42
+ return this.socket.espData$.pipe((0, operators_1.filter)((value) => value.type === requestResponseMatching_1.MessageTypes.PingResponse), (0, operators_1.take)(1), (0, operators_1.switchMap)((data) => (0, rxjs_1.of)(api_1.PingResponse.decode(new minimal_1.Reader(data.payload)))));
43
+ }
44
+ deviceInfo() {
45
+ const data = api_1.DeviceInfoRequest.encode({}).finish();
46
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.DeviceInfoRequest, data);
47
+ return this.socket.espData$.pipe((0, operators_1.filter)(({ type }) => type === requestResponseMatching_1.MessageTypes.DeviceInfoResponse), (0, operators_1.take)(1), (0, operators_1.switchMap)(({ payload }) => (0, rxjs_1.of)(api_1.DeviceInfoResponse.decode(new minimal_1.Reader(payload)))));
48
+ }
49
+ listEntities() {
50
+ const data = api_1.ListEntitiesRequest.encode({}).finish();
51
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.ListEntitiesRequest, data);
52
+ return (0, rxjs_1.of)(api_options_1.voidMessage.decode(new minimal_1.Reader(new Uint8Array())));
53
+ }
54
+ subscribeStateChange() {
55
+ const data = api_1.SubscribeStatesRequest.encode({}).finish();
56
+ this.socket.sendEspMessage(requestResponseMatching_1.MessageTypes.SubscribeStatesRequest, data);
57
+ return (0, rxjs_1.of)(api_options_1.voidMessage.decode(new minimal_1.Reader(new Uint8Array())));
58
+ }
59
+ }
60
+ exports.Client = Client;
@@ -0,0 +1,23 @@
1
+ import { BaseComponent } from '../components';
2
+ import { Observable } from 'rxjs';
3
+ import { DeviceInfoResponse } from './protobuf/api';
4
+ export declare class EspDevice {
5
+ protected readonly host: string;
6
+ protected readonly password: string;
7
+ protected readonly port: number;
8
+ private readonly socket;
9
+ private readonly client;
10
+ private readonly stateEvents$;
11
+ deviceInfo?: DeviceInfoResponse;
12
+ readonly components: {
13
+ [key: string]: BaseComponent;
14
+ };
15
+ private readonly discovery;
16
+ readonly discovery$: Observable<boolean>;
17
+ private readonly subscription;
18
+ readonly alive$: Observable<boolean>;
19
+ constructor(host: string, password?: string, port?: number);
20
+ provideRetryObservable(retryWhen$: Observable<unknown>): void;
21
+ terminate(): void;
22
+ private parseListResponse;
23
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EspDevice = void 0;
4
+ const operators_1 = require("rxjs/operators");
5
+ const _1 = require("./");
6
+ const rxjs_1 = require("rxjs");
7
+ const espSocket_1 = require("./espSocket");
8
+ const api_1 = require("./protobuf/api");
9
+ const PING_TIMEOUT = 90 * 1000;
10
+ class EspDevice {
11
+ constructor(host, password = '', port = 6053) {
12
+ this.host = host;
13
+ this.password = password;
14
+ this.port = port;
15
+ this.components = {};
16
+ this.subscription = new rxjs_1.Subscription();
17
+ this.discovery = new rxjs_1.BehaviorSubject(false);
18
+ this.discovery$ = this.discovery.asObservable();
19
+ this.socket = new espSocket_1.EspSocket(host, port, {
20
+ timeout: PING_TIMEOUT,
21
+ });
22
+ this.client = new _1.Client(this.socket);
23
+ this.stateEvents$ = this.socket.espData$.pipe((0, operators_1.filter)((data) => _1.stateResponses.has(data.type)), (0, operators_1.map)((data) => (0, _1.stateParser)(data)), (0, operators_1.filter)((parsed) => !!parsed));
24
+ this.subscription.add(this.socket.espData$
25
+ .pipe((0, operators_1.tap)((data) => {
26
+ if (_1.listResponses.has(data.type)) {
27
+ this.parseListResponse(data);
28
+ }
29
+ else if (data.type === _1.MessageTypes.DeviceInfoResponse) {
30
+ this.deviceInfo = (0, _1.decode)(api_1.DeviceInfoResponse, data);
31
+ }
32
+ }))
33
+ .subscribe());
34
+ this.subscription.add(this.socket.connected$
35
+ .pipe((0, operators_1.distinctUntilChanged)(), (0, operators_1.tap)((connected) => {
36
+ if (!connected) {
37
+ this.socket.open();
38
+ }
39
+ }), (0, operators_1.filter)(_1.isTrue), (0, operators_1.switchMap)(() => this.client.hello({ clientInfo: 'esphome-ts' })), (0, operators_1.switchMap)(() => this.client.connect({ password })), (0, operators_1.switchMap)(() => this.client.deviceInfo()), (0, operators_1.switchMap)(() => this.client.listEntities()), (0, operators_1.switchMap)(() => this.client.subscribeStateChange()))
40
+ .subscribe());
41
+ this.socket.timeout$.pipe((0, operators_1.tap)(() => console.log('timeout'))).subscribe();
42
+ this.alive$ = (0, rxjs_1.merge)(this.socket.connected$, this.socket.espData$.pipe((0, operators_1.switchMap)(() => {
43
+ return (0, rxjs_1.concat)((0, rxjs_1.of)(true), this.socket.espData$.pipe((0, operators_1.mapTo)(true), (0, operators_1.timeout)(PING_TIMEOUT), (0, operators_1.catchError)(() => (0, rxjs_1.of)(false)), (0, operators_1.take)(1)));
44
+ }))).pipe((0, operators_1.distinctUntilChanged)(), (0, operators_1.shareReplay)(1));
45
+ }
46
+ provideRetryObservable(retryWhen$) {
47
+ this.subscription.add(this.alive$
48
+ .pipe((0, operators_1.filter)(_1.isFalse), (0, operators_1.switchMap)(() => retryWhen$.pipe((0, operators_1.tap)(() => this.socket.open()), (0, operators_1.takeUntil)(this.alive$.pipe((0, operators_1.filter)(_1.isTrue))))))
49
+ .subscribe());
50
+ }
51
+ terminate() {
52
+ Object.values(this.components).forEach((component) => {
53
+ component.terminate();
54
+ });
55
+ this.client.terminate();
56
+ this.socket.close(true);
57
+ this.subscription.unsubscribe();
58
+ }
59
+ parseListResponse(data) {
60
+ var _a, _b;
61
+ if (data.type === _1.MessageTypes.ListEntitiesDoneResponse) {
62
+ this.discovery.next(true);
63
+ }
64
+ else {
65
+ const knownComponents = new Set(Object.keys(this.components));
66
+ const { id, component, state$ } = (0, _1.createComponents)(data, this.stateEvents$, this.socket, knownComponents);
67
+ if (component) {
68
+ this.components[id] = (_a = this.components[id]) !== null && _a !== void 0 ? _a : component;
69
+ }
70
+ else if (state$) {
71
+ (_b = this.components[id]) === null || _b === void 0 ? void 0 : _b.provideStateObservable(state$);
72
+ }
73
+ }
74
+ }
75
+ }
76
+ exports.EspDevice = EspDevice;
@@ -0,0 +1,13 @@
1
+ import { Observable } from 'rxjs';
2
+ import { CommandInterface } from '../components';
3
+ import { RxjsSocket, RxjsSocketConfiguration } from './socket';
4
+ import { MessageTypes } from './requestResponseMatching';
5
+ export interface ReadData {
6
+ type: number;
7
+ payload: Uint8Array;
8
+ }
9
+ export declare class EspSocket extends RxjsSocket implements CommandInterface {
10
+ readonly espData$: Observable<ReadData>;
11
+ constructor(host: string, port: number, config?: RxjsSocketConfiguration);
12
+ sendEspMessage(type: MessageTypes, payload: Uint8Array): void;
13
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EspSocket = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const socket_1 = require("./socket");
7
+ const bytePositions_1 = require("./bytePositions");
8
+ const helpers_1 = require("./helpers");
9
+ class EspSocket extends socket_1.RxjsSocket {
10
+ constructor(host, port, config) {
11
+ super(host, port, config);
12
+ this.espData$ = this.data$.pipe((0, operators_1.switchMap)((buffer) => {
13
+ let bytesTaken = 0;
14
+ const result = [];
15
+ while (bytesTaken < buffer.length) {
16
+ const currentPackageSize = buffer[bytesTaken + bytePositions_1.BytePositions.LENGTH];
17
+ if (typeof currentPackageSize !== 'number') {
18
+ break;
19
+ }
20
+ const subBuffer = buffer.slice(bytesTaken, bytesTaken + bytePositions_1.HEADER_SIZE + currentPackageSize);
21
+ result.push(subBuffer);
22
+ bytesTaken += bytePositions_1.HEADER_SIZE + currentPackageSize;
23
+ }
24
+ return (0, rxjs_1.from)(result);
25
+ }), (0, operators_1.filter)((buffer) => buffer.length >= bytePositions_1.HEADER_SIZE), (0, operators_1.filter)((buffer) => buffer.readUInt8(bytePositions_1.BytePositions.ZERO) === bytePositions_1.HEADER_FIRST_BYTE), (0, operators_1.map)((buffer) => ({
26
+ type: buffer.readUInt8(bytePositions_1.BytePositions.TYPE),
27
+ payload: buffer.slice(bytePositions_1.BytePositions.PAYLOAD, bytePositions_1.BytePositions.PAYLOAD + buffer.readUInt8(bytePositions_1.BytePositions.LENGTH)),
28
+ })));
29
+ }
30
+ sendEspMessage(type, payload) {
31
+ this.connected$
32
+ .pipe((0, operators_1.timeout)(5000), (0, operators_1.filter)(helpers_1.isTrue), (0, operators_1.take)(1), (0, operators_1.switchMap)(() => {
33
+ const final = new Uint8Array([bytePositions_1.HEADER_FIRST_BYTE, payload.length, type, ...payload]);
34
+ return this.send(final);
35
+ }), (0, operators_1.takeUntil)(this.terminate))
36
+ .subscribe();
37
+ }
38
+ }
39
+ exports.EspSocket = EspSocket;
@@ -0,0 +1,19 @@
1
+ import { ListEntityResponses, StateResponses } from './interfaces';
2
+ import { CommandInterface } from '../components';
3
+ import { Observable } from 'rxjs';
4
+ import { BaseComponent } from '..';
5
+ import { ReadData } from './espSocket';
6
+ export declare const stateParser: (data: ReadData) => StateResponses | undefined;
7
+ export declare const createComponents: (data: ReadData, stateEvents$: Observable<StateResponses>, connection: CommandInterface, knownComponents: Set<string>) => {
8
+ id: string;
9
+ component?: BaseComponent;
10
+ state$?: Observable<StateResponses>;
11
+ };
12
+ export declare const emptyCommandInterface: CommandInterface;
13
+ export declare const transformStates: <T extends StateResponses>(stateEvents$: Observable<StateResponses>, listEntityResponse: ListEntityResponses) => Observable<T>;
14
+ declare type FalsyTypes = null | undefined | false | 0 | 0n | '';
15
+ export declare const isTrue: (val: unknown) => val is true;
16
+ export declare const isTruthy: <T>(val: T | FalsyTypes) => val is T;
17
+ export declare const isFalse: (val: unknown) => val is false;
18
+ export declare const isFalsy: <T>(val: FalsyTypes | T) => val is FalsyTypes;
19
+ export {};
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFalsy = exports.isFalse = exports.isTruthy = exports.isTrue = exports.transformStates = exports.emptyCommandInterface = exports.createComponents = exports.stateParser = void 0;
4
+ const api_1 = require("./protobuf/api");
5
+ const requestResponseMatching_1 = require("./requestResponseMatching");
6
+ const client_1 = require("./client");
7
+ const operators_1 = require("rxjs/operators");
8
+ const __1 = require("..");
9
+ const fan_1 = require("../components/fan");
10
+ const stateParser = (data) => {
11
+ switch (data.type) {
12
+ case requestResponseMatching_1.MessageTypes.BinarySensorStateResponse: {
13
+ return (0, client_1.decode)(api_1.BinarySensorStateResponse, data);
14
+ }
15
+ case requestResponseMatching_1.MessageTypes.LightStateResponse: {
16
+ return (0, client_1.decode)(api_1.LightStateResponse, data);
17
+ }
18
+ case requestResponseMatching_1.MessageTypes.SensorStateResponse: {
19
+ return (0, client_1.decode)(api_1.SensorStateResponse, data);
20
+ }
21
+ case requestResponseMatching_1.MessageTypes.SwitchStateResponse: {
22
+ return (0, client_1.decode)(api_1.SwitchStateResponse, data);
23
+ }
24
+ case requestResponseMatching_1.MessageTypes.CoverStateResponse: {
25
+ return (0, client_1.decode)(api_1.CoverStateResponse, data);
26
+ }
27
+ }
28
+ return undefined;
29
+ };
30
+ exports.stateParser = stateParser;
31
+ const createComponents = (data, stateEvents$, connection, knownComponents) => {
32
+ switch (data.type) {
33
+ case requestResponseMatching_1.MessageTypes.ListEntitiesBinarySensorResponse: {
34
+ const response = (0, client_1.decode)(api_1.ListEntitiesBinarySensorResponse, data);
35
+ const state$ = (0, exports.transformStates)(stateEvents$, response);
36
+ return knownComponents.has(response.objectId)
37
+ ? {
38
+ id: response.objectId,
39
+ state$,
40
+ }
41
+ : {
42
+ id: response.objectId,
43
+ component: new __1.BinarySensorComponent(response, state$, exports.emptyCommandInterface),
44
+ };
45
+ }
46
+ case requestResponseMatching_1.MessageTypes.ListEntitiesSwitchResponse: {
47
+ const response = (0, client_1.decode)(api_1.ListEntitiesSwitchResponse, data);
48
+ const state$ = (0, exports.transformStates)(stateEvents$, response);
49
+ return knownComponents.has(response.objectId)
50
+ ? {
51
+ id: response.objectId,
52
+ state$,
53
+ }
54
+ : {
55
+ id: response.objectId,
56
+ component: new __1.SwitchComponent(response, state$, connection),
57
+ };
58
+ }
59
+ case requestResponseMatching_1.MessageTypes.ListEntitiesLightResponse: {
60
+ const response = (0, client_1.decode)(api_1.ListEntitiesLightResponse, data);
61
+ const state$ = (0, exports.transformStates)(stateEvents$, response);
62
+ return knownComponents.has(response.objectId)
63
+ ? {
64
+ id: response.objectId,
65
+ state$,
66
+ }
67
+ : {
68
+ id: response.objectId,
69
+ component: new __1.LightComponent(response, state$, connection),
70
+ };
71
+ }
72
+ case requestResponseMatching_1.MessageTypes.ListEntitiesSensorResponse: {
73
+ const response = (0, client_1.decode)(api_1.ListEntitiesSensorResponse, data);
74
+ const state$ = (0, exports.transformStates)(stateEvents$, response);
75
+ return knownComponents.has(response.objectId)
76
+ ? {
77
+ id: response.objectId,
78
+ state$,
79
+ }
80
+ : {
81
+ id: response.objectId,
82
+ component: new __1.SensorComponent(response, state$, exports.emptyCommandInterface),
83
+ };
84
+ }
85
+ case requestResponseMatching_1.MessageTypes.ListEntitiesFanResponse: {
86
+ const response = (0, client_1.decode)(api_1.ListEntitiesFanResponse, data);
87
+ const state$ = (0, exports.transformStates)(stateEvents$, response);
88
+ return knownComponents.has(response.objectId)
89
+ ? {
90
+ id: response.objectId,
91
+ state$,
92
+ }
93
+ : {
94
+ id: response.objectId,
95
+ component: new fan_1.FanComponent(response, state$, connection),
96
+ };
97
+ }
98
+ }
99
+ return { id: '' };
100
+ };
101
+ exports.createComponents = createComponents;
102
+ exports.emptyCommandInterface = {
103
+ sendEspMessage: () => undefined,
104
+ };
105
+ const transformStates = (stateEvents$, listEntityResponse) => {
106
+ return stateEvents$.pipe((0, operators_1.filter)((stateEvent) => stateEvent.key === listEntityResponse.key));
107
+ };
108
+ exports.transformStates = transformStates;
109
+ const isTrue = (val) => val === true;
110
+ exports.isTrue = isTrue;
111
+ const isTruthy = (val) => !!val;
112
+ exports.isTruthy = isTruthy;
113
+ const isFalse = (val) => val === false;
114
+ exports.isFalse = isFalse;
115
+ const isFalsy = (val) => !val;
116
+ exports.isFalsy = isFalsy;
@@ -0,0 +1,9 @@
1
+ export * from './bytePositions';
2
+ export * from './client';
3
+ export * from './espDevice';
4
+ export * from './helpers';
5
+ export * from './interfaces';
6
+ export * from './requestResponseMatching';
7
+ export * from './responses';
8
+ export * from './socket';
9
+ export * from './typeGuards';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./bytePositions"), exports);
14
+ __exportStar(require("./client"), exports);
15
+ __exportStar(require("./espDevice"), exports);
16
+ __exportStar(require("./helpers"), exports);
17
+ __exportStar(require("./interfaces"), exports);
18
+ __exportStar(require("./requestResponseMatching"), exports);
19
+ __exportStar(require("./responses"), exports);
20
+ __exportStar(require("./socket"), exports);
21
+ __exportStar(require("./typeGuards"), exports);
@@ -0,0 +1,4 @@
1
+ import { BinarySensorStateResponse, CoverCommandRequest, CoverStateResponse, FanCommandRequest, FanStateResponse, LightCommandRequest, LightStateResponse, ListEntitiesBinarySensorResponse, ListEntitiesCoverResponse, ListEntitiesFanResponse, ListEntitiesLightResponse, ListEntitiesSensorResponse, ListEntitiesSwitchResponse, ListEntitiesTextSensorResponse, SensorStateResponse, SwitchCommandRequest, SwitchStateResponse, TextSensorStateResponse } from './protobuf/api';
2
+ export declare type ListEntityResponses = ListEntitiesBinarySensorResponse | ListEntitiesCoverResponse | ListEntitiesFanResponse | ListEntitiesLightResponse | ListEntitiesSensorResponse | ListEntitiesSwitchResponse | ListEntitiesTextSensorResponse;
3
+ export declare type StateResponses = BinarySensorStateResponse | CoverStateResponse | FanStateResponse | LightStateResponse | SensorStateResponse | SwitchStateResponse | TextSensorStateResponse;
4
+ export declare type CommandRequests = CoverCommandRequest | FanCommandRequest | LightCommandRequest | SwitchCommandRequest;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });