mqtt2matter 0.3.2 → 0.5.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.
- package/CHANGELOG.md +35 -0
- package/README.md +17 -0
- package/dist/engine/payload.d.ts +6 -3
- package/dist/engine/payload.js +8 -1
- package/dist/engine/payload.js.map +1 -1
- package/dist/engine/runtime.js +4 -0
- package/dist/engine/runtime.js.map +1 -1
- package/dist/engine/template.d.ts +1 -20
- package/dist/engine/template.js +4 -263
- package/dist/engine/template.js.map +1 -1
- package/dist/families/color.d.ts +3 -22
- package/dist/families/color.js +7 -144
- package/dist/families/color.js.map +1 -1
- package/dist/importers/ha/areas.d.ts +1 -6
- package/dist/importers/ha/areas.js +5 -278
- package/dist/importers/ha/areas.js.map +1 -1
- package/dist/importers/ha/source.d.ts +11 -9
- package/dist/importers/ha/source.js +22 -63
- package/dist/importers/ha/source.js.map +1 -1
- package/dist/importers/ha/templates.d.ts +3 -14
- package/dist/importers/ha/templates.js +7 -248
- package/dist/importers/ha/templates.js.map +1 -1
- package/dist/importers/ha/types.d.ts +2 -78
- package/dist/importers/ha/types.js +1 -472
- package/dist/importers/ha/types.js.map +1 -1
- package/dist/mqtt/client.d.ts +17 -3
- package/dist/mqtt/client.js +70 -13
- package/dist/mqtt/client.js.map +1 -1
- package/dist/server/server.d.ts +12 -1
- package/dist/server/server.js +35 -1
- package/dist/server/server.js.map +1 -1
- package/docs/config.md +1 -1
- package/docs/importers.md +2 -2
- package/package.json +2 -2
- package/ui/dist/assets/index-4vhUtv0G.css +1 -0
- package/ui/dist/assets/index-Bapuw9pm.js +10 -0
- package/ui/dist/index.html +2 -2
- package/ui/dist/licenses.json +1 -1
- package/ui/dist/assets/index-Bl_bpL_0.js +0 -10
- package/ui/dist/assets/index-DsAb-xhK.css +0 -1
package/dist/families/color.d.ts
CHANGED
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
saturation: number;
|
|
4
|
-
}
|
|
5
|
-
export interface Xy {
|
|
6
|
-
x: number;
|
|
7
|
-
y: number;
|
|
8
|
-
}
|
|
9
|
-
export interface Rgb {
|
|
10
|
-
r: number;
|
|
11
|
-
g: number;
|
|
12
|
-
b: number;
|
|
13
|
-
}
|
|
14
|
-
export declare function hsToRgb({ hue, saturation }: Hs, value?: number): Rgb;
|
|
15
|
-
export declare function rgbToHs({ r, g, b }: Rgb): Hs;
|
|
16
|
-
export declare function rgbToXy({ r, g, b }: Rgb): Xy;
|
|
17
|
-
export declare function xyToRgb({ x, y }: Xy, brightness?: number): Rgb;
|
|
18
|
-
export declare function hsToXy(hs: Hs): Xy;
|
|
19
|
-
export declare function xyToHs(xy: Xy): Hs;
|
|
1
|
+
export { hsToRgb, rgbToHs, rgbToXy, xyToRgb, hsToXy, xyToHs, parseColor } from 'mqtt-ha-entities';
|
|
2
|
+
export type { Hs, Xy, Rgb } from 'mqtt-ha-entities';
|
|
20
3
|
/** Matter hue 0–254 ↔ degrees */
|
|
21
4
|
export declare const hueToMatter: (deg: number) => number;
|
|
22
5
|
export declare const hueFromMatter: (v: number) => number;
|
|
23
6
|
/** Matter saturation 0–254 ↔ percent */
|
|
24
7
|
export declare const saturationToMatter: (pct: number) => number;
|
|
25
8
|
export declare const saturationFromMatter: (v: number) => number;
|
|
26
|
-
/**
|
|
9
|
+
/** CurrentX/CurrentY = x/y × 65536, at most 65279 (0xFEFF): Matter 1.4 ColorControl, CurrentX/CurrentY */
|
|
27
10
|
export declare const xyToMatter: (v: number) => number;
|
|
28
11
|
export declare const xyFromMatter: (v: number) => number;
|
|
29
|
-
/** parse a colour object, array or `"a,b(,c)"` into named fields */
|
|
30
|
-
export declare function parseColor(value: unknown, names: readonly string[], aliases?: Record<string, string>): number[] | undefined;
|
package/dist/families/color.js
CHANGED
|
@@ -1,152 +1,15 @@
|
|
|
1
|
-
/* Colour
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* Colour for the light family: the conversions between hue/saturation (0–360°, 0–100 %), CIE xy (0–1) and
|
|
2
|
+
RGB (0–255) come from mqtt-ha-entities (sRGB with its gamma, D65 white; good enough for lights, not for
|
|
3
|
+
colorimetry); the Matter scalings are mqtt2matter's: hue and saturation 0–254, x and y × 65536 up to 65279. */
|
|
4
|
+
export { hsToRgb, rgbToHs, rgbToXy, xyToRgb, hsToXy, xyToHs, parseColor } from 'mqtt-ha-entities';
|
|
4
5
|
const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
|
|
5
|
-
export function hsToRgb({ hue, saturation }, value = 1) {
|
|
6
|
-
const h = (((hue % 360) + 360) % 360) / 60;
|
|
7
|
-
const s = clamp(saturation / 100, 0, 1);
|
|
8
|
-
const c = value * s;
|
|
9
|
-
const x = c * (1 - Math.abs((h % 2) - 1));
|
|
10
|
-
const m = value - c;
|
|
11
|
-
let r;
|
|
12
|
-
let g;
|
|
13
|
-
let b;
|
|
14
|
-
if (h < 1) {
|
|
15
|
-
[r, g, b] = [c, x, 0];
|
|
16
|
-
}
|
|
17
|
-
else if (h < 2) {
|
|
18
|
-
[r, g, b] = [x, c, 0];
|
|
19
|
-
}
|
|
20
|
-
else if (h < 3) {
|
|
21
|
-
[r, g, b] = [0, c, x];
|
|
22
|
-
}
|
|
23
|
-
else if (h < 4) {
|
|
24
|
-
[r, g, b] = [0, x, c];
|
|
25
|
-
}
|
|
26
|
-
else if (h < 5) {
|
|
27
|
-
[r, g, b] = [x, 0, c];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
[r, g, b] = [c, 0, x];
|
|
31
|
-
}
|
|
32
|
-
return { r: Math.round((r + m) * 255), g: Math.round((g + m) * 255), b: Math.round((b + m) * 255) };
|
|
33
|
-
}
|
|
34
|
-
export function rgbToHs({ r, g, b }) {
|
|
35
|
-
const rn = clamp(r, 0, 255) / 255;
|
|
36
|
-
const gn = clamp(g, 0, 255) / 255;
|
|
37
|
-
const bn = clamp(b, 0, 255) / 255;
|
|
38
|
-
const max = Math.max(rn, gn, bn);
|
|
39
|
-
const min = Math.min(rn, gn, bn);
|
|
40
|
-
const delta = max - min;
|
|
41
|
-
let hue = 0;
|
|
42
|
-
if (delta !== 0) {
|
|
43
|
-
if (max === rn) {
|
|
44
|
-
hue = 60 * (((gn - bn) / delta) % 6);
|
|
45
|
-
}
|
|
46
|
-
else if (max === gn) {
|
|
47
|
-
hue = 60 * ((bn - rn) / delta + 2);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
hue = 60 * ((rn - gn) / delta + 4);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (hue < 0) {
|
|
54
|
-
hue += 360;
|
|
55
|
-
}
|
|
56
|
-
const saturation = max === 0 ? 0 : (delta / max) * 100;
|
|
57
|
-
return { hue: Math.round(hue * 100) / 100, saturation: Math.round(saturation * 100) / 100 };
|
|
58
|
-
}
|
|
59
|
-
function gammaDecode(c) {
|
|
60
|
-
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
61
|
-
}
|
|
62
|
-
function gammaEncode(c) {
|
|
63
|
-
return c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055;
|
|
64
|
-
}
|
|
65
|
-
export function rgbToXy({ r, g, b }) {
|
|
66
|
-
const rl = gammaDecode(clamp(r, 0, 255) / 255);
|
|
67
|
-
const gl = gammaDecode(clamp(g, 0, 255) / 255);
|
|
68
|
-
const bl = gammaDecode(clamp(b, 0, 255) / 255);
|
|
69
|
-
const X = rl * 0.4124 + gl * 0.3576 + bl * 0.1805;
|
|
70
|
-
const Y = rl * 0.2126 + gl * 0.7152 + bl * 0.0722;
|
|
71
|
-
const Z = rl * 0.0193 + gl * 0.1192 + bl * 0.9505;
|
|
72
|
-
const sum = X + Y + Z;
|
|
73
|
-
if (sum === 0) {
|
|
74
|
-
return { x: 0.3127, y: 0.329 };
|
|
75
|
-
}
|
|
76
|
-
return { x: Math.round((X / sum) * 10000) / 10000, y: Math.round((Y / sum) * 10000) / 10000 };
|
|
77
|
-
}
|
|
78
|
-
export function xyToRgb({ x, y }, brightness = 1) {
|
|
79
|
-
if (y <= 0) {
|
|
80
|
-
return { r: 0, g: 0, b: 0 };
|
|
81
|
-
}
|
|
82
|
-
const Y = brightness;
|
|
83
|
-
const X = (Y / y) * x;
|
|
84
|
-
const Z = (Y / y) * (1 - x - y);
|
|
85
|
-
let r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
|
|
86
|
-
let g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
|
|
87
|
-
let b = X * 0.0557 + Y * -0.204 + Z * 1.057;
|
|
88
|
-
const max = Math.max(r, g, b);
|
|
89
|
-
if (max > 1) {
|
|
90
|
-
r /= max;
|
|
91
|
-
g /= max;
|
|
92
|
-
b /= max;
|
|
93
|
-
}
|
|
94
|
-
r = gammaEncode(clamp(r, 0, 1));
|
|
95
|
-
g = gammaEncode(clamp(g, 0, 1));
|
|
96
|
-
b = gammaEncode(clamp(b, 0, 1));
|
|
97
|
-
const top = Math.max(r, g, b);
|
|
98
|
-
if (top > 0) {
|
|
99
|
-
r /= top;
|
|
100
|
-
g /= top;
|
|
101
|
-
b /= top;
|
|
102
|
-
}
|
|
103
|
-
return { r: Math.round(r * 255), g: Math.round(g * 255), b: Math.round(b * 255) };
|
|
104
|
-
}
|
|
105
|
-
export function hsToXy(hs) {
|
|
106
|
-
return rgbToXy(hsToRgb(hs));
|
|
107
|
-
}
|
|
108
|
-
export function xyToHs(xy) {
|
|
109
|
-
return rgbToHs(xyToRgb(xy));
|
|
110
|
-
}
|
|
111
6
|
/** Matter hue 0–254 ↔ degrees */
|
|
112
7
|
export const hueToMatter = (deg) => Math.round((((deg % 360) + 360) % 360) * (254 / 360));
|
|
113
8
|
export const hueFromMatter = (v) => Math.round((v / 254) * 360 * 100) / 100;
|
|
114
9
|
/** Matter saturation 0–254 ↔ percent */
|
|
115
10
|
export const saturationToMatter = (pct) => Math.round(clamp(pct, 0, 100) * 2.54);
|
|
116
11
|
export const saturationFromMatter = (v) => Math.round((v / 254) * 100 * 100) / 100;
|
|
117
|
-
/**
|
|
118
|
-
export const xyToMatter = (v) => Math.round(clamp(v, 0, 1) *
|
|
119
|
-
export const xyFromMatter = (v) => Math.round((v /
|
|
120
|
-
/** parse a colour object, array or `"a,b(,c)"` into named fields */
|
|
121
|
-
export function parseColor(value, names, aliases = {}) {
|
|
122
|
-
let parts;
|
|
123
|
-
if (typeof value === 'string') {
|
|
124
|
-
parts = value.split(/[,;\s]+/).filter((p) => p !== '');
|
|
125
|
-
}
|
|
126
|
-
else if (Array.isArray(value)) {
|
|
127
|
-
parts = value;
|
|
128
|
-
}
|
|
129
|
-
else if (typeof value === 'object' && value !== null) {
|
|
130
|
-
const record = value;
|
|
131
|
-
parts = names.map((name) => {
|
|
132
|
-
if (name in record) {
|
|
133
|
-
return record[name];
|
|
134
|
-
}
|
|
135
|
-
for (const [alias, target] of Object.entries(aliases)) {
|
|
136
|
-
if (target === name && alias in record) {
|
|
137
|
-
return record[alias];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return undefined;
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
if (parts.length < names.length) {
|
|
147
|
-
return undefined;
|
|
148
|
-
}
|
|
149
|
-
const numbers = parts.slice(0, names.length).map((p) => (typeof p === 'number' ? p : Number(p)));
|
|
150
|
-
return numbers.every((n) => Number.isFinite(n)) ? numbers : undefined;
|
|
151
|
-
}
|
|
12
|
+
/** CurrentX/CurrentY = x/y × 65536, at most 65279 (0xFEFF): Matter 1.4 ColorControl, CurrentX/CurrentY */
|
|
13
|
+
export const xyToMatter = (v) => Math.min(0xfeff, Math.round(clamp(v, 0, 1) * 65536));
|
|
14
|
+
export const xyFromMatter = (v) => Math.round((v / 65536) * 10000) / 10000;
|
|
152
15
|
//# sourceMappingURL=color.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/families/color.ts"],"names":[],"mappings":"AAAA;;
|
|
1
|
+
{"version":3,"file":"color.js","sourceRoot":"","sources":["../../src/families/color.ts"],"names":[],"mappings":"AAAA;;iHAEiH;AAEjH,OAAO,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAGhG,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAU,EAAE,EAAU,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAE3F,iCAAiC;AACjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC;AAC1G,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AAC5F,wCAAwC;AACxC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;AACjG,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACnG,0GAA0G;AAC1G,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AACtG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function areaTag(name: string): {
|
|
3
|
-
name: string;
|
|
4
|
-
id: number;
|
|
5
|
-
} | undefined;
|
|
6
|
-
export declare const AREA_TAGS: Readonly<Record<string, number>>;
|
|
1
|
+
export { areaTag, AREA_TAGS } from 'mqtt-ha-entities';
|
|
@@ -1,279 +1,6 @@
|
|
|
1
|
-
/* Home Assistant's `suggested_area` onto Matter's Common Area semantic tags (namespace 0x10
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const TAGS = {
|
|
7
|
-
Aisle: 0,
|
|
8
|
-
Attic: 1,
|
|
9
|
-
BackDoor: 2,
|
|
10
|
-
BackYard: 3,
|
|
11
|
-
Balcony: 4,
|
|
12
|
-
Ballroom: 5,
|
|
13
|
-
Bathroom: 6,
|
|
14
|
-
Bedroom: 7,
|
|
15
|
-
Border: 8,
|
|
16
|
-
Boxroom: 9,
|
|
17
|
-
BreakfastRoom: 10,
|
|
18
|
-
Carport: 11,
|
|
19
|
-
Cellar: 12,
|
|
20
|
-
Cloakroom: 13,
|
|
21
|
-
Closet: 14,
|
|
22
|
-
Conservatory: 15,
|
|
23
|
-
Corridor: 16,
|
|
24
|
-
CraftRoom: 17,
|
|
25
|
-
Cupboard: 18,
|
|
26
|
-
Deck: 19,
|
|
27
|
-
Den: 20,
|
|
28
|
-
Dining: 21,
|
|
29
|
-
DrawingRoom: 22,
|
|
30
|
-
DressingRoom: 23,
|
|
31
|
-
Driveway: 24,
|
|
32
|
-
Elevator: 25,
|
|
33
|
-
Ensuite: 26,
|
|
34
|
-
Entrance: 27,
|
|
35
|
-
Entryway: 28,
|
|
36
|
-
FamilyRoom: 29,
|
|
37
|
-
Foyer: 30,
|
|
38
|
-
FrontDoor: 31,
|
|
39
|
-
FrontYard: 32,
|
|
40
|
-
GameRoom: 33,
|
|
41
|
-
Garage: 34,
|
|
42
|
-
GarageDoor: 35,
|
|
43
|
-
Garden: 36,
|
|
44
|
-
GardenDoor: 37,
|
|
45
|
-
GuestBathroom: 38,
|
|
46
|
-
GuestBedroom: 39,
|
|
47
|
-
GuestRoom: 41,
|
|
48
|
-
Gym: 42,
|
|
49
|
-
Hallway: 43,
|
|
50
|
-
HearthRoom: 44,
|
|
51
|
-
KidsRoom: 45,
|
|
52
|
-
KidsBedroom: 46,
|
|
53
|
-
Kitchen: 47,
|
|
54
|
-
LaundryRoom: 49,
|
|
55
|
-
Lawn: 50,
|
|
56
|
-
Library: 51,
|
|
57
|
-
LivingRoom: 52,
|
|
58
|
-
Lounge: 53,
|
|
59
|
-
MediaTvRoom: 54,
|
|
60
|
-
MudRoom: 55,
|
|
61
|
-
MusicRoom: 56,
|
|
62
|
-
Nursery: 57,
|
|
63
|
-
Office: 58,
|
|
64
|
-
OutdoorKitchen: 59,
|
|
65
|
-
Outside: 60,
|
|
66
|
-
Pantry: 61,
|
|
67
|
-
ParkingLot: 62,
|
|
68
|
-
Parlor: 63,
|
|
69
|
-
Patio: 64,
|
|
70
|
-
PlayRoom: 65,
|
|
71
|
-
PoolRoom: 66,
|
|
72
|
-
Porch: 67,
|
|
73
|
-
PrimaryBathroom: 68,
|
|
74
|
-
PrimaryBedroom: 69,
|
|
75
|
-
Ramp: 70,
|
|
76
|
-
ReceptionRoom: 71,
|
|
77
|
-
RecreationRoom: 72,
|
|
78
|
-
Roof: 74,
|
|
79
|
-
Sauna: 75,
|
|
80
|
-
Scullery: 76,
|
|
81
|
-
SewingRoom: 77,
|
|
82
|
-
Shed: 78,
|
|
83
|
-
SideDoor: 79,
|
|
84
|
-
SideYard: 80,
|
|
85
|
-
SittingRoom: 81,
|
|
86
|
-
Snug: 82,
|
|
87
|
-
Spa: 83,
|
|
88
|
-
Staircase: 84,
|
|
89
|
-
SteamRoom: 85,
|
|
90
|
-
StorageRoom: 86,
|
|
91
|
-
Studio: 87,
|
|
92
|
-
Study: 88,
|
|
93
|
-
SunRoom: 89,
|
|
94
|
-
SwimmingPool: 90,
|
|
95
|
-
Terrace: 91,
|
|
96
|
-
UtilityRoom: 92,
|
|
97
|
-
Ward: 93,
|
|
98
|
-
Workshop: 94,
|
|
99
|
-
Toilet: 95,
|
|
100
|
-
};
|
|
101
|
-
/** other spellings and German names, normalised (lower case, no spaces, no umlaut dots) */
|
|
102
|
-
const SYNONYMS = {
|
|
103
|
-
livingroom: 'LivingRoom',
|
|
104
|
-
wohnzimmer: 'LivingRoom',
|
|
105
|
-
wohnen: 'LivingRoom',
|
|
106
|
-
kitchen: 'Kitchen',
|
|
107
|
-
kuche: 'Kitchen',
|
|
108
|
-
kueche: 'Kitchen',
|
|
109
|
-
bedroom: 'Bedroom',
|
|
110
|
-
schlafzimmer: 'Bedroom',
|
|
111
|
-
schlafen: 'Bedroom',
|
|
112
|
-
bathroom: 'Bathroom',
|
|
113
|
-
bad: 'Bathroom',
|
|
114
|
-
badezimmer: 'Bathroom',
|
|
115
|
-
restroom: 'Bathroom',
|
|
116
|
-
gastebad: 'GuestBathroom',
|
|
117
|
-
gaestebad: 'GuestBathroom',
|
|
118
|
-
gastezimmer: 'GuestRoom',
|
|
119
|
-
gaestezimmer: 'GuestRoom',
|
|
120
|
-
gastewc: 'Toilet',
|
|
121
|
-
gaestewc: 'Toilet',
|
|
122
|
-
wc: 'Toilet',
|
|
123
|
-
toilette: 'Toilet',
|
|
124
|
-
hallway: 'Hallway',
|
|
125
|
-
flur: 'Hallway',
|
|
126
|
-
diele: 'Hallway',
|
|
127
|
-
corridor: 'Corridor',
|
|
128
|
-
gang: 'Corridor',
|
|
129
|
-
office: 'Office',
|
|
130
|
-
buro: 'Office',
|
|
131
|
-
buero: 'Office',
|
|
132
|
-
arbeitszimmer: 'Office',
|
|
133
|
-
study: 'Study',
|
|
134
|
-
kidsroom: 'KidsRoom',
|
|
135
|
-
kinderzimmer: 'KidsRoom',
|
|
136
|
-
nursery: 'Nursery',
|
|
137
|
-
babyzimmer: 'Nursery',
|
|
138
|
-
garage: 'Garage',
|
|
139
|
-
garden: 'Garden',
|
|
140
|
-
garten: 'Garden',
|
|
141
|
-
yard: 'BackYard',
|
|
142
|
-
hof: 'BackYard',
|
|
143
|
-
cellar: 'Cellar',
|
|
144
|
-
basement: 'Cellar',
|
|
145
|
-
keller: 'Cellar',
|
|
146
|
-
attic: 'Attic',
|
|
147
|
-
dachboden: 'Attic',
|
|
148
|
-
speicher: 'Attic',
|
|
149
|
-
balcony: 'Balcony',
|
|
150
|
-
balkon: 'Balcony',
|
|
151
|
-
terrace: 'Terrace',
|
|
152
|
-
terrasse: 'Terrace',
|
|
153
|
-
patio: 'Patio',
|
|
154
|
-
dining: 'Dining',
|
|
155
|
-
diningroom: 'Dining',
|
|
156
|
-
esszimmer: 'Dining',
|
|
157
|
-
laundry: 'LaundryRoom',
|
|
158
|
-
laundryroom: 'LaundryRoom',
|
|
159
|
-
waschkuche: 'LaundryRoom',
|
|
160
|
-
waschkueche: 'LaundryRoom',
|
|
161
|
-
hauswirtschaftsraum: 'UtilityRoom',
|
|
162
|
-
hwr: 'UtilityRoom',
|
|
163
|
-
utility: 'UtilityRoom',
|
|
164
|
-
utilityroom: 'UtilityRoom',
|
|
165
|
-
pantry: 'Pantry',
|
|
166
|
-
vorratskammer: 'Pantry',
|
|
167
|
-
speisekammer: 'Pantry',
|
|
168
|
-
storage: 'StorageRoom',
|
|
169
|
-
storageroom: 'StorageRoom',
|
|
170
|
-
abstellraum: 'StorageRoom',
|
|
171
|
-
abstellkammer: 'StorageRoom',
|
|
172
|
-
closet: 'Closet',
|
|
173
|
-
kleiderschrank: 'Closet',
|
|
174
|
-
dressingroom: 'DressingRoom',
|
|
175
|
-
ankleide: 'DressingRoom',
|
|
176
|
-
ankleidezimmer: 'DressingRoom',
|
|
177
|
-
workshop: 'Workshop',
|
|
178
|
-
werkstatt: 'Workshop',
|
|
179
|
-
craftroom: 'CraftRoom',
|
|
180
|
-
bastelraum: 'CraftRoom',
|
|
181
|
-
hobbyraum: 'CraftRoom',
|
|
182
|
-
playroom: 'PlayRoom',
|
|
183
|
-
spielzimmer: 'PlayRoom',
|
|
184
|
-
gameroom: 'GameRoom',
|
|
185
|
-
spielezimmer: 'GameRoom',
|
|
186
|
-
gym: 'Gym',
|
|
187
|
-
fitnessraum: 'Gym',
|
|
188
|
-
sauna: 'Sauna',
|
|
189
|
-
pool: 'SwimmingPool',
|
|
190
|
-
swimmingpool: 'SwimmingPool',
|
|
191
|
-
schwimmbad: 'SwimmingPool',
|
|
192
|
-
entrance: 'Entrance',
|
|
193
|
-
eingang: 'Entrance',
|
|
194
|
-
eingangsbereich: 'Entrance',
|
|
195
|
-
hauseingang: 'Entrance',
|
|
196
|
-
staircase: 'Staircase',
|
|
197
|
-
stairs: 'Staircase',
|
|
198
|
-
treppe: 'Staircase',
|
|
199
|
-
treppenhaus: 'Staircase',
|
|
200
|
-
roof: 'Roof',
|
|
201
|
-
dach: 'Roof',
|
|
202
|
-
shed: 'Shed',
|
|
203
|
-
schuppen: 'Shed',
|
|
204
|
-
gartenhaus: 'Shed',
|
|
205
|
-
carport: 'Carport',
|
|
206
|
-
driveway: 'Driveway',
|
|
207
|
-
einfahrt: 'Driveway',
|
|
208
|
-
outside: 'Outside',
|
|
209
|
-
aussen: 'Outside',
|
|
210
|
-
draussen: 'Outside',
|
|
211
|
-
library: 'Library',
|
|
212
|
-
bibliothek: 'Library',
|
|
213
|
-
musicroom: 'MusicRoom',
|
|
214
|
-
musikzimmer: 'MusicRoom',
|
|
215
|
-
mediaroom: 'MediaTvRoom',
|
|
216
|
-
tvroom: 'MediaTvRoom',
|
|
217
|
-
fernsehzimmer: 'MediaTvRoom',
|
|
218
|
-
heimkino: 'MediaTvRoom',
|
|
219
|
-
lounge: 'Lounge',
|
|
220
|
-
familyroom: 'FamilyRoom',
|
|
221
|
-
frontdoor: 'FrontDoor',
|
|
222
|
-
haustur: 'FrontDoor',
|
|
223
|
-
haustuer: 'FrontDoor',
|
|
224
|
-
backdoor: 'BackDoor',
|
|
225
|
-
hintertur: 'BackDoor',
|
|
226
|
-
hintertuer: 'BackDoor',
|
|
227
|
-
conservatory: 'Conservatory',
|
|
228
|
-
wintergarten: 'Conservatory',
|
|
229
|
-
sunroom: 'SunRoom',
|
|
230
|
-
masterbedroom: 'PrimaryBedroom',
|
|
231
|
-
primarybedroom: 'PrimaryBedroom',
|
|
232
|
-
elternschlafzimmer: 'PrimaryBedroom',
|
|
233
|
-
masterbathroom: 'PrimaryBathroom',
|
|
234
|
-
primarybathroom: 'PrimaryBathroom',
|
|
235
|
-
guestroom: 'GuestRoom',
|
|
236
|
-
guestbedroom: 'GuestBedroom',
|
|
237
|
-
guestbathroom: 'GuestBathroom',
|
|
238
|
-
toilet: 'Toilet',
|
|
239
|
-
spa: 'Spa',
|
|
240
|
-
wellness: 'Spa',
|
|
241
|
-
boxroom: 'Boxroom',
|
|
242
|
-
kammer: 'Boxroom',
|
|
243
|
-
elevator: 'Elevator',
|
|
244
|
-
aufzug: 'Elevator',
|
|
245
|
-
fahrstuhl: 'Elevator',
|
|
246
|
-
studio: 'Studio',
|
|
247
|
-
atelier: 'Studio',
|
|
248
|
-
porch: 'Porch',
|
|
249
|
-
veranda: 'Porch',
|
|
250
|
-
lawn: 'Lawn',
|
|
251
|
-
rasen: 'Lawn',
|
|
252
|
-
parking: 'ParkingLot',
|
|
253
|
-
parkplatz: 'ParkingLot',
|
|
254
|
-
};
|
|
255
|
-
function normalise(name) {
|
|
256
|
-
return name
|
|
257
|
-
.toLowerCase()
|
|
258
|
-
.replace(/ä/g, 'a')
|
|
259
|
-
.replace(/ö/g, 'o')
|
|
260
|
-
.replace(/ü/g, 'u')
|
|
261
|
-
.replace(/ß/g, 'ss')
|
|
262
|
-
.replace(/[^a-z0-9]/g, '');
|
|
263
|
-
}
|
|
264
|
-
const BY_NORMALISED = new Map(Object.keys(TAGS).map((name) => [normalise(name), name]));
|
|
265
|
-
/** the Common Area tag for an area name, or undefined when the name matches none */
|
|
266
|
-
export function areaTag(name) {
|
|
267
|
-
const key = normalise(name);
|
|
268
|
-
if (key === '') {
|
|
269
|
-
return undefined;
|
|
270
|
-
}
|
|
271
|
-
const tagName = BY_NORMALISED.get(key) ?? SYNONYMS[key];
|
|
272
|
-
if (tagName === undefined) {
|
|
273
|
-
return undefined;
|
|
274
|
-
}
|
|
275
|
-
const id = TAGS[tagName];
|
|
276
|
-
return id === undefined ? undefined : { name: tagName, id };
|
|
277
|
-
}
|
|
278
|
-
export const AREA_TAGS = TAGS;
|
|
1
|
+
/* Home Assistant's `suggested_area` onto Matter's Common Area semantic tags (namespace 0x10): a name that
|
|
2
|
+
matches a tag — in English or German — becomes a Descriptor tag on the device's own endpoint; any other
|
|
3
|
+
name is only carried in the discovery report. The table lives in mqtt-ha-entities;
|
|
4
|
+
test/ha-areas.test.ts checks its ids against matter.js. */
|
|
5
|
+
export { areaTag, AREA_TAGS } from 'mqtt-ha-entities';
|
|
279
6
|
//# sourceMappingURL=areas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"areas.js","sourceRoot":"","sources":["../../../src/importers/ha/areas.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"areas.js","sourceRoot":"","sources":["../../../src/importers/ha/areas.ts"],"names":[],"mappings":"AAAA;;;6DAG6D;AAE7D,OAAO,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,kBAAkB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DEFAULT_PREFIX } from 'mqtt-ha-entities';
|
|
1
2
|
import type { TopicCache } from '../../mqtt/index.ts';
|
|
2
3
|
import { type Discovery } from './sync.ts';
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
4
|
+
import type { DeviceInfo, EntityConfig, Origin } from './types.ts';
|
|
5
|
+
export { DEFAULT_PREFIX };
|
|
5
6
|
/** one discovered entity: a per-entity config, or one component of a device-based config */
|
|
6
7
|
export interface Entity {
|
|
7
8
|
/** the discovery topic; for a device-based component `<topic>#<component key>` */
|
|
@@ -16,19 +17,20 @@ export interface Entity {
|
|
|
16
17
|
config: EntityConfig;
|
|
17
18
|
}
|
|
18
19
|
export declare class HaSource {
|
|
19
|
-
readonly
|
|
20
|
-
/** entities by id */
|
|
21
|
-
readonly entities: Map<string, Entity>;
|
|
22
|
-
/** the device-based configs by topic, with their component ids, so a new payload replaces all of them */
|
|
23
|
-
private readonly deviceConfigs;
|
|
20
|
+
private readonly store;
|
|
24
21
|
/** a config message (or a removal) was seen: devices missing from the view are orphaned */
|
|
25
22
|
seen: boolean;
|
|
26
23
|
constructor(prefix?: string);
|
|
24
|
+
get prefix(): string;
|
|
25
|
+
/** entities by id */
|
|
26
|
+
get entities(): ReadonlyMap<string, Entity>;
|
|
27
27
|
/** the topics to subscribe */
|
|
28
28
|
get topics(): string[];
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* take a message when its topic is a discovery config; `'entity'`, `'device'` or `'removed'`; throws a
|
|
31
|
+
* `DiscoveryError` on a payload that is not a JSON object (what the topic announced before stays)
|
|
32
|
+
*/
|
|
30
33
|
handle(topic: string, payload: string | Buffer): 'entity' | 'device' | 'removed' | undefined;
|
|
31
|
-
private remove;
|
|
32
34
|
/** take what the cache holds under the prefix; a payload that does not parse is skipped */
|
|
33
35
|
load(cache: TopicCache): string[];
|
|
34
36
|
discover(): Discovery;
|
|
@@ -1,79 +1,38 @@
|
|
|
1
1
|
/* The MQTT side of the Home Assistant discovery importer: every retained `<prefix>/…/config` kept as the
|
|
2
2
|
entity it describes (both discovery forms), an empty payload removing it, and the discovery they yield.
|
|
3
|
-
Feed it messages (`handle`) or the topic cache (`load`); the caller subscribes `<prefix>/#`.
|
|
3
|
+
Feed it messages (`handle`) or the topic cache (`load`); the caller subscribes `<prefix>/#`. Parsing and
|
|
4
|
+
keeping the configs is mqtt-ha-entities' `DiscoveryStore`; what is mqtt2matter's is `seen`, the cache
|
|
5
|
+
and the discovery for the generator. */
|
|
6
|
+
import { DEFAULT_PREFIX, DiscoveryStore, parseDiscoveryTopic } from 'mqtt-ha-entities';
|
|
4
7
|
import { discover } from "./sync.js";
|
|
5
|
-
|
|
6
|
-
export const DEFAULT_PREFIX = 'homeassistant';
|
|
8
|
+
export { DEFAULT_PREFIX };
|
|
7
9
|
export class HaSource {
|
|
8
|
-
|
|
9
|
-
/** entities by id */
|
|
10
|
-
entities = new Map();
|
|
11
|
-
/** the device-based configs by topic, with their component ids, so a new payload replaces all of them */
|
|
12
|
-
deviceConfigs = new Map();
|
|
10
|
+
store;
|
|
13
11
|
/** a config message (or a removal) was seen: devices missing from the view are orphaned */
|
|
14
12
|
seen = false;
|
|
15
13
|
constructor(prefix = DEFAULT_PREFIX) {
|
|
16
|
-
this.
|
|
14
|
+
this.store = new DiscoveryStore({ prefix });
|
|
15
|
+
}
|
|
16
|
+
get prefix() {
|
|
17
|
+
return this.store.prefix;
|
|
18
|
+
}
|
|
19
|
+
/** entities by id */
|
|
20
|
+
get entities() {
|
|
21
|
+
return this.store.entities;
|
|
17
22
|
}
|
|
18
23
|
/** the topics to subscribe */
|
|
19
24
|
get topics() {
|
|
20
|
-
return
|
|
25
|
+
return this.store.subscriptions;
|
|
21
26
|
}
|
|
22
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* take a message when its topic is a discovery config; `'entity'`, `'device'` or `'removed'`; throws a
|
|
29
|
+
* `DiscoveryError` on a payload that is not a JSON object (what the topic announced before stays)
|
|
30
|
+
*/
|
|
23
31
|
handle(topic, payload) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const text = typeof payload === 'string' ? payload : payload.toString('utf8');
|
|
29
|
-
this.seen = true;
|
|
30
|
-
if (text.trim() === '') {
|
|
31
|
-
this.remove(topic);
|
|
32
|
-
return 'removed';
|
|
33
|
-
}
|
|
34
|
-
const json = JSON.parse(text);
|
|
35
|
-
if (typeof json !== 'object' || json === null || Array.isArray(json)) {
|
|
36
|
-
throw new Error(`${topic}: the discovery payload is not an object`);
|
|
37
|
-
}
|
|
38
|
-
const raw = json;
|
|
39
|
-
if (parsed.component === 'device') {
|
|
40
|
-
this.remove(topic);
|
|
41
|
-
const { components } = expandDevicePayload(raw);
|
|
42
|
-
const ids = [];
|
|
43
|
-
for (const [key, config] of Object.entries(components)) {
|
|
44
|
-
if (typeof config.platform !== 'string' || config.platform === '') {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const id = `${topic}#${key}`;
|
|
48
|
-
ids.push(id);
|
|
49
|
-
this.entities.set(id, {
|
|
50
|
-
id,
|
|
51
|
-
topic,
|
|
52
|
-
component: config.platform,
|
|
53
|
-
objectId: key,
|
|
54
|
-
...(parsed.nodeId === undefined ? {} : { nodeId: parsed.nodeId }),
|
|
55
|
-
config,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
this.deviceConfigs.set(topic, ids);
|
|
59
|
-
return 'device';
|
|
60
|
-
}
|
|
61
|
-
this.entities.set(topic, {
|
|
62
|
-
id: topic,
|
|
63
|
-
topic,
|
|
64
|
-
component: parsed.component,
|
|
65
|
-
objectId: parsed.objectId,
|
|
66
|
-
...(parsed.nodeId === undefined ? {} : { nodeId: parsed.nodeId }),
|
|
67
|
-
config: expandEntity(raw),
|
|
68
|
-
});
|
|
69
|
-
return 'entity';
|
|
70
|
-
}
|
|
71
|
-
remove(topic) {
|
|
72
|
-
this.entities.delete(topic);
|
|
73
|
-
for (const id of this.deviceConfigs.get(topic) ?? []) {
|
|
74
|
-
this.entities.delete(id);
|
|
32
|
+
if (parseDiscoveryTopic(this.prefix, topic) !== undefined) {
|
|
33
|
+
this.seen = true;
|
|
75
34
|
}
|
|
76
|
-
this.
|
|
35
|
+
return this.store.handle(topic, payload);
|
|
77
36
|
}
|
|
78
37
|
/** take what the cache holds under the prefix; a payload that does not parse is skipped */
|
|
79
38
|
load(cache) {
|