forked from nurikk/zigbee2mqtt-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
325 lines (285 loc) · 8 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import { JSONSchema7 } from 'json-schema';
import { CustomClusters } from './zcl/definition/tstype';
export type DeviceType = 'EndDevice' | 'Router' | 'Coordinator';
export type FriendlyName = string;
export type IEEEEAddress = string;
export type OTAState = {
state: 'available' | 'updating';
progress: number;
remaining: number;
};
export type RGBColor = {
r: number;
g: number;
b: number;
};
export type HueSaturationColor = {
hue: number;
saturation: number;
};
export type XYColor = {
x: number;
y: number;
};
export type AnyColor = RGBColor | XYColor | HueSaturationColor;
export type DeviceState = Record<string, unknown>;
export type Cluster = string | number;
export type Attribute = string;
export type Endpoint = string | number;
export interface AttributeDefinition {
ID: number;
type: number;
manufacturerCode?: number;
}
export interface Parameter {
name: string;
type: number;
}
export interface CommandDefinition {
ID: number;
parameters: readonly Parameter[];
response?: number;
}
export interface ClusterDefinition {
ID: number;
name?: string;
manufacturerCode?: number;
attributes: Readonly<Record<string, Readonly<AttributeDefinition>>>;
commands: Readonly<Record<string, Readonly<CommandDefinition>>>;
commandsResponse: Readonly<Record<string, Readonly<CommandDefinition>>>;
}
export interface BridgeDefinitions {
clusters: Readonly<Record<Cluster, Readonly<ClusterDefinition>>>;
custom_clusters: Readonly<Record<IEEEEAddress, Readonly<CustomClusters>>>;
}
export interface Meta {
revision: number;
transportrev: number;
product: number;
majorrel: number;
minorrel: number;
maintrel: number;
}
export interface Coordinator {
type: string;
meta: Meta;
}
export interface Network {
channel: number;
pan_id: number;
extended_pan_id: number[];
}
export type DeviceConfig = Record<string, unknown>;
export interface AdvancedConfig {
elapsed: boolean;
last_seen: 'disable' | 'ISO_8601' | 'ISO_8601_local' | 'epoch';
legacy_api: boolean;
}
export interface Z2MConfig {
homeassistant: boolean;
advanced: AdvancedConfig;
devices: Record<string, DeviceConfig>;
device_options: DeviceConfig;
[k: string]: unknown;
}
export type BridgeState = 'online' | 'offline';
export interface BridgeInfo {
config: Z2MConfig;
config_schema: JSONSchema7;
permit_join: boolean;
permit_join_end: number | undefined;
commit?: string;
version?: string;
zigbee_herdsman_converters: { version: string };
zigbee_herdsman: { version: string };
coordinator?: {
meta?: {
revision?: string;
};
type?: string;
ieee_address: string;
};
device_options: Record<IEEEEAddress, unknown>;
restart_required: boolean;
}
export type PowerSource = 'Battery' | 'Mains (single phase)' | 'DC Source';
export type GenericFeatureType = 'numeric' | 'binary' | 'enum' | 'text' | 'list';
export type CompositeFeatureType = 'fan' | 'light' | 'switch' | 'cover' | 'lock' | 'composite' | 'climate';
export enum FeatureAccessMode {
NONE,
ACCESS_STATE = 0b001,
ACCESS_WRITE = 0b010,
ACCESS_READ = 0b100,
}
export interface GenericExposedFeature {
type: GenericFeatureType;
name: string;
label: string;
unit?: 'string';
access: FeatureAccessMode;
endpoint?: Endpoint;
property?: string;
description?: string;
}
export interface BinaryFeature extends GenericExposedFeature {
type: 'binary';
value_on: unknown;
value_off: unknown;
value_toggle?: unknown;
}
export interface ListFeature extends GenericExposedFeature {
type: 'list';
// bad design decision
item_type: 'number' | GenericOrCompositeFeature;
length_min?: number;
length_max?: number;
}
export interface CompositeFeature extends Omit<GenericExposedFeature, 'type'> {
type: CompositeFeatureType;
features: GenericOrCompositeFeature[];
}
export type GenericOrCompositeFeature = GenericExposedFeature | CompositeFeature;
export interface NumericFeaturePreset {
name: string;
value: number;
description?: string;
}
export interface NumericFeature extends GenericExposedFeature {
type: 'numeric';
value_min?: number;
value_max?: number;
value_step?: number;
presets?: NumericFeaturePreset[];
}
export interface TextualFeature extends GenericExposedFeature {
type: 'text';
}
export interface EnumFeature extends GenericExposedFeature {
type: 'enum';
values: unknown[];
}
export interface GradientFeature extends GenericExposedFeature {
type: 'text';
name: 'gradient';
length_min: number;
length_max: number;
}
export interface LightFeature extends CompositeFeature {
type: 'light';
}
export interface SwitchFeature extends CompositeFeature {
type: 'switch';
}
export interface CoverFeature extends CompositeFeature {
type: 'cover';
}
export interface LockFeature extends CompositeFeature {
type: 'lock';
}
export interface FanFeature extends CompositeFeature {
type: 'fan';
}
export interface ClimateFeature extends CompositeFeature {
type: 'climate';
}
export interface ColorFeature extends CompositeFeature {
type: 'composite';
name: 'color_xy' | 'color_hs';
features: NumericFeature[];
}
export interface DeviceDefinition {
description: string;
model: string;
supports: string;
vendor: string;
exposes: GenericOrCompositeFeature[];
options: GenericOrCompositeFeature[];
supports_ota: boolean;
icon?: string;
custom_clusters?: CustomClusters;
}
export interface ReportingConfig {
cluster: Cluster;
attribute: Attribute;
maximum_report_interval: number;
minimum_report_interval: number;
reportable_change: number;
}
export interface WithScenes {
scenes?: Scene[];
}
export interface EndpointDescription extends WithScenes {
bindings: BindRule[];
configured_reportings: ReportingConfig[];
clusters: {
input: Cluster[];
output: Cluster[];
};
}
export interface WithDescription {
description: string;
}
export interface WithFriendlyName {
friendly_name: FriendlyName;
}
export interface GroupAddress {
endpoint: Endpoint;
ieee_address: IEEEEAddress;
}
export type Scene = {
id: number;
name?: string;
endpoint?: Endpoint;
};
export interface Group extends WithFriendlyName, WithDescription, WithScenes {
id: number;
members: GroupAddress[];
}
export interface Device extends WithFriendlyName, WithDescription {
ieee_address: IEEEEAddress;
type: DeviceType;
network_address: number;
source_route: number[];
power_source?: PowerSource;
model_id: string;
manufacturer: string;
interviewing: boolean;
interview_completed: boolean;
software_build_id: number;
supported: boolean;
definition?: DeviceDefinition;
date_code: string;
endpoints: Record<Endpoint, EndpointDescription>;
}
export type ObjectType = 'device' | 'group';
export interface BindRule {
cluster: Cluster;
target: {
id?: number;
endpoint?: Endpoint;
ieee_address?: IEEEEAddress;
type: 'endpoint' | 'group';
};
}
export interface TouchLinkDevice {
ieee_address: IEEEEAddress;
channel: number;
}
export type LastSeenType = 'disable' | 'ISO_8601' | 'ISO_8601_local' | 'epoch';
export type KVP = Record<string, unknown>;
export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
export type Join<K, P> = K extends string | number
? P extends string | number
? `${K}${'' extends P ? '' : '.'}${P}`
: never
: never;
export type Paths<T, D extends number = 10> = [D] extends [never]
? never
: T extends object
? { [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Paths<T[K], Prev[D]>> : never }[keyof T]
: '';
export type Leaves<T, D extends number = 10> = [D] extends [never]
? never
: T extends object
? { [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T]
: '';