@raineworks/ha-dashboards 0.0.0-stage → 1.1.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.
@@ -0,0 +1,156 @@
1
+ /**
2
+ * TVs from Raineworks TV: discovery, each TV's state (its apps, inputs, what's playing, volume), its
3
+ * remote's keys, and the status line.
4
+ *
5
+ * @module
6
+ */
7
+ import type { HassEntity, HomeAssistant } from '../types/homeassistant';
8
+ /**
9
+ * The TVs are Raineworks TV's (`googletv`, [raine-works/ha-googletv](https://github.com/raine-works/ha-googletv)):
10
+ * one `media_player` per TV that knows its apps (with their Google Play icons), its HDMI inputs,
11
+ * what any app is playing (with a poster or cover) and the TV's volume, plus a `remote` and an
12
+ * Activity sensor on the same device.
13
+ */
14
+ export declare const TV_PLATFORM = "googletv";
15
+ /** An app on the TV, as its `apps` attribute lists it. */
16
+ export interface TvApp {
17
+ /** Its package (the TV's `app_id` while it's open), what `play_media` with `app` opens. */
18
+ packageName: string;
19
+ /** Its name ("Netflix"). */
20
+ name: string;
21
+ /** Its Google Play icon (a URL), when the integration found one. */
22
+ icon?: string;
23
+ }
24
+ /** What's plugged into an HDMI input, by the `kind` the integration gives it from the input's name. */
25
+ export type TvInputKind = 'xbox' | 'playstation' | 'nintendo_switch' | 'nintendo_wii' | 'steam' | 'apple_tv' | 'laptop' | 'computer' | 'streamer' | 'cable' | 'disc' | 'audio' | 'camera' | 'console' | 'hdmi';
26
+ /** One of a TV's HDMI inputs. */
27
+ export interface TvInput {
28
+ /** Android TV's input id, what `select_source` takes. */
29
+ id: string;
30
+ /** Its name on the TV ("Xbox"), else "HDMI <port>". */
31
+ label: string;
32
+ /** Its HDMI port (0 when unknown). */
33
+ port: number;
34
+ /** What's plugged in, for its icon. */
35
+ kind: TvInputKind;
36
+ /** The name its device gives itself over HDMI-CEC ("Arc Ultra"). */
37
+ device?: string;
38
+ }
39
+ /** Whether an input is a game console. */
40
+ export declare const isConsoleInput: (input: Pick<TvInput, "kind">) => boolean;
41
+ /** What the TV is doing, from its Activity sensor (`sensor.<tv>_activity`). */
42
+ export type TvActivity = 'off' | 'screensaver' | 'home' | 'app' | 'playing' | 'paused' | 'input';
43
+ /** A TV's power state (anything but off or unavailable counts as on). */
44
+ export type TvState = 'on' | 'off' | 'unavailable';
45
+ /** What an app on the TV is playing (title, show or artist, its poster or cover), as the TV reports it. */
46
+ export interface TvNowPlaying {
47
+ /** Playing or paused. */
48
+ state: 'playing' | 'paused';
49
+ /** The title. */
50
+ title: string;
51
+ /** The show, channel or artist ("FX"). */
52
+ subtitle?: string;
53
+ /** Its poster or cover through Home Assistant's proxy (the app's icon when none was found). */
54
+ artwork?: string;
55
+ }
56
+ /** A TV as the TVs dialog shows it (`toTv`). */
57
+ export interface Tv {
58
+ /** Its `media_player` entity id. */
59
+ entityId: string;
60
+ /** Its friendly name. */
61
+ name: string;
62
+ /** Its power state. */
63
+ state: TvState;
64
+ /** What it's doing, from its Activity sensor. */
65
+ activity?: TvActivity;
66
+ /** The app in front (its package), while on. */
67
+ appId?: string;
68
+ /** What's on by name: the app, the input on screen, "Home screen", "Screensaver". */
69
+ appName?: string;
70
+ /** The app in front, when it's one of the TV's apps (its icon). */
71
+ app?: TvApp;
72
+ /** The launcher: the TV's apps, the featured ones first. */
73
+ apps: TvApp[];
74
+ /** Its HDMI inputs, by port. */
75
+ inputs: TvInput[];
76
+ /** The input on screen, while one is. */
77
+ input?: TvInput;
78
+ /** What an app is playing, while on and not on an input. */
79
+ nowPlaying?: TvNowPlaying;
80
+ /** 0–100. */
81
+ volume?: number;
82
+ /** Muted (false while off). */
83
+ muted: boolean;
84
+ /** Its `TV_FEATURE` bits (test with `tvSupports`). */
85
+ features: number;
86
+ /** The TV's `remote` entity, which sends key presses (`REMOTE_KEYS`; needs ADB). */
87
+ remoteEntityId?: string;
88
+ }
89
+ /** Keys the TV's remote sends (`remote.send_command`): Android key codes without `KEYCODE_`. */
90
+ export declare const REMOTE_KEYS: {
91
+ readonly up: "DPAD_UP";
92
+ readonly down: "DPAD_DOWN";
93
+ readonly left: "DPAD_LEFT";
94
+ readonly right: "DPAD_RIGHT";
95
+ readonly select: "DPAD_CENTER";
96
+ readonly back: "BACK";
97
+ readonly home: "HOME";
98
+ };
99
+ /** A key on the on-screen remote. */
100
+ export type RemoteKey = keyof typeof REMOTE_KEYS;
101
+ /** The TV's `remote` entity. */
102
+ export declare const remoteFor: (tv: HassEntity, states: Record<string, HassEntity>, registries?: Pick<HomeAssistant, "entities">) => string | undefined;
103
+ /** The TV's Activity sensor. */
104
+ export declare const activityFor: (tv: HassEntity, states: Record<string, HassEntity>, registries?: Pick<HomeAssistant, "entities">) => string | undefined;
105
+ /** Feature bits the TV reports (it sets and steps volume, opens apps and inputs as sources). */
106
+ export declare const TV_FEATURE: {
107
+ readonly TURN_ON: 128;
108
+ readonly TURN_OFF: 256;
109
+ readonly VOLUME_STEP: 1024;
110
+ readonly SELECT_SOURCE: 2048;
111
+ readonly PAUSE: 1;
112
+ readonly SEEK: 2;
113
+ readonly VOLUME_SET: 4;
114
+ readonly VOLUME_MUTE: 8;
115
+ readonly PREVIOUS_TRACK: 16;
116
+ readonly NEXT_TRACK: 32;
117
+ readonly PLAY_MEDIA: 512;
118
+ readonly CLEAR_PLAYLIST: 8192;
119
+ readonly PLAY: 16384;
120
+ readonly SHUFFLE_SET: 32768;
121
+ readonly REPEAT_SET: 262144;
122
+ readonly GROUPING: 524288;
123
+ };
124
+ /** Whether a TV supports a `TV_FEATURE`. */
125
+ export declare const tvSupports: (tv: Tv, feature: number) => boolean;
126
+ /** TVs are `media_player`s; their activity a sensor of theirs. */
127
+ export declare const TVS_WATCH: (entityId: string) => boolean;
128
+ /** The TV's apps from its `apps` attribute: the launcher's (named, not an input's), featured first. */
129
+ export declare function toApps(value: unknown): TvApp[];
130
+ /** The TV's HDMI inputs from its `inputs` attribute, by port. */
131
+ export declare function toInputs(value: unknown): TvInput[];
132
+ /** What the TV says is playing: playing or paused, with a title. */
133
+ export declare function toNowPlaying(entity: HassEntity): TvNowPlaying | undefined;
134
+ /**
135
+ * A Raineworks TV `media_player` as a `Tv` (without its remote, which `discoverTvs` adds).
136
+ * @param activityState Its Activity sensor's state, when it has one.
137
+ */
138
+ export declare function toTv(entity: HassEntity, activityState?: string): Tv;
139
+ /**
140
+ * The label ("Household TV") that picks the house's TVs: once any entity carries it, only the
141
+ * labeled Raineworks TV `media_player`s are listed (the TVs dialog, the intercom's TVs, Party
142
+ * mode's displays, which are matched to them by name); a house without it lists every one.
143
+ */
144
+ export declare const TV_LABEL = "household_tv";
145
+ /**
146
+ * Every TV, by name: the integration's `media_player`s, not hidden. Music Assistant calls things
147
+ * TVs too (its dashboard displays, Party mode's cast targets, the Library's WiiM Pro among them).
148
+ * Without the entity registry (tests), by device class alone.
149
+ */
150
+ export declare function discoverTvs(states: Record<string, HassEntity>, registries?: Pick<HomeAssistant, 'entities'>): Tv[];
151
+ /** The TV in a speaker's room (its area, else its device's): the one a soundbar plays the sound of. */
152
+ export declare function tvInArea(tvs: Tv[], speakerId: string, registries: Pick<HomeAssistant, 'entities' | 'devices'>): Tv | undefined;
153
+ /** The TV to show: the preferred one if it exists, else one that's on, else the first. */
154
+ export declare function defaultTv(tvs: Tv[], preferred?: string): string | undefined;
155
+ /** "YouTube TV · Spider-Man: Homecoming", "Xbox", "Screensaver", "On", "Off" or "Unavailable". */
156
+ export declare function tvStatus(tv: Tv): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Attribute coercers: Home Assistant's attributes (and script responses) are untyped JSON.
3
+ *
4
+ * @module
5
+ */
6
+ /** A finite number, else undefined (null, NaN, a numeric string). */
7
+ export declare const finiteNumber: (value: unknown) => number | undefined;
8
+ /** A string with something in it, trimmed; else undefined. */
9
+ export declare const trimmedString: (value: unknown) => string | undefined;
10
+ /** A state Home Assistant can't read: `unavailable` or `unknown`. */
11
+ export declare const isUnavailable: (state: string | undefined) => state is "unavailable" | "unknown";
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The parts of Home Assistant's frontend `hass` object, and the data in it, that the dashboards
3
+ * use. Typed by hand (narrower than the frontend's own types) so the cards don't depend on
4
+ * Home Assistant's frontend source.
5
+ *
6
+ * @module
7
+ */
8
+ /** An entity's attributes: the few read everywhere are typed, the rest are `unknown`. */
9
+ export interface HassEntityAttributes {
10
+ friendly_name?: string;
11
+ entity_picture?: string;
12
+ brightness?: number;
13
+ temperature?: number | null;
14
+ target_temp_low?: number | null;
15
+ target_temp_high?: number | null;
16
+ current_temperature?: number | null;
17
+ hvac_modes?: string[];
18
+ [key: string]: unknown;
19
+ }
20
+ /** An entity's state as in `hass.states`; `last_changed` / `last_updated` are ISO timestamps. */
21
+ export interface HassEntity {
22
+ entity_id: string;
23
+ state: string;
24
+ attributes: HassEntityAttributes;
25
+ last_changed: string;
26
+ last_updated: string;
27
+ }
28
+ /** A `state_changed` event; `old_state` is null for a new entity, `new_state` for a removed one. */
29
+ export interface HassStateChangeEvent {
30
+ data: {
31
+ entity_id: string;
32
+ old_state: HassEntity | null;
33
+ new_state: HassEntity | null;
34
+ };
35
+ }
36
+ /** Entity registry entry as the frontend receives it (`hass.entities`). */
37
+ export interface HassEntityRegistryEntry {
38
+ entity_id: string;
39
+ name?: string | null;
40
+ area_id?: string | null;
41
+ device_id?: string | null;
42
+ labels?: string[];
43
+ hidden?: boolean;
44
+ /** The integration the entity comes from (`googletv`, `music_assistant`). */
45
+ platform?: string;
46
+ }
47
+ /** Device registry entry as the frontend receives it (`hass.devices`). */
48
+ export interface HassDeviceRegistryEntry {
49
+ id: string;
50
+ area_id?: string | null;
51
+ name?: string | null;
52
+ /** The name given in Home Assistant (Settings → Devices → rename), over the integration's `name`. */
53
+ name_by_user?: string | null;
54
+ manufacturer?: string | null;
55
+ model?: string | null;
56
+ }
57
+ /** An area (`hass.areas`), optionally on a floor. */
58
+ export interface HassArea {
59
+ area_id: string;
60
+ name: string;
61
+ floor_id?: string | null;
62
+ }
63
+ /** A floor (`hass.floors`); `level` orders floors (0 is the ground floor), null when unset. */
64
+ export interface HassFloor {
65
+ floor_id: string;
66
+ name: string;
67
+ level?: number | null;
68
+ }
69
+ /** The events the websocket connection fires (see `HomeAssistant.connection.addEventListener`). */
70
+ export type ConnectionEvent = 'ready' | 'disconnected' | 'reconnect-error';
71
+ /**
72
+ * The `hass` object Home Assistant's frontend hands a card. Everything but `states` and
73
+ * `callService` is optional: older frontends, the demo's mock and tests leave parts out.
74
+ */
75
+ export interface HomeAssistant {
76
+ states: Record<string, HassEntity>;
77
+ connection?: {
78
+ subscribeEvents: (callback: (event: HassStateChangeEvent) => void, eventType?: string) => Promise<() => void>;
79
+ subscribeMessage?: <T = unknown>(callback: (event: T) => void, message: Record<string, unknown>) => Promise<() => void>;
80
+ sendMessagePromise: (message: Record<string, unknown>) => Promise<unknown>;
81
+ socket?: WebSocket;
82
+ /** Whether the websocket is up (home-assistant-js-websocket's Connection). */
83
+ connected?: boolean;
84
+ /** `ready` after (re)connecting, `disconnected` when the socket drops, `reconnect-error` when it can't get back. */
85
+ addEventListener?: (event: ConnectionEvent, listener: () => void) => void;
86
+ removeEventListener?: (event: ConnectionEvent, listener: () => void) => void;
87
+ };
88
+ callService: (domain: string, service: string, serviceData?: Record<string, unknown>) => Promise<unknown>;
89
+ callWS?: <T = unknown>(message: Record<string, unknown>) => Promise<T>;
90
+ /** Home Assistant's REST API as the signed-in user (`path` without `/api/`). */
91
+ callApi?: <T = unknown>(method: 'GET' | 'POST', path: string, parameters?: Record<string, unknown>) => Promise<T>;
92
+ /** Authenticated fetch against the HA REST API. */
93
+ fetchWithAuth?: (path: string, init?: RequestInit) => Promise<Response>;
94
+ /** Core config; external_url/internal_url as set under Settings → System → Network. */
95
+ config?: {
96
+ external_url?: string | null;
97
+ internal_url?: string | null;
98
+ /** `length` is "mi" for imperial installs. */
99
+ unit_system?: {
100
+ length?: string;
101
+ };
102
+ /** The integrations loaded (`assist_pipeline`, `music_assistant`…). */
103
+ components?: string[];
104
+ };
105
+ /** The user's sidebar setting in this browser (Profile → "Always hide the sidebar"). */
106
+ dockedSidebar?: 'docked' | 'always_hidden' | 'auto';
107
+ /** Registries (entity → device → area → floor), as loaded by the frontend. */
108
+ entities?: Record<string, HassEntityRegistryEntry>;
109
+ devices?: Record<string, HassDeviceRegistryEntry>;
110
+ areas?: Record<string, HassArea>;
111
+ floors?: Record<string, HassFloor>;
112
+ /** Theme state; `darkMode` is the user's resolved choice (Auto follows the device). */
113
+ themes?: {
114
+ darkMode?: boolean;
115
+ theme?: string;
116
+ };
117
+ /** This browser's theme choice (Profile → Browser settings); `dark` unset = Auto. */
118
+ selectedTheme?: {
119
+ theme?: string;
120
+ dark?: boolean;
121
+ } | null;
122
+ /** Registered services by domain. */
123
+ services?: Record<string, Record<string, unknown>>;
124
+ user?: {
125
+ id: string;
126
+ name: string;
127
+ is_admin: boolean;
128
+ is_owner: boolean;
129
+ };
130
+ }
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
- "name": "@raineworks/ha-dashboards",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@raineworks/ha-dashboards",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "description": "Raineworks Dashboards' house settings parser, bedtime routines and setup MCP server, for a house's own Home Assistant config repository",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/raine-works/ha-dashboards.git",
10
+ "directory": "packages/kit"
11
+ },
12
+ "bin": {
13
+ "raineworks-dashboards-mcp": "./dist/mcp.js"
14
+ },
15
+ "exports": {
16
+ "./house": {
17
+ "types": "./dist/types/kit/src/house.d.ts",
18
+ "default": "./dist/house.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "bun scripts/build.ts",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "devDependencies": {
30
+ "@app/ha-client": "workspace:*",
31
+ "@app/mcp": "workspace:*",
32
+ "@app/ui": "workspace:*",
33
+ "@types/bun": "catalog:",
34
+ "typescript": "catalog:"
35
+ }
36
+ }