@glasshome/sync-layer 0.7.2 → 0.8.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.
Files changed (58) hide show
  1. package/dist/index.d.ts +1291 -54
  2. package/dist/index.js +203 -304
  3. package/dist/service-C8H42I-Q.d.ts +459 -0
  4. package/dist/solid/index.d.ts +119 -6
  5. package/dist/solid/index.js +20 -15
  6. package/dist/{statistics-CtRfIF6D.js → statistics-DyCCTwv2.js} +83 -95
  7. package/dist/worker/worker-main.d.ts +11 -8
  8. package/dist/worker/worker-main.js +2 -3
  9. package/dist/{worker-main-C-3QM4di.js → worker-main-D_wyGAIG.js} +47 -157
  10. package/package.json +4 -4
  11. package/dist/calendar/track.d.ts +0 -19
  12. package/dist/calendar/types.d.ts +0 -32
  13. package/dist/camera/fetch.d.ts +0 -16
  14. package/dist/camera/query.d.ts +0 -15
  15. package/dist/camera/types.d.ts +0 -85
  16. package/dist/camera/webrtc.d.ts +0 -31
  17. package/dist/commands/service.d.ts +0 -53
  18. package/dist/commands/types.d.ts +0 -113
  19. package/dist/connection/adapter.d.ts +0 -48
  20. package/dist/connection/auth.d.ts +0 -126
  21. package/dist/connection/bridged.d.ts +0 -16
  22. package/dist/connection/manager.d.ts +0 -51
  23. package/dist/connection/subscription-manager.d.ts +0 -48
  24. package/dist/connection/subscriptions.d.ts +0 -31
  25. package/dist/connection/types.d.ts +0 -151
  26. package/dist/core/privileged-conn.d.ts +0 -29
  27. package/dist/core/reducers.d.ts +0 -99
  28. package/dist/core/store.d.ts +0 -100
  29. package/dist/core/types.d.ts +0 -339
  30. package/dist/demo/demo-data.d.ts +0 -24
  31. package/dist/demo/demo-provider.d.ts +0 -40
  32. package/dist/demo/energy-sim.d.ts +0 -112
  33. package/dist/energy/prefs.d.ts +0 -56
  34. package/dist/entities/area-views.d.ts +0 -32
  35. package/dist/entities/index.d.ts +0 -54
  36. package/dist/entities/views.d.ts +0 -35
  37. package/dist/history/constants.d.ts +0 -16
  38. package/dist/history/fetch.d.ts +0 -19
  39. package/dist/history/query.d.ts +0 -27
  40. package/dist/history/statistics.d.ts +0 -55
  41. package/dist/history/types.d.ts +0 -146
  42. package/dist/host-api.d.ts +0 -50
  43. package/dist/media/url.d.ts +0 -14
  44. package/dist/query/area-builder.d.ts +0 -25
  45. package/dist/query/builder.d.ts +0 -18
  46. package/dist/query/helpers.d.ts +0 -21
  47. package/dist/query/memoization.d.ts +0 -18
  48. package/dist/query/projections.d.ts +0 -74
  49. package/dist/query/types.d.ts +0 -260
  50. package/dist/solid/hooks.d.ts +0 -119
  51. package/dist/solid/indices.d.ts +0 -15
  52. package/dist/weather/fetch.d.ts +0 -19
  53. package/dist/weather/query.d.ts +0 -23
  54. package/dist/weather/types.d.ts +0 -126
  55. package/dist/worker/bridge-client.d.ts +0 -47
  56. package/dist/worker/enforcement.d.ts +0 -53
  57. package/dist/worker/protocol.d.ts +0 -129
  58. package/dist/worker/token-store.d.ts +0 -3
@@ -1,112 +0,0 @@
1
- /**
2
- * Demo Energy Simulation
3
- *
4
- * A pure, deterministic model of a solar home: solar production, household
5
- * load with appliance events, a battery that charges on surplus and covers
6
- * deficits, and grid import/export as the residual.
7
- *
8
- * `simulateEnergy(timestampMs)` is the single source of truth. Live ticks,
9
- * day history, and long-term statistics are all derived from it, so every
10
- * widget agrees with every other widget. There is no hidden mutable state:
11
- * the only module-level data is a memoization cache of a pure computation
12
- * (battery SOC integrated from local midnight).
13
- *
14
- * @packageDocumentation
15
- */
16
- /** Every instantaneous value of the home energy system, in watts (SOC in %). */
17
- export interface EnergySample {
18
- solarW: number;
19
- homeW: number;
20
- batteryChargeW: number;
21
- batteryDischargeW: number;
22
- batterySocPct: number;
23
- gridImportW: number;
24
- gridExportW: number;
25
- fridgeW: number;
26
- dishwasherW: number;
27
- washerW: number;
28
- ovenW: number;
29
- evChargerW: number;
30
- alwaysOnW: number;
31
- }
32
- interface LocalTime {
33
- /** Local hour as a fraction (e.g. 13.5 = 13:30). */
34
- hourFrac: number;
35
- /** Minutes since local midnight. */
36
- minuteOfDay: number;
37
- /** 0 = Sunday .. 6 = Saturday. */
38
- dayOfWeek: number;
39
- /** Integer day-of-year-ish key (days since epoch in local time). */
40
- dayKey: number;
41
- }
42
- /** Coarse solar elevation in degrees for sun.sun attributes. */
43
- export declare function sunElevation(lt: LocalTime): number;
44
- /**
45
- * Compute every instantaneous energy value at a timestamp.
46
- *
47
- * Deterministic: equal timestamps always yield deep-equal samples. Obeys the
48
- * conservation invariant
49
- * `solar + gridImport + batteryDischarge === home + gridExport + batteryCharge`
50
- * to within rounding.
51
- */
52
- export declare function simulateEnergy(timestampMs: number): EnergySample;
53
- /** Whether the sun is above the horizon at a timestamp. */
54
- export declare function isSunUp(timestampMs: number): boolean;
55
- /** Next sunrise/sunset ISO strings relative to a timestamp. */
56
- export declare function sunEvents(timestampMs: number): {
57
- nextRising: string;
58
- nextSetting: string;
59
- elevation: number;
60
- };
61
- /** The energy sensor entity ids the simulation drives. */
62
- export declare const ENERGY_ENTITY_IDS: readonly ["sensor.solar_power", "sensor.grid_import_power", "sensor.grid_export_power", "sensor.battery_charge_power", "sensor.battery_discharge_power", "sensor.battery_soc", "sensor.home_power", "sensor.fridge_power", "sensor.dishwasher_power", "sensor.washing_machine_power", "sensor.oven_power", "sensor.ev_charger_power", "sensor.always_on_power"];
63
- export type EnergyEntityId = (typeof ENERGY_ENTITY_IDS)[number];
64
- /** Map an energy entity id to its numeric value from a sample (W, or % for SOC). */
65
- export declare function energyEntityValue(entityId: string, sample: EnergySample): number | undefined;
66
- /** Whether an entity id is one of the simulated energy sensors. */
67
- export declare function isEnergyEntity(entityId: string): boolean;
68
- /** Round to 1 decimal for display-friendly state strings (whole % for SOC). */
69
- export declare function formatEnergyState(entityId: string, value: number): string;
70
- /** A synthesized history point: ms-epoch last-updated + string state. */
71
- export interface DemoHistoryPoint {
72
- /** Unix seconds (HA history wire format). */
73
- lu: number;
74
- /** State value as string. */
75
- s: string;
76
- }
77
- /**
78
- * Synthesize history points for one energy entity by sampling the model across
79
- * the window at a fixed cadence (default 1-minute). Returns HA-compressed
80
- * `{ lu, s }` points with `lu` in Unix seconds.
81
- */
82
- export declare function synthesizeEnergyHistory(entityId: string, startMs: number, endMs: number, stepMs?: number): DemoHistoryPoint[];
83
- /** One synthesized statistics bucket (ms-epoch start/end). */
84
- export interface DemoStatisticBucket {
85
- start: number;
86
- end: number;
87
- mean: number;
88
- min: number;
89
- max: number;
90
- /** Energy in Wh accumulated over the bucket (W-h integration). */
91
- sum: number;
92
- /**
93
- * Energy added during this bucket, in kWh, matching HA's `change` field for
94
- * an energy (kWh) sensor. This is the per-bucket delta (not cumulative), the
95
- * value daily-total consumers read.
96
- */
97
- change: number;
98
- }
99
- /**
100
- * Synthesize statistics buckets for one energy entity across a window.
101
- *
102
- * `mean`/`min`/`max` come from 5-minute power samples in the bucket; `sum` is
103
- * the energy in Wh (mean W times bucket hours). `sum` is cumulative across the
104
- * window, matching HA's monotonically increasing meter semantics.
105
- */
106
- export declare function synthesizeEnergyStatistics(entityId: string, startMs: number, endMs: number, period: "hour" | "day"): DemoStatisticBucket[];
107
- /** The demo energy dashboard preferences wiring the simulated sensors. */
108
- export declare function demoEnergyPreferences(): {
109
- energy_sources: Array<Record<string, unknown>>;
110
- device_consumption: Array<Record<string, unknown>>;
111
- };
112
- export {};
@@ -1,56 +0,0 @@
1
- /**
2
- * Energy Preferences Fetching
3
- *
4
- * Reads HA's energy dashboard config via `energy/get_prefs`.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { SyncLayerConnection } from "../connection/types";
9
- /**
10
- * An energy source entry. Only the fields the widgets read are typed; the
11
- * rest is passthrough. HA emits one of several shapes keyed by `type`:
12
- * - grid: `flow_from[].stat_energy_from`, `flow_to[].stat_energy_to`
13
- * - solar: `stat_energy_from`
14
- * - battery: `stat_energy_from`, `stat_energy_to`
15
- */
16
- export interface EnergySource {
17
- type: "grid" | "solar" | "battery" | "gas" | "water" | string;
18
- stat_energy_from?: string;
19
- stat_energy_to?: string;
20
- flow_from?: Array<{
21
- stat_energy_from: string;
22
- [key: string]: unknown;
23
- }>;
24
- flow_to?: Array<{
25
- stat_energy_to: string;
26
- [key: string]: unknown;
27
- }>;
28
- [key: string]: unknown;
29
- }
30
- /** A device tracked on the energy dashboard. */
31
- export interface EnergyDeviceConsumption {
32
- stat_consumption: string;
33
- name?: string;
34
- [key: string]: unknown;
35
- }
36
- /**
37
- * HA energy dashboard preferences.
38
- *
39
- * Based on HA frontend: EnergyPreferences.
40
- */
41
- export interface EnergyPreferences {
42
- energy_sources: EnergySource[];
43
- device_consumption: EnergyDeviceConsumption[];
44
- [key: string]: unknown;
45
- }
46
- /** Connection surface used by energy prefs fetching. */
47
- type EnergyConnection = Pick<SyncLayerConnection, "sendMessagePromise">;
48
- /**
49
- * Fetch the HA energy dashboard preferences.
50
- *
51
- * Returns `null` when no energy dashboard is configured (HA raises an error
52
- * for `energy/get_prefs` in that case); callers treat `null` as "not
53
- * configured".
54
- */
55
- export declare function fetchEnergyPreferences(connection: EnergyConnection): Promise<EnergyPreferences | null>;
56
- export {};
@@ -1,32 +0,0 @@
1
- /**
2
- * Area View Builder
3
- *
4
- * Constructs unified AreaView objects by combining registry data with computed
5
- * entities and devices.
6
- *
7
- * Membership (which entities/devices belong to an area) is registry-driven and
8
- * cheap; live entity *views* read entity state and are therefore exposed as a
9
- * lazy `entities` getter. Callers that only need names, ids, or counts never
10
- * touch entity state, so building the whole-area list does not recompute on
11
- * every entity state tick.
12
- *
13
- * @packageDocumentation
14
- */
15
- import type { AreaId, AreaView, DeviceRegistryEntry, DeviceView } from "../core/types";
16
- /**
17
- * Build a DeviceView from registry data
18
- */
19
- export declare function buildDeviceView(device: DeviceRegistryEntry): DeviceView;
20
- /**
21
- * Build an AreaView for a single area from registry data.
22
- */
23
- export declare function buildAreaView(areaId: AreaId): AreaView;
24
- /**
25
- * Get all area views. Membership is resolved in a single registry pass; entity
26
- * views stay lazy per area (see `assembleAreaView`).
27
- */
28
- export declare function getAreaViews(): AreaView[];
29
- /**
30
- * Get area view
31
- */
32
- export declare function getAreaView(areaId: AreaId): AreaView | undefined;
@@ -1,54 +0,0 @@
1
- /**
2
- * Entity Index Queries
3
- *
4
- * Provides utilities for querying entities by various criteria.
5
- * In the SolidJS port, indices are NOT stored in state -- they are
6
- * computed on the fly here (and will be derived reactively in Plan 03).
7
- *
8
- * @packageDocumentation
9
- */
10
- import type { AreaId, DeviceId, EntityDomain, EntityId, FloorId, LabelId } from "../core/types";
11
- /**
12
- * Get all entity IDs
13
- */
14
- export declare function getAllEntityIds(): EntityId[];
15
- /**
16
- * Get entities by domain
17
- */
18
- export declare function getEntitiesByDomain(domain: EntityDomain): EntityId[];
19
- /**
20
- * Get entities via devices in area
21
- *
22
- * Only includes entities that inherit area from device (entity.area_id is null).
23
- */
24
- export declare function getEntitiesViaDevices(areaId: AreaId): EntityId[];
25
- /**
26
- * Get entities by area
27
- *
28
- * Returns entities with direct area_id assignments and entities that inherit their area from devices.
29
- */
30
- export declare function getEntitiesByArea(areaId: AreaId): EntityId[];
31
- /**
32
- * Get entities by device
33
- */
34
- export declare function getEntitiesByDevice(deviceId: DeviceId): EntityId[];
35
- /**
36
- * Get entities by floor
37
- */
38
- export declare function getEntitiesByFloor(floorId: FloorId): EntityId[];
39
- /**
40
- * Get entities by label
41
- */
42
- export declare function getEntitiesByLabel(labelId: LabelId): EntityId[];
43
- /**
44
- * Get domain statistics
45
- */
46
- export declare function getDomainStats(): Record<EntityDomain, number>;
47
- /**
48
- * Get area statistics
49
- */
50
- export declare function getAreaStats(): Record<AreaId, number>;
51
- /**
52
- * Get total entity count
53
- */
54
- export declare function getEntityCount(): number;
@@ -1,35 +0,0 @@
1
- /**
2
- * Entity View Builder
3
- *
4
- * Constructs unified EntityView objects by combining runtime state
5
- * with registry metadata.
6
- *
7
- * @packageDocumentation
8
- */
9
- import type { EntityRegistryEntry } from "@glasshome/ha-types";
10
- import type { EntityId, EntityView, HassEntity } from "../core/types";
11
- /**
12
- * Build an EntityView from runtime state and registry metadata
13
- */
14
- export declare function buildEntityView(entity: HassEntity, registry: EntityRegistryEntry | undefined): EntityView;
15
- /**
16
- * Get or build an EntityView
17
- */
18
- export declare function getEntityView(entityId: EntityId): EntityView | undefined;
19
- /**
20
- * Get multiple entity views
21
- */
22
- export declare function getEntityViews(entityIds: EntityId[]): EntityView[];
23
- /**
24
- * Get all entity views
25
- */
26
- export declare function getAllEntityViews(): EntityView[];
27
- /**
28
- * Rebuild entity view
29
- */
30
- export declare function rebuildEntityView(entityId: EntityId): EntityView | undefined;
31
- /**
32
- * Shallow equality check for EntityView.
33
- * Compares fields that affect rendering; skips lastUpdated (heartbeat noise).
34
- */
35
- export declare function entityViewEquals(a: EntityView | undefined, b: EntityView | undefined): boolean;
@@ -1,16 +0,0 @@
1
- /**
2
- * History Constants
3
- *
4
- * Constants and utilities for history fetching and processing.
5
- * Based on Home Assistant frontend implementation.
6
- *
7
- * @packageDocumentation
8
- */
9
- import type { EntityId } from "../core/types";
10
- export declare const DOMAINS_USE_LAST_UPDATED: readonly ["climate", "humidifier", "water_heater"];
11
- export declare const NEED_ATTRIBUTE_DOMAINS: readonly ["climate", "humidifier", "input_datetime", "water_heater", "person", "device_tracker"];
12
- export declare const LINE_ATTRIBUTES_TO_KEEP: readonly ["temperature", "current_temperature", "target_temp_low", "target_temp_high", "hvac_action", "humidity", "mode", "action", "current_humidity"];
13
- /**
14
- * Check if an entity needs attributes in history response
15
- */
16
- export declare function entityIdHistoryNeedsAttributes(entityId: EntityId): boolean;
@@ -1,19 +0,0 @@
1
- /**
2
- * History Fetching
3
- *
4
- * @packageDocumentation
5
- */
6
- import type { EntityId } from "../core/types";
7
- import type { EntityHistoryData, EntityHistoryQueryOptions, EntityHistoryState, HistoryQueryOptions, TimelineState } from "./types";
8
- /**
9
- * Fetch history for entities during a time period
10
- */
11
- export declare function fetchHistory(options: HistoryQueryOptions): Promise<Record<EntityId, EntityHistoryState[]>>;
12
- /**
13
- * Fetch history for a single entity
14
- */
15
- export declare function fetchEntityHistory(entityId: EntityId, options: EntityHistoryQueryOptions): Promise<EntityHistoryData>;
16
- /**
17
- * Convert compressed history state to timeline state
18
- */
19
- export declare function historyStateToTimeline(s: EntityHistoryState): TimelineState;
@@ -1,27 +0,0 @@
1
- import type { EntityId } from "../core/types";
2
- import type { EntityHistoryData, EntityHistoryQueryOptions } from "./types";
3
- export interface HistoryPoint {
4
- entityId: EntityId;
5
- stateValue: string;
6
- attributes: Record<string, unknown>;
7
- lastUpdated: number;
8
- lastChanged?: number;
9
- }
10
- /** Hard cap on retained points per entity timeline. */
11
- export declare const MAX_HISTORY_POINTS = 5760;
12
- /** Check if an entity has active history tracking. */
13
- export declare function isHistoryTracked(entityId: EntityId): boolean;
14
- /** Start tracking history for an entity. Fetches initial backfill. */
15
- export declare function trackEntityHistory(entityId: EntityId, options: EntityHistoryQueryOptions): Promise<EntityHistoryData>;
16
- /** Release one tracker. The entity's data is cleared only when the last one goes. */
17
- export declare function untrackEntityHistory(entityId: EntityId): void;
18
- /**
19
- * Append a state change to an entity's history.
20
- * Called by the entity subscription handler when a tracked entity changes.
21
- */
22
- export declare function appendHistoryPoint(entityId: EntityId, stateValue: string, attributes: Record<string, unknown>, lastUpdated: number, lastChanged?: number): void;
23
- /**
24
- * Append multiple history points in a single setState(produce(...)).
25
- * Called by the rAF-batched subscription flush.
26
- */
27
- export declare function bulkAppendHistoryPoints(points: HistoryPoint[]): void;
@@ -1,55 +0,0 @@
1
- /**
2
- * Long-term Statistics Fetching
3
- *
4
- * Reads HA's recorder long-term statistics via `recorder/statistics_during_period`.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { SyncLayerConnection } from "../connection/types";
9
- /**
10
- * A single statistics bucket for one statistic id.
11
- *
12
- * HA 2023.6+ omits columns that were not requested and may omit null
13
- * columns, so every value field is optional. `start`/`end` are normalized
14
- * to ms epoch numbers regardless of the version's wire format.
15
- */
16
- export interface StatisticValue {
17
- /** Bucket start (ms epoch) */
18
- start: number;
19
- /** Bucket end (ms epoch) */
20
- end: number;
21
- mean?: number;
22
- sum?: number;
23
- min?: number;
24
- max?: number;
25
- state?: number;
26
- change?: number;
27
- }
28
- /** Aggregation period for statistics buckets. */
29
- export type StatisticsPeriod = "5minute" | "hour" | "day" | "week" | "month";
30
- /**
31
- * Options for {@link fetchStatisticsDuringPeriod}.
32
- */
33
- export interface StatisticsQueryOptions {
34
- /** Start time (required) */
35
- startTime: Date;
36
- /** End time (optional, defaults to now on the HA side) */
37
- endTime?: Date;
38
- /** Aggregation period */
39
- period: StatisticsPeriod;
40
- }
41
- /** Connection surface used by statistics fetching. */
42
- type StatisticsConnection = Pick<SyncLayerConnection, "sendMessagePromise">;
43
- /**
44
- * HA returns start/end as ISO strings or ms numbers depending on version.
45
- * Normalize both shapes to ms epoch numbers; unparseable values become NaN.
46
- */
47
- export declare function normalizeStatisticTime(value: unknown): number;
48
- /**
49
- * Fetch long-term statistics for one or more statistic ids during a period.
50
- *
51
- * Statistic ids with no data are returned as empty arrays so callers never
52
- * hit `undefined`.
53
- */
54
- export declare function fetchStatisticsDuringPeriod(connection: StatisticsConnection, statisticIds: string[], options: StatisticsQueryOptions): Promise<Record<string, StatisticValue[]>>;
55
- export {};
@@ -1,146 +0,0 @@
1
- /**
2
- * History Types
3
- *
4
- * Type definitions for entity history data.
5
- * Based on Home Assistant frontend implementation.
6
- *
7
- * @packageDocumentation
8
- */
9
- import type { EntityId } from "../core/types";
10
- /**
11
- * History states record
12
- * Maps entity IDs to their history state arrays
13
- *
14
- * Based on HA frontend: HistoryStates
15
- */
16
- export type HistoryStates = Record<string, EntityHistoryState[]>;
17
- /**
18
- * History stream message
19
- * Used for history/stream subscription
20
- *
21
- * Based on HA frontend: HistoryStreamMessage
22
- */
23
- export interface HistoryStreamMessage {
24
- /** History states */
25
- states: HistoryStates;
26
- /** Start time of this historical chunk (Unix timestamp in seconds) */
27
- start_time?: number;
28
- /** End time of this historical chunk (Unix timestamp in seconds) */
29
- end_time?: number;
30
- }
31
- /**
32
- * Entity history state point
33
- * Represents a single point in entity history from Home Assistant
34
- *
35
- * Based on HA frontend: EntityHistoryState
36
- */
37
- export interface EntityHistoryState {
38
- /** State value (compressed format from HA) */
39
- s: string;
40
- /** Attributes */
41
- a: Record<string, any>;
42
- /** Last changed timestamp (Unix timestamp in seconds, optional; if set, also applies to lu) */
43
- lc?: number;
44
- /** Last updated timestamp (Unix timestamp in seconds) */
45
- lu: number;
46
- }
47
- /**
48
- * Timeline state point
49
- * Represents a point in the timeline with full data
50
- */
51
- export interface TimelineState {
52
- /** Timestamp (Unix timestamp in seconds) */
53
- timestamp: number;
54
- /** State value */
55
- state: string;
56
- /** Attributes */
57
- attributes?: Record<string, any>;
58
- /** Last changed timestamp */
59
- lastChanged?: number;
60
- /** Last updated timestamp */
61
- lastUpdated: number;
62
- }
63
- /**
64
- * History data for a single entity
65
- */
66
- export interface EntityHistoryData {
67
- /** Entity ID */
68
- entityId: EntityId;
69
- /** Timeline data points */
70
- timeline: TimelineState[];
71
- /** Compressed history states (from HA API) */
72
- entityHistory: EntityHistoryState[];
73
- /** Loading state */
74
- loading: boolean;
75
- /** Error if any */
76
- error: Error | null;
77
- /** Last fetched timestamp */
78
- lastFetched: number | null;
79
- }
80
- /**
81
- * History data for multiple entities
82
- */
83
- export interface HistoryData {
84
- /** Entity ID -> History data */
85
- [entityId: EntityId]: EntityHistoryData;
86
- }
87
- /**
88
- * Options for history queries
89
- *
90
- * Based on HA frontend fetchDateWS parameters
91
- */
92
- export interface HistoryQueryOptions {
93
- /** Start time (required) */
94
- startTime: Date;
95
- /** End time (optional, defaults to now) */
96
- endTime?: Date;
97
- /** Entity IDs to query (optional, defaults to all) */
98
- entityIds?: EntityId[];
99
- /** Include start time state */
100
- includeStartTimeState?: boolean;
101
- /** Only significant changes */
102
- significantChangesOnly?: boolean;
103
- /** Minimal response (defaults to true, matching HA frontend) */
104
- minimalResponse?: boolean;
105
- /** No attributes (if not provided, automatically determined based on entity domains) */
106
- noAttributes?: boolean;
107
- }
108
- /**
109
- * Single entity history query options
110
- */
111
- export interface EntityHistoryQueryOptions {
112
- /** Start time (required) */
113
- startTime: Date;
114
- /** End time (optional, defaults to now) */
115
- endTime?: Date;
116
- /** Include start time state */
117
- includeStartTimeState?: boolean;
118
- /** Only significant changes */
119
- significantChangesOnly?: boolean;
120
- /** Minimal response (no attributes) */
121
- minimalResponse?: boolean;
122
- /** No attributes */
123
- noAttributes?: boolean;
124
- }
125
- /**
126
- * History query result
127
- */
128
- export interface HistoryResult {
129
- /** History data for each entity */
130
- data: HistoryData;
131
- /** Loading state */
132
- loading: boolean;
133
- /** Error if any */
134
- error: Error | null;
135
- }
136
- /**
137
- * Single entity history result
138
- */
139
- export interface EntityHistoryResult {
140
- /** History data */
141
- data: EntityHistoryData | null;
142
- /** Loading state */
143
- loading: boolean;
144
- /** Error if any */
145
- error: Error | null;
146
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * One-shot handoff of the host-only surface.
3
- *
4
- * The problem this solves: the host import map serves this package's entry to
5
- * every widget bundle, so everything exported there is callable by untrusted
6
- * widget code. But the host needs privileged operations from the same package —
7
- * connect the bridge, authenticate, disconnect — and it cannot import them
8
- * through a private subpath, because the store must be ONE instance shared with
9
- * widgets. An unserved subpath gets bundled into the host and forks the store
10
- * (finding 45); a served one is reachable by widgets again (finding 46). A
11
- * subpath cannot be both, so hiding is not available.
12
- *
13
- * So the surface stays on the shared entry and is protected by ORDER instead of
14
- * by visibility: `claimHostApi()` yields the API to its first caller and null to
15
- * everyone after. The host claims it while booting; widget bundles are fetched
16
- * and evaluated later, by which point there is nothing left to take.
17
- *
18
- * Why these members are dangerous in a widget's hands:
19
- * - attachBridgeToStore / createHaBridge: install a connection, i.e. replace the
20
- * host's link with one the widget controls — every subsequent service call is
21
- * intercepted and every entity the dashboard renders can be fabricated.
22
- * - authenticateWithOAuth: returns an `Auth` carrying a live access token.
23
- * - disconnect / detachBridgeFromStore: drop the household's connection.
24
- * - loadDemoData / unloadDemoData: overwrite live state with fixtures.
25
- */
26
- import { authenticateWithOAuth } from "./connection/auth";
27
- import { applyBridgeConnState, attachBridgeToStore, detachBridgeFromStore, reloadAfterBridgeReconnect } from "./connection/bridged";
28
- import { disconnect } from "./connection/manager";
29
- import { loadDemoData, unloadDemoData } from "./demo/demo-provider";
30
- import { createHaBridge } from "./worker/bridge-client";
31
- export interface HostApi {
32
- attachBridgeToStore: typeof attachBridgeToStore;
33
- detachBridgeFromStore: typeof detachBridgeFromStore;
34
- applyBridgeConnState: typeof applyBridgeConnState;
35
- reloadAfterBridgeReconnect: typeof reloadAfterBridgeReconnect;
36
- createHaBridge: typeof createHaBridge;
37
- authenticateWithOAuth: typeof authenticateWithOAuth;
38
- disconnect: typeof disconnect;
39
- loadDemoData: typeof loadDemoData;
40
- unloadDemoData: typeof unloadDemoData;
41
- }
42
- /**
43
- * Take the host-only surface. Returns it once; null on every later call.
44
- *
45
- * Call it exactly once, during host boot, and keep the result in a module the
46
- * import map does not serve. Calling it from anywhere else is what this guards
47
- * against, so a null return means something already claimed it — treat that as
48
- * a fatal misconfiguration, not a retry.
49
- */
50
- export declare function claimHostApi(): HostApi | null;
@@ -1,14 +0,0 @@
1
- /**
2
- * Resolve an HA media reference (e.g. an entity's `entity_picture`, a camera
3
- * proxy path) to a URL the page can actually load.
4
- *
5
- * HA gives these as origin-relative paths (`/api/media_player_proxy/...?token=`)
6
- * carrying their own signed token. A bare `<img src>` would resolve them against
7
- * the dash origin and 404. When the host set `mediaProxyBase`, route through the
8
- * same-origin media proxy so the page CSP (`img-src 'self'`) covers it in every
9
- * mode, LAN and remote. Otherwise fall back to prefixing `hassUrl` directly
10
- * (the LAN-only path, used until a transport sets the proxy base).
11
- *
12
- * Absolute URLs and non-path values pass through untouched.
13
- */
14
- export declare function hassMediaUrl(path: string | null | undefined): string | undefined;
@@ -1,25 +0,0 @@
1
- /**
2
- * Area Query Builder
3
- *
4
- * Fluent API for filtering and querying areas.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { AreaId, AreaView, Callback, FloorId, LabelId, PredicateFunc, UnsubscribeFunc } from "../core/types";
9
- export interface AreaQueryBuilder {
10
- byFloor(floorId: FloorId): AreaQueryBuilder;
11
- byLabel(labelId: LabelId): AreaQueryBuilder;
12
- where(predicate: PredicateFunc<AreaView>): AreaQueryBuilder;
13
- orderBy(key: keyof AreaView | string, direction?: "asc" | "desc"): AreaQueryBuilder;
14
- get(): AreaView[];
15
- first(): AreaView | undefined;
16
- subscribe(callback: Callback<AreaView[]>): UnsubscribeFunc;
17
- }
18
- /**
19
- * Create a query builder for areas
20
- */
21
- export declare function areas(): AreaQueryBuilder;
22
- /**
23
- * Create a query for a single area
24
- */
25
- export declare function area(areaId: AreaId): AreaView | undefined;
@@ -1,18 +0,0 @@
1
- /**
2
- * Query Builder
3
- *
4
- * Fluent API for filtering, sorting, projecting, and subscribing to entities.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { EntityId, EntityView } from "../core/types";
9
- import type { EntitiesQueryBuilder, EntityQueryBuilder } from "./types";
10
- /**
11
- * Create a query builder for multiple entities
12
- */
13
- export declare function entities(): EntitiesQueryBuilder<EntityView>;
14
- /**
15
- * Create a query builder for a single entity
16
- */
17
- export declare function entity(entityId: EntityId): EntityQueryBuilder;
18
- export type { EntitiesQueryBuilder, EntityQueryBuilder, UnsubscribeFunc } from "./types";