esphome-ts 3.3.1 → 4.0.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 (60) hide show
  1. package/README.md +33 -1
  2. package/dist/index.d.ts +379 -2
  3. package/dist/index.js +3355 -18
  4. package/package.json +58 -39
  5. package/dist/api/bytePositions.d.ts +0 -8
  6. package/dist/api/bytePositions.js +0 -12
  7. package/dist/api/client.d.ts +0 -22
  8. package/dist/api/client.js +0 -60
  9. package/dist/api/connection.d.ts +0 -18
  10. package/dist/api/connection.js +0 -51
  11. package/dist/api/espDevice.d.ts +0 -23
  12. package/dist/api/espDevice.js +0 -76
  13. package/dist/api/espSocket.d.ts +0 -13
  14. package/dist/api/espSocket.js +0 -35
  15. package/dist/api/helpers.d.ts +0 -17
  16. package/dist/api/helpers.js +0 -102
  17. package/dist/api/index.d.ts +0 -10
  18. package/dist/api/index.js +0 -26
  19. package/dist/api/interfaces.d.ts +0 -4
  20. package/dist/api/interfaces.js +0 -2
  21. package/dist/api/protobuf/api.d.ts +0 -922
  22. package/dist/api/protobuf/api.js +0 -6678
  23. package/dist/api/protobuf/api_options.d.ts +0 -24
  24. package/dist/api/protobuf/api_options.js +0 -76
  25. package/dist/api/protobuf/google_descriptor.d.ts +0 -1022
  26. package/dist/api/protobuf/google_descriptor.js +0 -3980
  27. package/dist/api/requestResponseMatching.d.ts +0 -50
  28. package/dist/api/requestResponseMatching.js +0 -54
  29. package/dist/api/responses.d.ts +0 -3
  30. package/dist/api/responses.js +0 -23
  31. package/dist/api/socket.d.ts +0 -29
  32. package/dist/api/socket.js +0 -109
  33. package/dist/api/typeGuards.d.ts +0 -5
  34. package/dist/api/typeGuards.js +0 -7
  35. package/dist/components/base.d.ts +0 -23
  36. package/dist/components/base.js +0 -51
  37. package/dist/components/binarySensor.d.ts +0 -9
  38. package/dist/components/binarySensor.js +0 -19
  39. package/dist/components/binarySensorTypes.d.ts +0 -26
  40. package/dist/components/binarySensorTypes.js +0 -30
  41. package/dist/components/commandInterface.d.ts +0 -4
  42. package/dist/components/commandInterface.js +0 -2
  43. package/dist/components/entities.d.ts +0 -21
  44. package/dist/components/entities.js +0 -2
  45. package/dist/components/helpers.d.ts +0 -1
  46. package/dist/components/helpers.js +0 -12
  47. package/dist/components/index.d.ts +0 -11
  48. package/dist/components/index.js +0 -27
  49. package/dist/components/interfaces.d.ts +0 -10
  50. package/dist/components/interfaces.js +0 -2
  51. package/dist/components/light.d.ts +0 -22
  52. package/dist/components/light.js +0 -159
  53. package/dist/components/sensor.d.ts +0 -10
  54. package/dist/components/sensor.js +0 -23
  55. package/dist/components/states.d.ts +0 -18
  56. package/dist/components/states.js +0 -2
  57. package/dist/components/switch.d.ts +0 -9
  58. package/dist/components/switch.js +0 -28
  59. package/dist/run.d.ts +0 -1
  60. package/dist/run.js +0 -17
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LightComponent = exports.DEFAULT_NO_EFFECT = void 0;
4
- const helpers_1 = require("./helpers");
5
- const base_1 = require("./base");
6
- const color_convert_1 = require("color-convert");
7
- const api_1 = require("../api/protobuf/api");
8
- const api_2 = require("../api");
9
- exports.DEFAULT_NO_EFFECT = 'None';
10
- class LightComponent extends base_1.BaseComponent {
11
- turnOn() {
12
- this.queueCommand(api_2.MessageTypes.LightCommandRequest, () => api_1.LightCommandRequest.encode(this.generateState(1)).finish());
13
- }
14
- turnOff() {
15
- this.queueCommand(api_2.MessageTypes.LightCommandRequest, () => api_1.LightCommandRequest.encode(this.generateState(0, false)).finish());
16
- }
17
- getBrightness() {
18
- const state = this.state.getValue();
19
- if ((state === null || state === void 0 ? void 0 : state.brightness) === undefined || !this.listEntity.supportsBrightness) {
20
- return undefined;
21
- }
22
- else if (this.listEntity.supportsRgb) {
23
- return this.hsv.value;
24
- }
25
- else if (this.listEntity.supportsBrightness) {
26
- return (0, helpers_1.convertNumbers)(state.brightness, 100, true);
27
- }
28
- }
29
- setBrightness(brightness) {
30
- if (this.listEntity.supportsRgb) {
31
- const { hue, saturation } = this.hsv;
32
- this.hsv = {
33
- hue,
34
- saturation,
35
- value: brightness,
36
- };
37
- }
38
- else if (this.listEntity.supportsBrightness) {
39
- const bright = (0, helpers_1.convertNumbers)(brightness, 100, false);
40
- const state = this.generateState(1);
41
- state.brightness = bright;
42
- this.queueCommand(api_2.MessageTypes.LightCommandRequest, () => api_1.LightCommandRequest.encode(state).finish());
43
- }
44
- }
45
- get hsv() {
46
- var _a, _b, _c, _d;
47
- const state = this.state.getValue();
48
- if (!state || !this.supportsRgb) {
49
- return {
50
- hue: 0,
51
- saturation: 0,
52
- value: 0,
53
- };
54
- }
55
- const [hue, saturation] = color_convert_1.rgb.hsv([(_a = state.red) !== null && _a !== void 0 ? _a : 0, (_b = state.green) !== null && _b !== void 0 ? _b : 0, (_c = state.blue) !== null && _c !== void 0 ? _c : 0]);
56
- return {
57
- hue,
58
- saturation,
59
- value: ((_d = state.brightness) !== null && _d !== void 0 ? _d : 0) * 100,
60
- };
61
- }
62
- set hsv(hsv) {
63
- if (!this.listEntity.supportsRgb) {
64
- return;
65
- }
66
- const [red, green, blue] = color_convert_1.hsv.rgb([hsv.hue, hsv.saturation, 100]);
67
- const newState = {
68
- red: (0, helpers_1.convertNumbers)(red, 255, false),
69
- green: (0, helpers_1.convertNumbers)(green, 255, false),
70
- blue: (0, helpers_1.convertNumbers)(blue, 255, false),
71
- brightness: (0, helpers_1.convertNumbers)(hsv.value, 100, false),
72
- };
73
- this.queueCommand(api_2.MessageTypes.LightCommandRequest, () => api_1.LightCommandRequest.encode(Object.assign(this.generateState(1), newState)).finish());
74
- }
75
- get rgb() {
76
- if (!this.listEntity.supportsRgb) {
77
- return {
78
- red: 0,
79
- green: 0,
80
- blue: 0,
81
- };
82
- }
83
- const { hue, saturation, value } = this.hsv;
84
- const [red, green, blue] = color_convert_1.hsv.rgb([hue, saturation, value]);
85
- return {
86
- red,
87
- green,
88
- blue,
89
- };
90
- }
91
- set rgb({ red, green, blue }) {
92
- if (!this.listEntity.supportsRgb) {
93
- return;
94
- }
95
- const [hue, saturation, value] = color_convert_1.rgb.hsv([red, green, blue]);
96
- this.hsv = {
97
- hue,
98
- saturation,
99
- value,
100
- };
101
- }
102
- get type() {
103
- return 'light';
104
- }
105
- get supportsRgb() {
106
- return this.listEntity.supportsRgb;
107
- }
108
- get supportsBrightness() {
109
- return this.listEntity.supportsBrightness;
110
- }
111
- availableEffects() {
112
- var _a;
113
- return (_a = this.listEntity.effects) !== null && _a !== void 0 ? _a : [];
114
- }
115
- get effect() {
116
- var _a;
117
- const state = this.state.getValue();
118
- return (_a = state === null || state === void 0 ? void 0 : state.effect) !== null && _a !== void 0 ? _a : exports.DEFAULT_NO_EFFECT;
119
- }
120
- set effect(effect) {
121
- var _a;
122
- const effects = (_a = this.listEntity.effects) !== null && _a !== void 0 ? _a : [];
123
- if (effects.includes(effect)) {
124
- this.queueCommand(api_2.MessageTypes.LightCommandRequest, () => {
125
- const command = this.generateState(1, true);
126
- command.effect = effect;
127
- command.hasRgb = false;
128
- command.hasEffect = true;
129
- return api_1.LightCommandRequest.encode(command).finish();
130
- });
131
- }
132
- }
133
- generateState(num, turnOn = true) {
134
- var _a, _b, _c, _d;
135
- const state = this.state.getValue();
136
- return {
137
- blue: (_a = state === null || state === void 0 ? void 0 : state.blue) !== null && _a !== void 0 ? _a : num,
138
- brightness: (_b = state === null || state === void 0 ? void 0 : state.brightness) !== null && _b !== void 0 ? _b : num,
139
- colorTemperature: 0,
140
- effect: '',
141
- flashLength: 0,
142
- green: (_c = state === null || state === void 0 ? void 0 : state.green) !== null && _c !== void 0 ? _c : num,
143
- hasBrightness: this.listEntity.supportsBrightness,
144
- hasColorTemperature: false,
145
- hasEffect: false,
146
- hasFlashLength: false,
147
- hasRgb: this.listEntity.supportsRgb,
148
- hasState: true,
149
- hasTransitionLength: false,
150
- hasWhite: false,
151
- red: (_d = state === null || state === void 0 ? void 0 : state.red) !== null && _d !== void 0 ? _d : num,
152
- transitionLength: 1,
153
- white: 0,
154
- key: this.key,
155
- state: turnOn,
156
- };
157
- }
158
- }
159
- exports.LightComponent = LightComponent;
@@ -1,10 +0,0 @@
1
- import { BaseComponent } from './base';
2
- import { ComponentType, SensorEntity } from './entities';
3
- import { SensorStateEvent } from './states';
4
- export declare class SensorComponent extends BaseComponent<SensorEntity, SensorStateEvent> {
5
- get value(): number | undefined;
6
- get type(): ComponentType;
7
- get deviceClass(): string | undefined;
8
- get unitOfMeasurement(): string;
9
- get icon(): string;
10
- }
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SensorComponent = void 0;
4
- const base_1 = require("./base");
5
- class SensorComponent extends base_1.BaseComponent {
6
- get value() {
7
- const state = this.state.getValue();
8
- return state === null || state === void 0 ? void 0 : state.state;
9
- }
10
- get type() {
11
- return 'sensor';
12
- }
13
- get deviceClass() {
14
- return this.listEntity.deviceClass;
15
- }
16
- get unitOfMeasurement() {
17
- return this.listEntity.unitOfMeasurement;
18
- }
19
- get icon() {
20
- return this.listEntity.icon;
21
- }
22
- }
23
- exports.SensorComponent = SensorComponent;
@@ -1,18 +0,0 @@
1
- export interface StateEvent {
2
- key: number;
3
- }
4
- export interface SensorStateEvent extends StateEvent {
5
- state?: number;
6
- }
7
- export interface BinarySensorStateEvent extends StateEvent {
8
- state?: boolean;
9
- }
10
- export type SwitchStateEvent = BinarySensorStateEvent;
11
- export interface LightStateEvent extends StateEvent {
12
- state?: boolean;
13
- brightness?: number;
14
- red?: number;
15
- green?: number;
16
- blue?: number;
17
- effect?: string;
18
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import { BaseComponent } from './base';
2
- import { ComponentType, ListEntity } from './entities';
3
- import { SwitchStateEvent } from './states';
4
- export declare class SwitchComponent extends BaseComponent<ListEntity, SwitchStateEvent> {
5
- get status(): boolean;
6
- turnOn(): void;
7
- turnOff(): void;
8
- get type(): ComponentType;
9
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwitchComponent = void 0;
4
- const base_1 = require("./base");
5
- const api_1 = require("../api");
6
- const api_2 = require("../api/protobuf/api");
7
- class SwitchComponent extends base_1.BaseComponent {
8
- get status() {
9
- const state = this.state.getValue();
10
- return !!(state === null || state === void 0 ? void 0 : state.state);
11
- }
12
- turnOn() {
13
- this.queueCommand(api_1.MessageTypes.SwitchCommandRequest, () => api_2.SwitchCommandRequest.encode({
14
- state: true,
15
- key: this.key,
16
- }).finish(), true);
17
- }
18
- turnOff() {
19
- this.queueCommand(api_1.MessageTypes.SwitchCommandRequest, () => api_2.SwitchCommandRequest.encode({
20
- state: false,
21
- key: this.key,
22
- }).finish(), true);
23
- }
24
- get type() {
25
- return 'switch';
26
- }
27
- }
28
- exports.SwitchComponent = SwitchComponent;
package/dist/run.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/run.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const operators_1 = require("rxjs/operators");
4
- const api_1 = require("./api");
5
- const device = new api_1.EspDevice('172.16.0.112');
6
- device.discovery$
7
- .pipe((0, operators_1.filter)(api_1.isTrue), (0, operators_1.take)(1), (0, operators_1.tap)(() => {
8
- const kitchenLights = device.components['kitchen_lights:'];
9
- const livingRoomDehumidifier = device.components['living_room_dehumidifier'];
10
- console.log(livingRoomDehumidifier.name);
11
- if ((0, api_1.isSwitchComponent)(livingRoomDehumidifier)) {
12
- livingRoomDehumidifier.state$.pipe((0, operators_1.tap)(console.log)).subscribe();
13
- livingRoomDehumidifier.turnOff();
14
- }
15
- }))
16
- .subscribe();
17
- device.alive$.pipe((0, operators_1.tap)((val) => console.log('alive', val))).subscribe();