@raineworks/ha-dashboards 0.0.0-stage → 1.1.1

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/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @raineworks/ha-dashboards
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What a house's own Home Assistant config repository needs from [Raineworks Dashboards](https://github.com/raine-works/ha-dashboards),
4
+ released with the integration, the same version.
5
+
6
+ - **`@raineworks/ha-dashboards/house`**: `parseHouseConfig()` (the parser the dashboards read a card's `house`
7
+ option with, so a test can check `house.yaml` loses nothing to it), `mergeHouseSources()`, and the bedtime
8
+ routines (`HOME_ROUTINE`, `BEDTIME_STEP_KINDS`), to check a house's bedtime automations against.
9
+ - **`raineworks-dashboards-mcp`**: the setup MCP server (stdio), for an AI assistant to check and set up the
10
+ dashboards on a Home Assistant. It reads `HA_URL` and `HA_TOKEN` (an administrator's long-lived token) from the
11
+ environment or the `.env` of the folder it's run in. In an MCP client's config:
12
+
13
+ ```json
14
+ { "command": "bunx", "args": ["--bun", "raineworks-dashboards-mcp"] }
15
+ ```
16
+
17
+ Needs [Bun](https://bun.sh) 1.4.5 or later. Pin it to an exact version.
package/dist/house.js ADDED
@@ -0,0 +1,461 @@
1
+ // @bun
2
+ // ../ui/src/lib/house-config.ts
3
+ var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
4
+ var text = (value) => typeof value === "string" && value.trim() ? value.trim() : undefined;
5
+ var entityOf = (value, domain) => {
6
+ const id = text(value);
7
+ if (!id || !/^[a-z_]+\.[a-z0-9_]+$/.test(id))
8
+ return;
9
+ return !domain || id.startsWith(`${domain}.`) ? id : undefined;
10
+ };
11
+ var list = (value) => Array.isArray(value) ? value : [];
12
+ function appliance(value, name) {
13
+ if (!isObject(value))
14
+ return;
15
+ const machineState = entityOf(value.machine_state, "sensor");
16
+ const jobState = entityOf(value.job_state, "sensor");
17
+ const timeRemaining = entityOf(value.time_remaining, "sensor");
18
+ if (!machineState || !jobState || !timeRemaining)
19
+ return;
20
+ return { name: text(value.name) ?? name, machineState, jobState, timeRemaining };
21
+ }
22
+ function routine(value) {
23
+ if (!isObject(value))
24
+ return;
25
+ const zone = text(value.zone);
26
+ if (!zone)
27
+ return;
28
+ const steps = list(value.steps).flatMap((step) => {
29
+ if (!isObject(step))
30
+ return [];
31
+ const kind = text(step.kind);
32
+ const line = text(step.text);
33
+ if (!kind || !BEDTIME_STEP_KINDS.includes(kind) || !line)
34
+ return [];
35
+ const actions = list(step.actions).filter((a) => typeof a === "string");
36
+ return [{ kind, text: line, actions }];
37
+ });
38
+ return { zone, steps };
39
+ }
40
+ function parseHouseConfig(raw) {
41
+ const config = isObject(raw) ? raw : {};
42
+ const tts = isObject(config.tts) ? config.tts : {};
43
+ const laundry = isObject(config.laundry) ? config.laundry : {};
44
+ const thermostats = list(config.thermostats).flatMap((zone) => {
45
+ const entityId = entityOf(isObject(zone) ? zone.entity : zone, "climate");
46
+ return entityId ? [{ entityId, name: isObject(zone) ? text(zone.name) : undefined }] : [];
47
+ });
48
+ const routines = {};
49
+ if (isObject(config.bedtime_routines))
50
+ for (const [toggle, value] of Object.entries(config.bedtime_routines)) {
51
+ const parsed = (entityOf(toggle, "switch") || entityOf(toggle, "input_boolean")) && routine(value);
52
+ if (parsed)
53
+ routines[toggle] = parsed;
54
+ }
55
+ return {
56
+ announceSpeaker: entityOf(config.announce_speaker, "media_player"),
57
+ weather: entityOf(config.weather, "weather"),
58
+ alarmPanel: entityOf(config.alarm_panel, "alarm_control_panel"),
59
+ thermostats: thermostats.length ? thermostats : undefined,
60
+ laundry: { washer: appliance(laundry.washer, "Washer"), dryer: appliance(laundry.dryer, "Dryer") },
61
+ guestWifiQr: entityOf(config.guest_wifi_qr, "image"),
62
+ liveInputs: list(config.live_inputs).flatMap((input) => {
63
+ if (!isObject(input))
64
+ return [];
65
+ const name = text(input.name);
66
+ const uri = text(input.uri);
67
+ return name && uri ? [{ name, uri, signal: entityOf(input.signal, "binary_sensor") }] : [];
68
+ }),
69
+ tts: {
70
+ engine: entityOf(tts.engine, "tts"),
71
+ voice: text(tts.voice),
72
+ streaming: tts.streaming === true,
73
+ fallback: entityOf(tts.fallback, "tts")
74
+ },
75
+ birthdayCalendar: entityOf(config.birthday_calendar, "calendar"),
76
+ bedtimeRoutines: routines,
77
+ modules: isObject(config.modules) ? Object.fromEntries(Object.entries(config.modules).filter((entry) => typeof entry[1] === "boolean")) : {}
78
+ };
79
+ }
80
+ var current = parseHouseConfig(undefined);
81
+ var listeners = new Set;
82
+ function mergeHouseSources(integration, card) {
83
+ return { ...isObject(integration) ? integration : {}, ...isObject(card) ? card : {} };
84
+ }
85
+
86
+ // ../ui/src/lib/household.ts
87
+ var members = null;
88
+ var hasTracker = (person) => Array.isArray(person.attributes.device_trackers) && person.attributes.device_trackers.length > 0;
89
+ function isHouseholdMember(person) {
90
+ if (!person?.entity_id.startsWith("person."))
91
+ return false;
92
+ return members ? members.has(person.entity_id) : hasTracker(person);
93
+ }
94
+
95
+ // ../ui/src/lib/values.ts
96
+ var trimmedString = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
97
+
98
+ // ../ui/src/lib/lights.ts
99
+ var HOUSEHOLD_LIGHT_LABEL = "household_light";
100
+ var COLOR_MODES = new Set(["hs", "xy", "rgb", "rgbw", "rgbww", "color_temp"]);
101
+ var NO_EFFECT = new Set(["", "off", "none", "solid", "unknown"]);
102
+ var RGB_MODES = new Set(["hs", "xy", "rgb", "rgbw", "rgbww"]);
103
+ function entityArea(hass, entityId) {
104
+ const entry = hass.entities?.[entityId];
105
+ if (entry?.area_id)
106
+ return entry.area_id;
107
+ const device = entry?.device_id ? hass.devices?.[entry.device_id] : undefined;
108
+ return device?.area_id ?? undefined;
109
+ }
110
+
111
+ // ../ui/src/lib/labels.ts
112
+ var labelsInUse = new WeakMap;
113
+ function labelInUse(entities, label) {
114
+ if (!entities)
115
+ return false;
116
+ let used = labelsInUse.get(entities);
117
+ if (!used) {
118
+ used = new Set(Object.values(entities).flatMap((e) => e.labels ?? []));
119
+ labelsInUse.set(entities, used);
120
+ }
121
+ return used.has(label);
122
+ }
123
+
124
+ // ../ui/src/lib/service-calls.ts
125
+ var RUN_DOMAINS = new Set(["script", "scene", "automation"]);
126
+
127
+ // ../ui/src/lib/music.ts
128
+ var MEDIA_FEATURE = {
129
+ PAUSE: 1,
130
+ SEEK: 2,
131
+ VOLUME_SET: 4,
132
+ VOLUME_MUTE: 8,
133
+ PREVIOUS_TRACK: 16,
134
+ NEXT_TRACK: 32,
135
+ PLAY_MEDIA: 512,
136
+ CLEAR_PLAYLIST: 8192,
137
+ PLAY: 16384,
138
+ SHUFFLE_SET: 32768,
139
+ REPEAT_SET: 262144,
140
+ GROUPING: 524288
141
+ };
142
+ var TV_AUDIO_FEATURES = MEDIA_FEATURE.VOLUME_SET | MEDIA_FEATURE.VOLUME_MUTE | MEDIA_FEATURE.GROUPING;
143
+ var QUEUE_ONLY_FEATURES = MEDIA_FEATURE.PAUSE | MEDIA_FEATURE.SEEK | MEDIA_FEATURE.PREVIOUS_TRACK | MEDIA_FEATURE.NEXT_TRACK | MEDIA_FEATURE.CLEAR_PLAYLIST | MEDIA_FEATURE.SHUFFLE_SET | MEDIA_FEATURE.REPEAT_SET;
144
+ var STATES = new Set(["playing", "paused", "idle", "off"]);
145
+ var PAUSED_INDICATOR_MS = 60 * 60 * 1000;
146
+ var MEDIA_TYPES = new Set(["artist", "album", "track", "playlist", "radio", "podcast"]);
147
+
148
+ // ../ui/src/lib/people.ts
149
+ var num = (value) => {
150
+ const n = typeof value === "number" ? value : Number.parseFloat(String(value));
151
+ return Number.isFinite(n) ? n : null;
152
+ };
153
+ function initialsFor(name) {
154
+ const words = name.trim().split(/\s+/).filter(Boolean);
155
+ if (words.length === 0)
156
+ return "?";
157
+ return (words.length === 1 ? words[0].slice(0, 2) : `${words[0][0]}${words[words.length - 1][0]}`).toUpperCase();
158
+ }
159
+ function haversineMeters(lat1, lon1, lat2, lon2) {
160
+ const toRad = (d) => d * Math.PI / 180;
161
+ const dLat = toRad(lat2 - lat1);
162
+ const dLon = toRad(lon2 - lon1);
163
+ const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
164
+ return 2 * 6371000 * Math.asin(Math.sqrt(a));
165
+ }
166
+ function batteryForTracker(trackerId, states) {
167
+ if (!trackerId)
168
+ return null;
169
+ const device = trackerId.split(".")[1];
170
+ const tracker = states[trackerId];
171
+ const level = num(states[`sensor.${device}_battery_level`]?.state) ?? num(tracker?.attributes.battery_level);
172
+ if (level == null)
173
+ return null;
174
+ const rawState = states[`sensor.${device}_battery_state`]?.state ?? tracker?.attributes.battery_status;
175
+ const batteryState = String(rawState ?? "").toLowerCase().replace(/[\s-]+/g, "_");
176
+ const full = batteryState === "full";
177
+ const charging = batteryState === "charging" || full && states[`sensor.${device}_charger_type`]?.state !== "none";
178
+ return { level: Math.round(level), charging, full };
179
+ }
180
+ function zoneFor(person, states) {
181
+ const zoneName = (z) => z.attributes.friendly_name ?? z.entity_id.split(".")[1];
182
+ const inZones = (Array.isArray(person.attributes.in_zones) ? person.attributes.in_zones : []).map((id) => states[String(id)]).filter((z) => Boolean(z)).sort((a, b) => (num(a.attributes.radius) ?? 0) - (num(b.attributes.radius) ?? 0));
183
+ if (inZones[0])
184
+ return { entityId: inZones[0].entity_id, name: zoneName(inZones[0]) };
185
+ if (person.state === "home")
186
+ return { entityId: "zone.home", name: "Home" };
187
+ if (["not_home", "unknown", "unavailable"].includes(person.state))
188
+ return null;
189
+ const byName = Object.values(states).find((s) => s.entity_id.startsWith("zone.") && zoneName(s).toLowerCase() === person.state.toLowerCase());
190
+ return { entityId: byName?.entity_id ?? "", name: byName ? zoneName(byName) : person.state };
191
+ }
192
+ function getPersonView(person, states) {
193
+ const name = person.attributes.friendly_name ?? person.entity_id.split(".")[1];
194
+ const trackers = Array.isArray(person.attributes.device_trackers) ? person.attributes.device_trackers : [];
195
+ const source = typeof person.attributes.source === "string" ? person.attributes.source : String(trackers[0] ?? "");
196
+ const zone = zoneFor(person, states);
197
+ const isHome = person.state === "home";
198
+ const latitude = num(person.attributes.latitude);
199
+ const longitude = num(person.attributes.longitude);
200
+ const home = states["zone.home"];
201
+ const homeLat = num(home?.attributes.latitude);
202
+ const homeLon = num(home?.attributes.longitude);
203
+ const distanceFromHome = latitude != null && longitude != null && homeLat != null && homeLon != null ? haversineMeters(homeLat, homeLon, latitude, longitude) : null;
204
+ let locationLabel = "Unknown";
205
+ if (zone)
206
+ locationLabel = zone.name;
207
+ else if (person.state === "not_home")
208
+ locationLabel = "Away";
209
+ return {
210
+ entityId: person.entity_id,
211
+ name,
212
+ shortName: name.split(/\s+/)[0] ?? name,
213
+ initials: initialsFor(name),
214
+ picture: person.attributes.entity_picture,
215
+ isHome,
216
+ zone,
217
+ locationLabel,
218
+ latitude,
219
+ longitude,
220
+ distanceFromHome,
221
+ battery: batteryForTracker(source || undefined, states),
222
+ updated: states[source]?.last_updated ?? person.last_updated
223
+ };
224
+ }
225
+ function discoverPeople(states) {
226
+ return Object.values(states).filter(isHouseholdMember).map((s) => getPersonView(s, states)).sort((a, b) => a.name.localeCompare(b.name));
227
+ }
228
+ var GEOCODE_RETRY_MS = 5 * 60000;
229
+ var placeCache = new Map;
230
+ var queue = Promise.resolve();
231
+
232
+ // ../ui/src/lib/text.ts
233
+ var MINOR_WORDS = new Set([
234
+ "a",
235
+ "an",
236
+ "and",
237
+ "as",
238
+ "at",
239
+ "but",
240
+ "by",
241
+ "for",
242
+ "in",
243
+ "nor",
244
+ "of",
245
+ "on",
246
+ "or",
247
+ "the",
248
+ "to",
249
+ "via",
250
+ "vs"
251
+ ]);
252
+
253
+ // ../ui/src/lib/tv.ts
254
+ var TV_PLATFORM = "googletv";
255
+ var CONSOLE_KINDS = new Set([
256
+ "xbox",
257
+ "playstation",
258
+ "nintendo_switch",
259
+ "nintendo_wii",
260
+ "steam",
261
+ "console"
262
+ ]);
263
+ var FEATURED_APPS = [
264
+ ["com.google.android.youtube.tv"],
265
+ ["com.google.android.youtube.tvunplugged"],
266
+ ["com.netflix.ninja"],
267
+ ["com.amazon.amazonvideo.livingroom"],
268
+ ["com.apple.atve.androidtv.appletv", "com.apple.atve.sony.appletv"],
269
+ ["com.wbd.stream"],
270
+ ["com.hulu.livingroomplus"],
271
+ ["com.disney.disneyplus"]
272
+ ];
273
+ var featuredRank = (app) => {
274
+ const rank = FEATURED_APPS.findIndex((packages) => packages.includes(app.packageName));
275
+ return rank < 0 ? FEATURED_APPS.length : rank;
276
+ };
277
+ var INPUT_APPS = new Set(["com.tcl.tv", "com.sony.dtv.tvx", "com.google.android.tv"]);
278
+ var launcherApp = (app) => !INPUT_APPS.has(app.packageName) && app.name !== app.packageName;
279
+ var OTHER_APPS = {
280
+ "com.google.android.apps.tv.launcherx": "Home screen",
281
+ "com.google.android.tvlauncher": "Home screen",
282
+ "com.google.android.apps.tv.dreamx": "Screensaver",
283
+ "com.google.android.apps.mediashell": "Casting"
284
+ };
285
+ var ACTIVITIES = new Set(["off", "screensaver", "home", "app", "playing", "paused", "input"]);
286
+ function siblingOf(tv, domain, suffix, states, registries) {
287
+ const entities = registries?.entities;
288
+ const deviceId = entities?.[tv.entity_id]?.device_id;
289
+ if (deviceId && entities) {
290
+ const sameDevice = Object.values(entities).find((e) => e.device_id === deviceId && e.entity_id.startsWith(`${domain}.`) && e.entity_id.endsWith(suffix) && (e.entity_id in states));
291
+ if (sameDevice)
292
+ return sameDevice.entity_id;
293
+ }
294
+ const byName = `${domain}.${tv.entity_id.slice("media_player.".length)}${suffix}`;
295
+ return byName in states ? byName : undefined;
296
+ }
297
+ var remoteFor = (tv, states, registries) => siblingOf(tv, "remote", "", states, registries);
298
+ var activityFor = (tv, states, registries) => siblingOf(tv, "sensor", "_activity", states, registries);
299
+ var TV_FEATURE = {
300
+ ...MEDIA_FEATURE,
301
+ TURN_ON: 128,
302
+ TURN_OFF: 256,
303
+ VOLUME_STEP: 1024,
304
+ SELECT_SOURCE: 2048
305
+ };
306
+ function toApps(value) {
307
+ if (!Array.isArray(value))
308
+ return [];
309
+ return value.map((item) => {
310
+ const a = item;
311
+ const packageName = trimmedString(a?.package);
312
+ if (!packageName)
313
+ return;
314
+ return { packageName, name: trimmedString(a.name) ?? packageName, icon: trimmedString(a.icon) };
315
+ }).filter((app) => !!app && launcherApp(app)).sort((a, b) => featuredRank(a) - featuredRank(b) || a.name.localeCompare(b.name));
316
+ }
317
+ function toInputs(value) {
318
+ if (!Array.isArray(value))
319
+ return [];
320
+ return value.map((item) => {
321
+ const i = item;
322
+ const id = trimmedString(i?.id);
323
+ if (!id)
324
+ return;
325
+ const port = typeof i.port === "number" ? i.port : 0;
326
+ return {
327
+ id,
328
+ label: trimmedString(i.name) ?? (port ? `HDMI ${port}` : id),
329
+ port,
330
+ kind: trimmedString(i.kind) ?? "hdmi",
331
+ device: trimmedString(i.device)
332
+ };
333
+ }).filter((input) => !!input).sort((a, b) => a.port - b.port);
334
+ }
335
+ function toNowPlaying(entity) {
336
+ if (entity.state !== "playing" && entity.state !== "paused")
337
+ return;
338
+ const a = entity.attributes;
339
+ const title = trimmedString(a.media_title);
340
+ if (!title)
341
+ return;
342
+ return {
343
+ state: entity.state,
344
+ title,
345
+ subtitle: trimmedString(a.media_artist),
346
+ artwork: trimmedString(a.entity_picture)
347
+ };
348
+ }
349
+ function toTv(entity, activityState) {
350
+ const a = entity.attributes;
351
+ const state = entity.state === "unavailable" ? "unavailable" : entity.state === "off" ? "off" : "on";
352
+ const on = state === "on";
353
+ const apps = toApps(a.apps);
354
+ const inputs = toInputs(a.inputs);
355
+ const appId = on ? trimmedString(a.app_id) : undefined;
356
+ const input = on ? inputs.find((i) => i.id === a.input) : undefined;
357
+ const app = appId ? apps.find((x) => x.packageName === appId) : undefined;
358
+ const reported = trimmedString(a.app_name);
359
+ const activity = activityState && ACTIVITIES.has(activityState) ? activityState : undefined;
360
+ const appName = !on ? undefined : input ? input.label : activity === "screensaver" ? "Screensaver" : activity === "home" ? "Home screen" : app?.name ?? (appId && OTHER_APPS[appId]) ?? (reported && reported !== appId ? reported : undefined) ?? appId;
361
+ return {
362
+ entityId: entity.entity_id,
363
+ name: trimmedString(a.friendly_name) ?? entity.entity_id,
364
+ state,
365
+ activity,
366
+ appId,
367
+ appName,
368
+ app: input ? undefined : app,
369
+ apps,
370
+ inputs,
371
+ input,
372
+ nowPlaying: on && !input ? toNowPlaying(entity) : undefined,
373
+ volume: on && typeof a.volume_level === "number" ? Math.round(a.volume_level * 100) : undefined,
374
+ muted: on && a.is_volume_muted === true,
375
+ features: typeof a.supported_features === "number" ? a.supported_features : 0
376
+ };
377
+ }
378
+ var TV_LABEL = "household_tv";
379
+ function discoverTvs(states, registries) {
380
+ const registry = registries?.entities;
381
+ const labeled = labelInUse(registry, TV_LABEL);
382
+ return Object.values(states).filter((s) => {
383
+ if (!s.entity_id.startsWith("media_player.") || s.attributes.device_class !== "tv")
384
+ return false;
385
+ if (s.attributes.mass_player_type != null)
386
+ return false;
387
+ if (!registry)
388
+ return true;
389
+ const entry = registry[s.entity_id];
390
+ if (labeled && !entry?.labels?.includes(TV_LABEL))
391
+ return false;
392
+ return entry?.platform === TV_PLATFORM && !entry.hidden;
393
+ }).map((s) => {
394
+ const activity = activityFor(s, states, registries);
395
+ return {
396
+ ...toTv(s, activity ? states[activity]?.state : undefined),
397
+ remoteEntityId: remoteFor(s, states, registries)
398
+ };
399
+ }).sort((a, b) => a.name.localeCompare(b.name));
400
+ }
401
+
402
+ // ../ui/src/lib/bedtime.ts
403
+ var BEDTIME_LABEL = "bedtime";
404
+ function discoverBedtimeToggles(hass) {
405
+ const byArea = {};
406
+ for (const entry of Object.values(hass.entities ?? {})) {
407
+ const isSwitch = entry.entity_id.startsWith("switch.");
408
+ if (!(isSwitch || entry.entity_id.startsWith("input_boolean.")) || entry.hidden)
409
+ continue;
410
+ if (!entry.labels?.includes(BEDTIME_LABEL))
411
+ continue;
412
+ const areaId = entityArea(hass, entry.entity_id);
413
+ if (!areaId)
414
+ continue;
415
+ if (!byArea[areaId] || isSwitch && !byArea[areaId].startsWith("switch."))
416
+ byArea[areaId] = entry.entity_id;
417
+ }
418
+ return byArea;
419
+ }
420
+ var BEDTIME_STEP_KINDS = [
421
+ "rooms",
422
+ "lights",
423
+ "media",
424
+ "speaker",
425
+ "fan",
426
+ "covers",
427
+ "locks",
428
+ "climate",
429
+ "alert",
430
+ "panels"
431
+ ];
432
+ var HOME_ROUTINE = {
433
+ zone: "The whole house",
434
+ steps: [
435
+ { kind: "rooms", text: "Puts every room still awake to bed, each with its own routine", actions: [] },
436
+ {
437
+ kind: "lights",
438
+ text: "Turns off every household light and TV, and stops the music (not what stays on at bedtime)",
439
+ actions: ["light.turn_off", "media_player.turn_off", "media_player.media_stop"]
440
+ },
441
+ { kind: "covers", text: "Closes every curtain, blind and garage door", actions: ["cover.close_cover"] },
442
+ {
443
+ kind: "locks",
444
+ text: "Locks the outside doors (an open door locks once it closes)",
445
+ actions: ["script.turn_on"]
446
+ },
447
+ { kind: "climate", text: "Sets the thermostats to Sleep", actions: ["input_select.select_option"] },
448
+ {
449
+ kind: "alert",
450
+ text: "A minute later, tells everyone's phones about any door, window or garage still open",
451
+ actions: ["script.notify_people"]
452
+ },
453
+ { kind: "panels", text: "Dims the wall panel lights to 10% until bedtime ends", actions: [] }
454
+ ]
455
+ };
456
+ export {
457
+ BEDTIME_STEP_KINDS,
458
+ HOME_ROUTINE,
459
+ mergeHouseSources,
460
+ parseHouseConfig
461
+ };