@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.
@@ -0,0 +1,489 @@
1
+ /**
2
+ * Music Assistant through Home Assistant: which speakers the dashboards list, each player's state
3
+ * as the music player shows it, groups and volume, search and the library, the queue, podcasts
4
+ * and the Party dashboard.
5
+ *
6
+ * @module
7
+ */
8
+ import type { HassEntity, HomeAssistant } from '../types/homeassistant';
9
+ /** The `media_player` `supported_features` bits the player reads. */
10
+ export declare const MEDIA_FEATURE: {
11
+ readonly PAUSE: 1;
12
+ readonly SEEK: 2;
13
+ readonly VOLUME_SET: 4;
14
+ readonly VOLUME_MUTE: 8;
15
+ readonly PREVIOUS_TRACK: 16;
16
+ readonly NEXT_TRACK: 32;
17
+ readonly PLAY_MEDIA: 512;
18
+ readonly CLEAR_PLAYLIST: 8192;
19
+ readonly PLAY: 16384;
20
+ readonly SHUFFLE_SET: 32768;
21
+ readonly REPEAT_SET: 262144;
22
+ readonly GROUPING: 524288;
23
+ };
24
+ /** A player's repeat mode. */
25
+ export type RepeatMode = 'off' | 'all' | 'one';
26
+ /** A player's state (anything Home Assistant reports beyond these counts as unavailable). */
27
+ export type PlaybackState = 'playing' | 'paused' | 'idle' | 'off' | 'unavailable';
28
+ /** A Music Assistant speaker as the music player shows it (`toMusicPlayer`). */
29
+ export interface MusicPlayer {
30
+ /** Its `media_player` entity id. */
31
+ entityId: string;
32
+ /** Its friendly name. */
33
+ name: string;
34
+ /** Its playback state. */
35
+ state: PlaybackState;
36
+ /** What's playing: the track, the live input's name, or "TV audio". */
37
+ title?: string;
38
+ /** The track's artist. */
39
+ artist?: string;
40
+ /** The track's album. */
41
+ album?: string;
42
+ /** Artwork URL (Home Assistant's proxy when available, so it works wherever HA does). */
43
+ artwork?: string;
44
+ /** Seconds. */
45
+ duration?: number;
46
+ /** 0–100. */
47
+ volume: number;
48
+ /** Muted. */
49
+ muted: boolean;
50
+ /** Shuffle on. */
51
+ shuffle: boolean;
52
+ /** Repeat mode. */
53
+ repeat: RepeatMode;
54
+ /** Whole sync group, leader first (empty when not grouped). */
55
+ groupMembers: string[];
56
+ /** The group leader when this player follows another; its controls act on the leader. */
57
+ leader?: string;
58
+ /** Seconds into the track at `positionUpdatedAt` (epoch ms). */
59
+ position?: number;
60
+ /** When `position` was reported (epoch ms). */
61
+ positionUpdatedAt?: number;
62
+ /** When the state last changed (epoch ms). */
63
+ lastChanged?: number;
64
+ /** Playing a live input (the turntable) instead of the queue: no seek, skip, shuffle or repeat. */
65
+ liveInput?: LiveInput;
66
+ /**
67
+ * Playing its TV's sound (a Sonos soundbar on its TV input): the TV runs playback, so nothing
68
+ * here can pause, skip or move it; only the volume and mute work.
69
+ */
70
+ tvAudio: boolean;
71
+ /** What it plays (music, a station, a podcast), for placeholder art when there's no cover. */
72
+ kind: MediaKind;
73
+ /** The playing item's URI (`media_content_id`), e.g. `spotify--x://track/…`. */
74
+ contentId?: string;
75
+ /**
76
+ * Music Assistant's queue id (`active_queue`). Empty while a live input (the turntable) plays as
77
+ * the speaker's source; the queue scripts then find the speaker's own from its entity.
78
+ */
79
+ queueId?: string;
80
+ /**
81
+ * `MEDIA_FEATURE` bits it supports, less what a live input or the TV's sound can't do (test with
82
+ * `supports`).
83
+ */
84
+ features: number;
85
+ }
86
+ /**
87
+ * A live audio input Music Assistant can play on any speaker (its Sendspin Source plugin turns a
88
+ * Sendspin source client into one): a `<provider>://audio_source/<client id>` URI. The id comes from
89
+ * the device's pairing key, so it stays put; a newly paired input shows its URI as the playing
90
+ * speaker's `media_content_id` once started from Music Assistant's Browse.
91
+ */
92
+ export interface LiveInput {
93
+ /** Its name ("Turntable"). */
94
+ name: string;
95
+ /** Its `<provider>://audio_source/<client id>` URI. */
96
+ uri: string;
97
+ /** Binary sensor that's on while audio reaches the input (the record is playing). */
98
+ signal?: string;
99
+ }
100
+ /** The house's live inputs (the house settings' `live_inputs`). */
101
+ export declare const liveInputs: () => LiveInput[];
102
+ /** The live input a player is on, from its content URI (an unknown one keeps Music Assistant's name). */
103
+ export declare function liveInputFor(contentId: string | undefined, title: string | undefined): LiveInput | undefined;
104
+ /**
105
+ * On its TV input (a Sonos soundbar): Music Assistant reports `source: TV` / `app_id: tv` with
106
+ * no queue (`media_title` "TV Audio", `media_content_id` `homeTheater-input`).
107
+ */
108
+ export declare const isTvAudio: (a: HassEntity["attributes"]) => boolean;
109
+ type Registries = Pick<HomeAssistant, 'entities' | 'devices'> | null | undefined;
110
+ /**
111
+ * The label ("Household Speaker") that picks the speakers the dashboards list: once any entity
112
+ * carries it, only the labeled ones are speakers (the music player, the intercom, the Daily
113
+ * dialog's Play on); a house without it lists every Music Assistant speaker.
114
+ */
115
+ export declare const SPEAKER_LABEL = "household_speaker";
116
+ /**
117
+ * A real speaker to list (in the music player and the intercom): with the Household Speaker label in
118
+ * use, one that carries it; else not one of Music Assistant's browser players (device model "Web
119
+ * Player", e.g. "Web (Chrome on Mac)"). Never one hidden in Home Assistant.
120
+ */
121
+ export declare function isSpeaker(entityId: string, hass: Registries): boolean;
122
+ /** A Music Assistant player (MA tags its entities with `mass_player_type`) that is a speaker. */
123
+ export declare const isMusicPlayer: (entity: HassEntity, hass?: Registries) => boolean;
124
+ /** Music Assistant's speakers, sorted by name. */
125
+ export declare function discoverMusicPlayers(states: Record<string, HassEntity>, hass?: Registries): MusicPlayer[];
126
+ /** A Music Assistant `media_player` entity as a `MusicPlayer`. */
127
+ export declare function toMusicPlayer(entity: HassEntity): MusicPlayer;
128
+ /** Whether a player supports a `MEDIA_FEATURE`. */
129
+ export declare const supports: (player: Pick<MusicPlayer, "features">, feature: number) => boolean;
130
+ /**
131
+ * Played to its end: idle (or paused) within 2 seconds of the track's length. Music Assistant
132
+ * leaves a finished track loaded, which would otherwise look paused.
133
+ */
134
+ export declare const hasEnded: (player: MusicPlayer) => boolean;
135
+ /**
136
+ * A track is loaded: playing, or paused. Music Assistant's WiiM and Sonos players report a pause
137
+ * as `idle` (keeping the track and the queue), so idle with a title counts as paused, unless it
138
+ * played to its end.
139
+ */
140
+ export declare const hasMedia: (player: MusicPlayer) => boolean;
141
+ /** Paused (or stopped with the track still loaded), as the player shows it. */
142
+ export declare const isPaused: (player: MusicPlayer, state?: PlaybackState) => boolean;
143
+ /** How long a paused speaker stays in the now-playing indicators (cards, header, mini player). */
144
+ export declare const PAUSED_INDICATOR_MS: number;
145
+ /**
146
+ * Worth showing on the dashboard: playing, or paused within the last hour. Never the TV's sound:
147
+ * nothing here controls it (the TV dialog shows what's on).
148
+ */
149
+ export declare function isNowPlaying(player: MusicPlayer, now?: number): boolean;
150
+ /** Every speaker (or group, by its leader) playing, or paused within the last hour: playing first. */
151
+ export declare function activePlayers(players: MusicPlayer[]): MusicPlayer[];
152
+ /** Seconds into the track now: the reported position plus the time since, while playing. */
153
+ export declare function currentPosition(player: MusicPlayer, now?: number): number;
154
+ /** Where a track was when it started moving to another speaker. */
155
+ export interface ResumePoint {
156
+ /** The track's title. */
157
+ title?: string;
158
+ /** Seconds into the track when the move started. */
159
+ position: number;
160
+ /** When the move started (epoch ms). */
161
+ at: number;
162
+ /** The track's length in seconds (none for a live stream). */
163
+ duration?: number;
164
+ /** Still playing: the track kept going during the move. */
165
+ playing: boolean;
166
+ }
167
+ /**
168
+ * Where to pick a moved track back up: where it was, plus the time the move took if it was
169
+ * playing. Undefined for live streams (no duration), the very start, or past the end.
170
+ */
171
+ export declare function resumePosition(point: ResumePoint, now?: number): number | undefined;
172
+ /** "3:07", or "1:02:03" past an hour. */
173
+ export declare const formatTrackTime: (seconds: number | undefined) => string;
174
+ /**
175
+ * The player to show first: the last pick if it still exists, else whatever is playing (a group
176
+ * shows as its leader; the TV's sound doesn't count), else paused, else the first.
177
+ */
178
+ export declare function defaultPlayer(players: MusicPlayer[], preferred?: string): string | undefined;
179
+ /** A group's volume: the average of its speakers' (0–100). */
180
+ export declare function groupVolume(volumes: number[]): number;
181
+ /**
182
+ * Each speaker's volume after moving the group volume to `target`: every speaker shifts by the same
183
+ * amount, so their balance stays (clamped to 0–100; at 0 everything is silent).
184
+ */
185
+ export declare function applyGroupVolume(volumes: number[], target: number): number[];
186
+ /** Speakers playing along with another (every group's followers): ungrouping them splits every group. */
187
+ export declare const groupFollowers: (players: MusicPlayer[]) => string[];
188
+ /**
189
+ * The speakers "Join all" adds to `leader`'s group: every other available speaker that can group
190
+ * and isn't in it yet (one in another group moves over), never one playing its TV's sound.
191
+ */
192
+ export declare function joinableSpeakers(leader: MusicPlayer, players: MusicPlayer[]): string[];
193
+ /** "Library + Kitchen", or the one speaker's name. */
194
+ export declare function speakerNames(player: MusicPlayer, players: MusicPlayer[]): string;
195
+ /** Search results by exactly this artist (MA's artist filter is fuzzy: "Knox" also finds "Knox Hamilton"). */
196
+ export declare function byArtist(items: MediaItem[], artist: string): MediaItem[];
197
+ /** Next repeat mode when the repeat button is tapped: off → all → one → off. */
198
+ export declare const nextRepeat: (mode: RepeatMode) => RepeatMode;
199
+ /** What Music Assistant's library and search list. */
200
+ export type MediaType = 'artist' | 'album' | 'track' | 'playlist' | 'radio' | 'podcast';
201
+ /** What something plays: music, a radio station, a podcast, or the spoken daily brief (or scripture). */
202
+ export type MediaKind = 'music' | 'radio' | 'podcast' | 'brief';
203
+ /**
204
+ * Where the daily brief's recording (`script.daily_brief_audio`) and the scripture's
205
+ * (`script.daily_scripture_audio`) are served from; Music Assistant plays them as
206
+ * `builtin://track/<url>`.
207
+ */
208
+ export declare const DAILY_BRIEF_AUDIO_PATH = "/local/daily_brief/";
209
+ /** The kind of a media type or URI (`library://radio/1`, `spotify--x://podcast_episode/…`). */
210
+ export declare function mediaKindOf(typeOrUri: string | undefined): MediaKind;
211
+ /** Something in Music Assistant's library or search results, to browse, play or queue. */
212
+ export interface MediaItem {
213
+ /** A podcast's episode is played (and queued) but never browsed or searched for. */
214
+ mediaType: MediaType | 'podcast_episode';
215
+ /** Music Assistant's URI for it. */
216
+ uri: string;
217
+ /** Its name. */
218
+ name: string;
219
+ /** Artists, or the album for a track without artists. */
220
+ subtitle?: string;
221
+ /** Its artists' names. */
222
+ artists?: string[];
223
+ /** Its cover URL. */
224
+ image?: string;
225
+ }
226
+ /** MA's item shape → MediaItem (unknown types and items without a URI are dropped). */
227
+ export declare function toMediaItems(raw: unknown): MediaItem[];
228
+ /** A search's results by media type. */
229
+ export interface SearchResults {
230
+ artists: MediaItem[];
231
+ albums: MediaItem[];
232
+ tracks: MediaItem[];
233
+ playlists: MediaItem[];
234
+ radio: MediaItem[];
235
+ podcasts: MediaItem[];
236
+ }
237
+ /** `music_assistant.search`'s response as `SearchResults` (a missing type is empty). */
238
+ export declare function toSearchResults(raw: unknown): SearchResults;
239
+ /** The current or next song in a speaker's queue (`music_assistant.get_queue`). */
240
+ export interface QueueItem {
241
+ /** Music Assistant's queue item id (the same song queued twice has two). */
242
+ id?: string;
243
+ /** Its title ("Unknown" when Music Assistant gives none). */
244
+ name: string;
245
+ /** Its artists, joined. */
246
+ artist?: string;
247
+ /** Its cover, else its album's. */
248
+ image?: string;
249
+ /** Seconds. */
250
+ duration?: number;
251
+ /** Its artists, to open their pages (Music Assistant gives their URIs). */
252
+ artistItems?: MediaItem[];
253
+ /** Its album, to open its page. */
254
+ albumItem?: MediaItem;
255
+ }
256
+ /** What `music_assistant.get_queue` tells of a speaker's queue. */
257
+ export interface QueueSummary {
258
+ /** Items in the queue. */
259
+ count: number;
260
+ /** The playing song. */
261
+ current?: QueueItem;
262
+ /** The song after it. */
263
+ next?: QueueItem;
264
+ }
265
+ /** `music_assistant.get_queue`'s response for one player (MA exposes current and next only). */
266
+ export declare function toQueueSummary(raw: unknown, entityId: string): QueueSummary | undefined;
267
+ type Hass = Pick<HomeAssistant, 'callWS'> & Partial<Pick<HomeAssistant, 'config' | 'services' | 'states' | 'entities'>>;
268
+ /**
269
+ * Music Assistant's integration has raine-works' actions (raine-works/ha-music-assistant: the whole
270
+ * queue and its edits, podcast episodes, the Party link), over its own connection; without them the
271
+ * Queue tab, podcast episodes and the Party link aren't there (the built-in integration has no way).
272
+ */
273
+ export declare const hasMusicActions: (hass: Pick<HomeAssistant, "services"> | Partial<Pick<HomeAssistant, "services">>) => boolean;
274
+ /**
275
+ * Music Assistant's config entry, which search and library calls need. Read from a player's
276
+ * registry entry (open to every user), falling back to the config entries list (admins).
277
+ */
278
+ export declare function findMusicConfigEntry(hass: Hass, playerEntityId?: string): Promise<string | undefined>;
279
+ /**
280
+ * Search Music Assistant (`music_assistant.search`).
281
+ * @param configEntryId Music Assistant's config entry (`findMusicConfigEntry`).
282
+ * @param types Only these media types; all when absent.
283
+ * @param filters `artist`: Music Assistant's (fuzzy) artist filter; `byArtist` narrows it.
284
+ * @throws When Home Assistant refuses the call.
285
+ */
286
+ export declare function searchMusic(hass: Hass, configEntryId: string, query: string, types?: MediaType[], filters?: {
287
+ artist?: string;
288
+ }): Promise<SearchResults>;
289
+ /**
290
+ * One media type from Music Assistant's library (`music_assistant.get_library`).
291
+ * @param options `favorite`: favorites only; `orderBy`: Music Assistant's sort key (`last_played`…).
292
+ * @throws When Home Assistant refuses the call.
293
+ */
294
+ export declare function getLibrary(hass: Hass, configEntryId: string, mediaType: MediaType, options?: {
295
+ favorite?: boolean;
296
+ orderBy?: string;
297
+ }): Promise<MediaItem[]>;
298
+ /**
299
+ * An album's or playlist's tracks, in order, from its media browser node. Their titles read "Artist -
300
+ * Title": the album's artist (else everything before the first " - ") is split off as the subtitle.
301
+ */
302
+ export declare function toTracks(node: unknown, albumArtist?: string): MediaItem[];
303
+ /**
304
+ * An album's or playlist's tracks through a Music Assistant player's media browser (MA's services
305
+ * don't list them).
306
+ */
307
+ export declare function getTracks(hass: Hass, playerEntityId: string, item: MediaItem): Promise<MediaItem[]>;
308
+ /**
309
+ * Whether the playing track is one of a list's tracks: by URI, else by title (a library track can
310
+ * play under its provider's URI).
311
+ */
312
+ export declare function hasTrack(tracks: MediaItem[], playing: Pick<MusicPlayer, 'contentId' | 'title'>): boolean;
313
+ /**
314
+ * Has the queue caught up with the playing track? Right after a skip Music Assistant's queue can
315
+ * still have the previous track as current, and for about a second after that its next item is
316
+ * still the current one (the same queue item). A queue item without a media item is named
317
+ * "Artist - Title".
318
+ */
319
+ export declare function queueIsCurrent(queue: QueueSummary | undefined, title: string | undefined): boolean;
320
+ /**
321
+ * A speaker's current and next songs (`music_assistant.get_queue`).
322
+ * @returns Undefined when Music Assistant has no queue for it.
323
+ * @throws When Home Assistant refuses the call.
324
+ */
325
+ export declare function getQueue(hass: Hass, entityId: string): Promise<QueueSummary | undefined>;
326
+ /** Music Assistant's Party guest join link (`music_assistant.get_party_url`); `url` is null while guest access is off. */
327
+ export interface PartyLink {
328
+ /** The join link, or null while guest access is off (or it couldn't be asked). */
329
+ url: string | null;
330
+ /** 200 when Music Assistant answered; 0 when it couldn't be asked (no raine-works/ha-music-assistant). */
331
+ status: number;
332
+ }
333
+ /** A TV Music Assistant can cast its Party Dashboard to (lyrics and the join QR code). */
334
+ export interface PartyTv {
335
+ /** Its Music Assistant display `media_player` entity id. */
336
+ id: string;
337
+ /** Its friendly name. */
338
+ name: string;
339
+ /** Showing the Party Dashboard now. */
340
+ showing: boolean;
341
+ }
342
+ /**
343
+ * The Party guest join link; `status` 0 without raine-works' Music Assistant actions.
344
+ * @throws When Home Assistant refuses the call.
345
+ */
346
+ export declare function getPartyLink(hass: Hass): Promise<PartyLink>;
347
+ /**
348
+ * The TVs for the Party Dashboard from Music Assistant's display media players (the built-in
349
+ * integration's: `music_assistant` entities with device class tv, each a display it can cast to),
350
+ * by name: those named in `tvNames`, the house's TVs (`discoverTvs()`: the Household TV label's,
351
+ * else every Raineworks TV; Music Assistant counts some audio receivers as displays), while
352
+ * available. A display shows the Party Dashboard while it's playing `party`.
353
+ */
354
+ export declare function partyDisplays(hass: Pick<HomeAssistant, 'states' | 'entities'>, tvNames: ReadonlySet<string>): PartyTv[];
355
+ /** `partyDisplays` from what `hass` has; none before its states arrive. */
356
+ export declare function getPartyTvs(hass: Hass, tvNames?: ReadonlySet<string>): Promise<PartyTv[]>;
357
+ /**
358
+ * Show (or hide) the Party Dashboard on one TV: its display media player (`media_player.play_media`
359
+ * with content type dashboard and id party; `turn_off` hides it); rejects when Music Assistant refuses.
360
+ */
361
+ export declare function castParty(hass: Hass, tv: string, show: boolean): Promise<void>;
362
+ /** One song in a speaker's whole queue (`music_assistant.get_queue_items`). */
363
+ export interface QueueEntry {
364
+ /** Music Assistant's queue_item_id, for playing from it, moving and removing it. */
365
+ id: string;
366
+ /** Its place in the queue (0 = the first item, played or not). */
367
+ index: number;
368
+ /** Its title ("Unknown" when Music Assistant gives none). */
369
+ name: string;
370
+ /** Its artist. */
371
+ artist?: string;
372
+ /** Its album. */
373
+ album?: string;
374
+ /** Seconds. */
375
+ duration?: number;
376
+ /** Its cover URL. */
377
+ image?: string;
378
+ /** Music Assistant's URI for the song. */
379
+ uri?: string;
380
+ }
381
+ /** A page of a speaker's whole queue, from Music Assistant through Home Assistant. */
382
+ export interface QueuePage {
383
+ /** The playing item's place in the queue. */
384
+ currentIndex: number;
385
+ /** Items in the whole queue, played ones included. */
386
+ total: number;
387
+ /** The first entry's index. */
388
+ offset: number;
389
+ /** The page's songs, in queue order. */
390
+ entries: QueueEntry[];
391
+ /** The playlist or album the queue was started from. */
392
+ source?: MediaItem;
393
+ }
394
+ /**
395
+ * A `music_assistant.get_queue_items` answer as a `QueuePage`: undefined unless its status is 200;
396
+ * entries without an id are dropped.
397
+ */
398
+ export declare function toQueuePage(response: unknown): QueuePage | undefined;
399
+ /**
400
+ * A page of the speaker's whole queue, from `offset` (default: the playing item). Found by its
401
+ * entity too, so it works while a live input plays (when `active_queue` is empty).
402
+ */
403
+ export declare function getQueuePage(hass: Hass, speaker: Pick<MusicPlayer, 'entityId' | 'queueId'>, options?: {
404
+ offset?: number;
405
+ limit?: number;
406
+ }): Promise<QueuePage | undefined>;
407
+ /** An edit to a queue entry: play from it, remove it, move it `shift` places, or resume the parked queue. */
408
+ export type QueueEdit = {
409
+ action: 'play';
410
+ } | {
411
+ action: 'remove';
412
+ } | {
413
+ action: 'move';
414
+ shift: number;
415
+ }
416
+ /** Back to the queue where it was parked (after a live input, the turntable); no entry. */
417
+ | {
418
+ action: 'resume';
419
+ };
420
+ /** Play from, move or remove a queue entry (`music_assistant.edit_queue`); rejects when Music Assistant refuses. */
421
+ export declare function editQueue(hass: Hass, speaker: Pick<MusicPlayer, 'entityId' | 'queueId'>, entry: string, edit: QueueEdit): Promise<void>;
422
+ /**
423
+ * The entries after a local edit, before Music Assistant's queue is read again (so a row moves or
424
+ * goes at once): `move` shifts it `shift` places (0 = right after the playing one), indexes follow.
425
+ */
426
+ export declare function applyQueueEdit(entries: QueueEntry[], id: string, edit: QueueEdit, currentIndex: number): QueueEntry[];
427
+ /** One of a podcast's episodes (`music_assistant.get_podcast_episodes`). */
428
+ export interface PodcastEpisode {
429
+ /** Music Assistant's URI for it. */
430
+ uri: string;
431
+ /** Its title ("Untitled episode" when it has none). */
432
+ name: string;
433
+ /** When it came out (ISO). */
434
+ released?: string;
435
+ /** Seconds. */
436
+ duration?: number;
437
+ /** Where the listener left off, in seconds (0 = not started). */
438
+ resume: number;
439
+ /** Listened to the end. */
440
+ played: boolean;
441
+ /** Its show notes as plain text, cut short. */
442
+ description?: string;
443
+ /** Its own cover URL. */
444
+ image?: string;
445
+ }
446
+ /** A page of a podcast's episodes, newest first. */
447
+ export interface EpisodePage {
448
+ /** Episodes the podcast has in all. */
449
+ total: number;
450
+ /** The first episode's place among them. */
451
+ offset: number;
452
+ /** The page's episodes. */
453
+ episodes: PodcastEpisode[];
454
+ }
455
+ /**
456
+ * A `music_assistant.get_podcast_episodes` answer as an `EpisodePage`: undefined unless its status
457
+ * is 200; episodes without a URI are dropped.
458
+ */
459
+ export declare function toEpisodePage(response: unknown): EpisodePage | undefined;
460
+ /**
461
+ * The next page added to the episodes shown (Show more). By uri, once each: an episode published
462
+ * since the last page shifts the list, so the next one starts with an episode already shown.
463
+ */
464
+ export declare function appendEpisodes(shown: EpisodePage, next: EpisodePage): EpisodePage;
465
+ /**
466
+ * A page of a podcast's episodes, newest first, from Music Assistant (Home Assistant's media
467
+ * browser doesn't expand a podcast); undefined when Music Assistant couldn't be asked.
468
+ */
469
+ export declare function getPodcastEpisodes(hass: Hass, podcast: Pick<MediaItem, 'uri'>, options?: {
470
+ offset?: number;
471
+ limit?: number;
472
+ }): Promise<EpisodePage | undefined>;
473
+ /** An episode as something to play or queue, with the podcast's cover when it has none of its own. */
474
+ export declare const episodeItem: (episode: PodcastEpisode, podcast: MediaItem) => MediaItem;
475
+ /** "Oct 24", or "Oct 24, 2025" from another year. */
476
+ export declare function formatEpisodeDate(iso: string | undefined, now?: Date): string | undefined;
477
+ /** "45 min", "1 hr 5 min"; under a minute counts as one. */
478
+ export declare function formatEpisodeLength(seconds: number): string;
479
+ /**
480
+ * How far along an episode is: "Played", "12 min left" once started, else its length; `progress`
481
+ * (0–1) only while it's started and not done.
482
+ */
483
+ export declare function episodeProgress(episode: Pick<PodcastEpisode, 'duration' | 'resume' | 'played'>): {
484
+ label?: string;
485
+ progress?: number;
486
+ };
487
+ /** A cover at the size the others come in: Spotify's Liked Songs art at 640px instead of 64. */
488
+ export declare function fullSizeCover(src: string | undefined): string | undefined;
489
+ export {};
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The household's people: where each is (zone, position, distance from home), their phone's
3
+ * battery, who's signed in, and street names for people outside every zone.
4
+ *
5
+ * @module
6
+ */
7
+ import type { HassEntity } from '../types/homeassistant';
8
+ import type { EntityWatch } from './hass-store';
9
+ /** A zone a person is in. */
10
+ export interface PersonZone {
11
+ /** The `zone.*` entity id (empty when the state names a zone that isn't there). */
12
+ entityId: string;
13
+ /** The zone's name. */
14
+ name: string;
15
+ }
16
+ /** A person's phone battery. */
17
+ export interface PersonBattery {
18
+ /** 0–100 */
19
+ level: number;
20
+ /** Charging (or full and still plugged in). */
21
+ charging: boolean;
22
+ /** Battery is reported full (iOS "Full"); counts as charging when still plugged in. */
23
+ full: boolean;
24
+ }
25
+ /** A person as the dashboards show them (`getPersonView`). */
26
+ export interface PersonView {
27
+ /** Their `person.*` entity id. */
28
+ entityId: string;
29
+ /** Their friendly name. */
30
+ name: string;
31
+ /** First word of the friendly name, for tight spaces. */
32
+ shortName: string;
33
+ /** One or two letters for an avatar without a picture. */
34
+ initials: string;
35
+ /** Their picture's URL. */
36
+ picture?: string;
37
+ /** Home Assistant has them home. */
38
+ isHome: boolean;
39
+ /** Smallest zone the person is in (home included), or null when away from every zone. */
40
+ zone: PersonZone | null;
41
+ /** Zone name, "Away" or "Unknown". */
42
+ locationLabel: string;
43
+ /** Their latitude, when known. */
44
+ latitude: number | null;
45
+ /** Their longitude, when known. */
46
+ longitude: number | null;
47
+ /** Straight-line distance from zone.home in meters, when both positions are known. */
48
+ distanceFromHome: number | null;
49
+ /** Their phone's battery, when it reports one. */
50
+ battery: PersonBattery | null;
51
+ /** When the tracker last reported (ISO timestamp). */
52
+ updated: string;
53
+ }
54
+ /** "AB" from "Alex Brown" (first and last words), "AL" from "Alex", "?" from nothing. */
55
+ export declare function initialsFor(name: string): string;
56
+ /** Great-circle distance in meters. */
57
+ export declare function haversineMeters(lat1: number, lon1: number, lat2: number, lon2: number): number;
58
+ /** "0.4 mi" / "12 mi" (imperial) or "650 m" / "12 km" (metric). */
59
+ export declare function formatDistance(meters: number, imperial: boolean): string;
60
+ /** "Just now", "5 min ago", "3 hr ago", "2 days ago". */
61
+ export declare function formatAgo(iso: string, now: number): string;
62
+ /**
63
+ * Battery for a tracker. Companion app trackers (`device_tracker.<device>`) come with
64
+ * `sensor.<device>_battery_level` and `sensor.<device>_battery_state` (Android: charging /
65
+ * discharging / full / not_charging; iOS: Charging / Not Charging / Full). Falls back to the
66
+ * tracker's own battery attributes.
67
+ */
68
+ export declare function batteryForTracker(trackerId: string | undefined, states: Record<string, HassEntity>): PersonBattery | null;
69
+ /** A `person.*` entity as a `PersonView`, its battery from its tracker (the `source`, else the first). */
70
+ export declare function getPersonView(person: HassEntity, states: Record<string, HassEntity>): PersonView;
71
+ /** What `discoverPeople` reads: people, zones, trackers and the Companion app's battery sensors. */
72
+ export declare const PEOPLE_WATCH: EntityWatch;
73
+ /**
74
+ * The household (`isHouseholdMember()`: the integration's list, else every person with a device
75
+ * tracker, which skips the admin account and pets), sorted by name.
76
+ */
77
+ export declare function discoverPeople(states: Record<string, HassEntity>): PersonView[];
78
+ /**
79
+ * The household member signed in as `userId`: the household person (`isHouseholdMember()`) whose
80
+ * `user_id` it is; undefined for an account that isn't a household member (the
81
+ * admin account, the wall panels' user).
82
+ */
83
+ export declare function householdPerson(states: Record<string, HassEntity>, userId: string | undefined): HassEntity | undefined;
84
+ /** The first name of the household member signed in as `userId` (`householdPerson()`), else undefined. */
85
+ export declare function householdFirstName(states: Record<string, HassEntity>, userId: string | undefined): string | undefined;
86
+ /** Everyone with a known position. */
87
+ export declare function locatedPeople(people: PersonView[]): (PersonView & {
88
+ latitude: number;
89
+ longitude: number;
90
+ })[];
91
+ /** The parts of a Nominatim reverse lookup's `address` that `formatPlace` reads. */
92
+ export interface NominatimAddress {
93
+ road?: string;
94
+ neighbourhood?: string;
95
+ suburb?: string;
96
+ hamlet?: string;
97
+ village?: string;
98
+ town?: string;
99
+ city?: string;
100
+ county?: string;
101
+ state?: string;
102
+ [key: string]: string | undefined;
103
+ }
104
+ /** "Main Street, Orem" — the street (or neighborhood) and the town. */
105
+ export declare function formatPlace(address: NominatimAddress, placeName?: string): string | null;
106
+ /**
107
+ * Street and town for a position, cached per ~100 m cell. Requests are serialized at
108
+ * ≥1 s apart to respect Nominatim's usage policy.
109
+ * @returns Null when the lookup fails (never rejects); a failed cell is asked again after five minutes.
110
+ */
111
+ export declare function reverseGeocode(lat: number, lon: number, fetcher?: typeof fetch): Promise<string | null>;
112
+ /**
113
+ * Groups of items whose points (screen pixels) are within `radius` of a group's first item, in
114
+ * order: what overlaps on the map at the current zoom becomes one marker.
115
+ */
116
+ export declare function groupNearby<T>(items: T[], point: (item: T) => {
117
+ x: number;
118
+ y: number;
119
+ }, radius: number): T[][];
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Service calls: one that answers with data, and a failed one in words for its toast.
3
+ *
4
+ * @module
5
+ */
6
+ import type { HassEntity, HomeAssistant } from '../types/homeassistant';
7
+ /**
8
+ * A failed service call in words ("Couldn't lock Front Entry", "Couldn't turn on Kitchen +2"), for
9
+ * the toast that reports it: the service's verb and the entities' names.
10
+ */
11
+ export declare function describeServiceCall(domain: string, service: string, data?: Record<string, unknown>, states?: Record<string, HassEntity>): string;
12
+ /** Home Assistant's reason for a failure: websocket errors are `{ code, message }`, others Errors. */
13
+ export declare function serviceErrorMessage(err: unknown): string | undefined;
14
+ /**
15
+ * Call a service that answers with data (`return_response`: a search, a queue, a calendar's
16
+ * events, a script's result), over the websocket. Its response, or undefined; rejects when Home
17
+ * Assistant does, or isn't connected yet.
18
+ */
19
+ export declare function callForResponse<T = unknown>(hass: Pick<HomeAssistant, 'callWS'>, domain: string, service: string, data?: Record<string, unknown>, target?: Record<string, unknown>): Promise<T | undefined>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Words: title case, a list of names in a sentence, a capital first letter.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Title case ("Front Door opened" → "Front Door Opened", "Snack on the way" → "Snack on the Way"):
8
+ * every word's first letter capitalized but the minor words inside, and nothing ever lowercased,
9
+ * so names keep their own spelling ("WiiM", "TV").
10
+ */
11
+ export declare function titleCase(text: string): string;
12
+ /** "Sam", "Sam and Alex", "Sam, Alex and Jo". */
13
+ export declare function nameList(names: readonly string[]): string;
14
+ /** The first letter capitalized, the rest kept ("heat_cool" → "Heat_cool", "person" → "Person"). */
15
+ export declare const capitalize: (text: string) => string;