@glasshome/sync-layer 0.7.1 → 0.8.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.
Files changed (58) hide show
  1. package/dist/index.d.ts +1291 -54
  2. package/dist/index.js +215 -308
  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 +3 -3
  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,21 +0,0 @@
1
- /**
2
- * Query Engine Helpers
3
- *
4
- * Helper functions to make query engine usage easier and more intuitive.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { AreaId, EntityDomain, EntityView } from "../core/types";
9
- import type { EntitiesQueryBuilder } from "./types";
10
- /**
11
- * Create a search query builder
12
- */
13
- export declare function searchEntities(searchText: string): EntitiesQueryBuilder<EntityView>;
14
- /**
15
- * Create a query for entities in an area by domain
16
- */
17
- export declare function entitiesByAreaAndDomain(areaId: AreaId, domain: EntityDomain): EntitiesQueryBuilder<EntityView>;
18
- /**
19
- * Create a query for entities matching a predicate
20
- */
21
- export declare function entitiesWhere(predicate: (entity: EntityView) => boolean): EntitiesQueryBuilder<EntityView>;
@@ -1,18 +0,0 @@
1
- /**
2
- * Query memoization
3
- *
4
- * @packageDocumentation
5
- */
6
- import type { QueryState } from "./types";
7
- /**
8
- * Build a unique signature for a query
9
- */
10
- export declare function buildQuerySignature(query: QueryState): string;
11
- /**
12
- * Execute query (no caching -- SolidJS createMemo handles this in Plan 03)
13
- */
14
- export declare function memoizedExecute<T>(_signature: string, compute: () => T): T;
15
- /**
16
- * Check if cache should be invalidated
17
- */
18
- export declare function isCacheStale(lastCheck: number, maxAge: number): boolean;
@@ -1,74 +0,0 @@
1
- /**
2
- * Projection utilities
3
- *
4
- * Functions for transforming entity views into different shapes.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { EntityId, EntityView, MapFunc } from "../core/types";
9
- /**
10
- * Project entities to IDs only
11
- *
12
- * @param entities - Array of entity views
13
- * @returns Array of entity IDs
14
- */
15
- export declare function projectToIds(entities: EntityView[]): EntityId[];
16
- /**
17
- * Pick specific fields from entities
18
- *
19
- * @param entities - Array of entity views
20
- * @param keys - Array of field names to include
21
- * @returns Array of objects with only specified fields
22
- */
23
- export declare function projectPick<K extends keyof EntityView>(entities: EntityView[], keys: K[]): Pick<EntityView, K>[];
24
- /**
25
- * Pluck a single field from entities
26
- *
27
- * Supports dot-notation for nested fields (e.g., "attributes.brightness")
28
- *
29
- * @param entities - Array of entity views
30
- * @param key - Field name or dot-path to extract
31
- * @returns Array of field values
32
- */
33
- export declare function projectPluck(entities: EntityView[], key: string): any[];
34
- /**
35
- * Map entities using a custom function
36
- *
37
- * @param entities - Array of entity views
38
- * @param mapper - Function to transform each entity
39
- * @returns Array of mapped values
40
- */
41
- export declare function projectMap<R>(entities: EntityView[], mapper: MapFunc<EntityView, R>): R[];
42
- /**
43
- * Get nested value from object using dot-notation
44
- *
45
- * @param obj - Object to extract value from
46
- * @param path - Dot-notation path (e.g., "attributes.brightness")
47
- * @returns Value at path or undefined
48
- *
49
- * @example
50
- * ```typescript
51
- * const entity = { attributes: { brightness: 255 } };
52
- * getNestedValue(entity, "attributes.brightness"); // 255
53
- * ```
54
- */
55
- export declare function getNestedValue(obj: any, path: string): any;
56
- /**
57
- * Set nested value in object using dot-notation
58
- *
59
- * @param obj - Object to set value in
60
- * @param path - Dot-notation path
61
- * @param value - Value to set
62
- *
63
- * @internal
64
- */
65
- export declare function setNestedValue(obj: any, path: string, value: any): void;
66
- /**
67
- * Check if a value is a primitive
68
- *
69
- * @param value - Value to check
70
- * @returns True if primitive
71
- *
72
- * @internal
73
- */
74
- export declare function isPrimitive(value: any): boolean;
@@ -1,260 +0,0 @@
1
- /**
2
- * Query-related types
3
- *
4
- * Type definitions for the query builder system.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { AreaId, AreaView, Callback, DeviceId, EntityDomain, EntityId, EntityView, FloorId, LabelId, MapFunc, PredicateFunc, UnsubscribeFunc } from "../core/types";
9
- export type { UnsubscribeFunc };
10
- /**
11
- * Main query builder interface for multiple entities
12
- *
13
- * Provides a fluent API for filtering, sorting, projecting, and subscribing.
14
- *
15
- * @template T - The result type (defaults to EntityView)
16
- */
17
- export interface EntitiesQueryBuilder<T = EntityView> {
18
- /**
19
- * Filter by area
20
- *
21
- * @param areaId - Area ID to filter by
22
- * @returns Query builder for chaining
23
- */
24
- byArea(areaId: AreaId): EntitiesQueryBuilder<T>;
25
- /**
26
- * Filter by domain
27
- *
28
- * @param domain - Domain to filter by (e.g., "light", "sensor")
29
- * @returns Query builder for chaining
30
- */
31
- byDomain(domain: EntityDomain): EntitiesQueryBuilder<T>;
32
- /**
33
- * Filter by device
34
- *
35
- * @param deviceId - Device ID to filter by
36
- * @returns Query builder for chaining
37
- */
38
- byDevice(deviceId: DeviceId): EntitiesQueryBuilder<T>;
39
- /**
40
- * Filter by floor
41
- *
42
- * @param floorId - Floor ID to filter by
43
- * @returns Query builder for chaining
44
- */
45
- byFloor(floorId: FloorId): EntitiesQueryBuilder<T>;
46
- /**
47
- * Filter by label
48
- *
49
- * @param labelId - Label ID to filter by
50
- * @returns Query builder for chaining
51
- */
52
- byLabel(labelId: LabelId): EntitiesQueryBuilder<T>;
53
- /**
54
- * Filter with custom predicate
55
- *
56
- * @param predicate - Function to test each entity
57
- * @returns Query builder for chaining
58
- */
59
- where(predicate: PredicateFunc<EntityView>): EntitiesQueryBuilder<T>;
60
- /**
61
- * Search entities by text (searches id, name, friendlyName)
62
- *
63
- * @param searchText - Text to search for
64
- * @returns Query builder for chaining
65
- */
66
- search(searchText: string): EntitiesQueryBuilder<T>;
67
- /**
68
- * Sort results
69
- *
70
- * @param key - Property key or dot-path (e.g., "name", "attributes.brightness")
71
- * @param direction - Sort direction ("asc" or "desc")
72
- * @returns Query builder for chaining
73
- */
74
- orderBy(key: string, direction?: "asc" | "desc"): EntitiesQueryBuilder<T>;
75
- /**
76
- * Project to entity IDs only
77
- *
78
- * @returns Query builder for entity IDs
79
- */
80
- ids(): EntitiesQueryBuilder<EntityId>;
81
- /**
82
- * Pick specific fields
83
- *
84
- * @param keys - Array of field names to include
85
- * @returns Query builder with picked fields
86
- */
87
- pick<K extends keyof EntityView>(keys: K[]): EntitiesQueryBuilder<Pick<EntityView, K>>;
88
- /**
89
- * Extract a single field from each entity
90
- *
91
- * @param key - Field name to extract
92
- * @returns Query builder for field values
93
- */
94
- pluck<K extends keyof EntityView>(key: K): EntitiesQueryBuilder<EntityView[K]>;
95
- /**
96
- * Map entities to new values
97
- *
98
- * @param mapper - Function to transform each entity
99
- * @returns Query builder for mapped values
100
- */
101
- map<R>(mapper: MapFunc<EntityView, R>): EntitiesQueryBuilder<R>;
102
- /**
103
- * Limit the number of results
104
- *
105
- * @param limit - Maximum number of results to return
106
- * @returns Query builder for chaining
107
- */
108
- take(limit: number): EntitiesQueryBuilder<T>;
109
- /**
110
- * Skip a number of results (for pagination)
111
- *
112
- * @param count - Number of results to skip
113
- * @returns Query builder for chaining
114
- */
115
- skip(count: number): EntitiesQueryBuilder<T>;
116
- /**
117
- * Get distinct values by a key
118
- *
119
- * @param key - Field name or dot-path to get distinct values for
120
- * @returns Query builder for distinct values
121
- */
122
- distinct(key: string): EntitiesQueryBuilder<T>;
123
- /**
124
- * Execute query and return results
125
- *
126
- * @returns Array of results
127
- */
128
- get(): T[];
129
- /**
130
- * Get first result
131
- *
132
- * @returns First result or undefined
133
- */
134
- first(): T | undefined;
135
- /**
136
- * Subscribe to query results
137
- *
138
- * Receives updates when entities matching the query change.
139
- *
140
- * @param callback - Function called with results
141
- * @returns Unsubscribe function
142
- */
143
- subscribe(callback: Callback<T[]>): UnsubscribeFunc;
144
- }
145
- /**
146
- * Query builder interface for areas
147
- */
148
- export interface AreaQueryBuilder {
149
- /**
150
- * Filter areas by floor
151
- */
152
- byFloor(floorId: FloorId): AreaQueryBuilder;
153
- /**
154
- * Filter areas by label
155
- */
156
- byLabel(labelId: LabelId): AreaQueryBuilder;
157
- /**
158
- * Filter areas using a predicate
159
- */
160
- where(predicate: PredicateFunc<AreaView>): AreaQueryBuilder;
161
- /**
162
- * Order results by a key
163
- */
164
- orderBy(key: keyof AreaView | string, direction?: "asc" | "desc"): AreaQueryBuilder;
165
- /**
166
- * Execute query and get results
167
- */
168
- get(): AreaView[];
169
- /**
170
- * Get first result
171
- */
172
- first(): AreaView | undefined;
173
- /**
174
- * Subscribe to query results
175
- */
176
- subscribe(callback: Callback<AreaView[]>): UnsubscribeFunc;
177
- }
178
- /**
179
- * Query builder interface for a single entity
180
- */
181
- export interface EntityQueryBuilder {
182
- /**
183
- * Get entity view
184
- *
185
- * @returns Entity view or undefined
186
- */
187
- get(): EntityView | undefined;
188
- /**
189
- * Extract a single field
190
- *
191
- * @param key - Field name to extract
192
- * @returns Field value or undefined
193
- */
194
- pluck<K extends keyof EntityView>(key: K): EntityView[K] | undefined;
195
- /**
196
- * Subscribe to entity changes
197
- *
198
- * @param callback - Function called with entity view
199
- * @returns Unsubscribe function
200
- */
201
- subscribe(callback: Callback<EntityView | undefined>): UnsubscribeFunc;
202
- }
203
- /**
204
- * Internal query state (not exported)
205
- *
206
- * @internal
207
- */
208
- export interface QueryState {
209
- /** Index-based filters (use indices for fast lookup) */
210
- indexFilters: IndexFilter[];
211
- /** Predicate-based filters (run on each entity) */
212
- predicateFilters: PredicateFunc<EntityView>[];
213
- /** Sort functions */
214
- sorts: SortConfig[];
215
- /** Projection configuration */
216
- projection?: ProjectionConfig;
217
- /** Search text (for text search functionality) */
218
- searchText?: string;
219
- /** Limit number of results */
220
- take?: number;
221
- /** Skip number of results (for pagination) */
222
- skip?: number;
223
- /** Distinct key for deduplication */
224
- distinct?: string;
225
- }
226
- /**
227
- * Index filter (uses store indices for fast lookup)
228
- *
229
- * @internal
230
- */
231
- export interface IndexFilter {
232
- type: "domain" | "area" | "device" | "floor" | "label";
233
- value: string;
234
- }
235
- /**
236
- * Sort configuration
237
- *
238
- * @internal
239
- */
240
- export interface SortConfig {
241
- key: string;
242
- direction: "asc" | "desc";
243
- }
244
- /**
245
- * Projection configuration
246
- *
247
- * @internal
248
- */
249
- export type ProjectionConfig = {
250
- type: "ids";
251
- } | {
252
- type: "pick";
253
- keys: string[];
254
- } | {
255
- type: "pluck";
256
- key: string;
257
- } | {
258
- type: "map";
259
- mapper: MapFunc<EntityView, any>;
260
- };
@@ -1,119 +0,0 @@
1
- /**
2
- * SolidJS Hooks for Sync-Layer
3
- *
4
- * Thin createMemo wrappers over the native SolidJS store.
5
- * Since the store IS SolidJS (Plan 01 replaced Zustand with createStore),
6
- * no subscription bridge is needed -- SolidJS auto-tracks fine-grained
7
- * reactivity through the store proxy.
8
- *
9
- * Every hook is just `createMemo(() => state.something)`.
10
- *
11
- * @packageDocumentation
12
- */
13
- import type { HassConfig, HassUnitSystem } from "@glasshome/ha-types";
14
- import type { Accessor, Resource } from "solid-js";
15
- import type { AreaView, CameraStreamData, ConnectionState, EntityHistoryData, EntityView, GlassHomeState, HassEntity, StatisticsQueryOptions, StatisticValue, WeatherForecastsData } from "@glasshome/sync-layer";
16
- import { callService, toggle, turnOff, turnOn } from "../commands/service";
17
- import type { CalendarEventsData, CalendarWindowOptions } from "../calendar/types";
18
- /**
19
- * Get a reactive EntityView for an entity ID.
20
- *
21
- * Registers the entity for live updates via the subscription manager.
22
- * Only re-runs when the specific entity's data changes.
23
- */
24
- export declare function useEntity(entityId: Accessor<string> | string): Accessor<EntityView | undefined>;
25
- /**
26
- * Get reactive EntityViews for multiple entity IDs.
27
- *
28
- * Registers all entity IDs for live updates via the subscription manager.
29
- */
30
- export declare function useEntities(entityIds: Accessor<string[]>): Accessor<EntityView[]>;
31
- /**
32
- * Get raw HassEntity state (without EntityView transformation).
33
- *
34
- * Registers the entity for live updates via the subscription manager.
35
- */
36
- export declare function useEntityState(entityId: Accessor<string> | string): Accessor<HassEntity | undefined>;
37
- /**
38
- * Get reactive connection status.
39
- */
40
- export declare function useConnection(): {
41
- status: Accessor<ConnectionState>;
42
- isConnected: Accessor<boolean>;
43
- };
44
- /** Reactive Home Assistant core config (null until loaded). */
45
- export declare function useHassConfig(): Accessor<HassConfig | null>;
46
- /** Reactive HA unit system (length/mass/temperature/volume), or null until loaded. */
47
- export declare function useUnitSystem(): Accessor<HassUnitSystem | null>;
48
- /** Reactive temperature unit from HA config, including the degree sign. Defaults to "°C". */
49
- export declare function useTemperatureUnit(): Accessor<string>;
50
- /** Reactive UI locale (BCP 47 tag) from HA config. Defaults to "en". */
51
- export declare function useLocale(): Accessor<string>;
52
- /** Reactive currency (ISO 4217) from HA config. Defaults to "USD". */
53
- export declare function useCurrency(): Accessor<string>;
54
- /**
55
- * Get all service call functions.
56
- */
57
- export declare function useService(): {
58
- callService: typeof callService;
59
- turnOn: typeof turnOn;
60
- turnOff: typeof turnOff;
61
- toggle: typeof toggle;
62
- };
63
- /** Get turnOn command function */
64
- export declare function useTurnOn(): typeof turnOn;
65
- /** Get turnOff command function */
66
- export declare function useTurnOff(): typeof turnOff;
67
- /** Get toggle command function */
68
- export declare function useToggle(): typeof toggle;
69
- /**
70
- * Get reactive list of all area views.
71
- */
72
- export declare function useAreas(): Accessor<AreaView[]>;
73
- /**
74
- * Get a reactive AreaView for a specific area.
75
- *
76
- * Registers all entities in the area for live updates.
77
- */
78
- export declare function useArea(areaId: Accessor<string> | string): Accessor<AreaView | undefined>;
79
- /**
80
- * Get reactive entity history data.
81
- *
82
- * History data is populated into the store via subscriptions;
83
- * this hook simply reads it reactively.
84
- */
85
- export declare function useEntityHistory(entityId: Accessor<string> | string): Accessor<EntityHistoryData | undefined>;
86
- /**
87
- * Get reactive long-term statistics for a statistic id.
88
- *
89
- * Fetches via `recorder/statistics_during_period` and re-fetches whenever the
90
- * statistic id or options change. The returned Resource exposes `.loading`
91
- * and `.error` alongside the value accessor.
92
- */
93
- export declare function useEntityStatistics(statisticId: Accessor<string> | string, options: Accessor<StatisticsQueryOptions> | StatisticsQueryOptions): Resource<StatisticValue[]>;
94
- /**
95
- * Get reactive camera stream data.
96
- */
97
- export declare function useCamera(entityId: Accessor<string> | string): {
98
- stream: Accessor<CameraStreamData | null>;
99
- refresh: () => void;
100
- };
101
- /**
102
- * Live calendar events for one calendar entity.
103
- *
104
- * Tracks the entity on mount (opening or joining the shared
105
- * `calendar/event/subscribe`) and untracks on cleanup; HA pushes the initial
106
- * snapshot and every later change, so the accessor is reactive with no
107
- * polling. `undefined` until the subscription is established.
108
- */
109
- export declare function useCalendarEvents(entityId: Accessor<string> | string, options?: CalendarWindowOptions): Accessor<CalendarEventsData | undefined>;
110
- /**
111
- * Get reactive weather forecast data.
112
- */
113
- export declare function useForecast(entityId: Accessor<string> | string): Accessor<WeatherForecastsData | undefined>;
114
- /**
115
- * Escape hatch for direct store access with a selector.
116
- *
117
- * Use when no specific hook exists for your data need.
118
- */
119
- export declare function useStore<T>(selector: (s: GlassHomeState) => T): Accessor<T>;
@@ -1,15 +0,0 @@
1
- /** Reactive derived entity indices. Each call reads from the SolidJS store directly,
2
- * so consumers wrap in createMemo within their own reactive root for memoization. */
3
- import type { Accessor } from "solid-js";
4
- /** Entity IDs grouped by domain (e.g., "light" -> ["light.living_room", ...]) */
5
- export declare const byDomain: Accessor<Record<string, string[]>>;
6
- /** Entity IDs grouped by area (via entity registry area_id) */
7
- export declare const byArea: Accessor<Record<string, string[]>>;
8
- /** Entity IDs grouped by device (via entity registry device_id) */
9
- export declare const byDevice: Accessor<Record<string, string[]>>;
10
- /** Entity IDs grouped by floor (device -> area -> floor chain) */
11
- export declare const byFloor: Accessor<Record<string, string[]>>;
12
- /** Entity IDs grouped by label */
13
- export declare const byLabel: Accessor<Record<string, string[]>>;
14
- /** All entity IDs currently in the store */
15
- export declare const allEntityIds: Accessor<string[]>;
@@ -1,19 +0,0 @@
1
- /**
2
- * Weather Forecast Fetching
3
- *
4
- * @packageDocumentation
5
- */
6
- import type { EntityId } from "../core/types";
7
- import type { ForecastType, WeatherForecast, WeatherForecastData, WeatherForecastsData } from "./types";
8
- /**
9
- * Fetch forecast for a single entity and type
10
- */
11
- export declare function fetchForecast(entityId: EntityId, type: ForecastType): Promise<WeatherForecast[]>;
12
- /**
13
- * Fetch forecasts for a single entity and multiple types
14
- */
15
- export declare function fetchForecasts(entityId: EntityId, types: ForecastType[]): Promise<WeatherForecastsData>;
16
- /**
17
- * Fetch forecast data with error handling
18
- */
19
- export declare function fetchForecastData(entityId: EntityId, type: ForecastType): Promise<WeatherForecastData>;
@@ -1,23 +0,0 @@
1
- /**
2
- * Weather Forecast Query Builder
3
- *
4
- * @packageDocumentation
5
- */
6
- import type { EntityId } from "../core/types";
7
- import type { ForecastType, WeatherForecastData, WeatherForecastsData } from "./types";
8
- /**
9
- * Get forecast for a single entity and type
10
- */
11
- export declare function getForecast(entityId: EntityId, type: ForecastType): Promise<WeatherForecastData>;
12
- /**
13
- * Get forecasts for a single entity and multiple types
14
- */
15
- export declare function getForecasts(entityId: EntityId, types: ForecastType[]): Promise<WeatherForecastsData>;
16
- /**
17
- * Refresh forecast
18
- */
19
- export declare function refreshForecast(entityId: EntityId, type: ForecastType): Promise<WeatherForecastData>;
20
- /**
21
- * Refresh forecasts
22
- */
23
- export declare function refreshForecasts(entityId: EntityId, types: ForecastType[]): Promise<WeatherForecastsData>;
@@ -1,126 +0,0 @@
1
- /**
2
- * Weather Types
3
- *
4
- * Type definitions for weather forecast data.
5
- *
6
- * @packageDocumentation
7
- */
8
- import type { EntityId } from "../core/types";
9
- /**
10
- * Forecast type
11
- * Supported forecast types from Home Assistant Weather API
12
- */
13
- export type ForecastType = "hourly" | "daily" | "twice_daily";
14
- /**
15
- * Weather forecast entry
16
- * Represents a single forecast point from Home Assistant
17
- */
18
- export interface WeatherForecast {
19
- /** Forecast datetime (ISO 8601) */
20
- datetime: string;
21
- /** Temperature (in unit system) */
22
- temperature?: number;
23
- /** Temperature low (for daily forecasts) */
24
- temp_low?: number;
25
- /** Temperature high (for daily forecasts) */
26
- temp_high?: number;
27
- /** Humidity percentage */
28
- humidity?: number;
29
- /** Wind bearing (degrees) */
30
- wind_bearing?: number;
31
- /** Wind speed (in unit system) */
32
- wind_speed?: number;
33
- /** Precipitation probability (0-100) */
34
- precipitation?: number;
35
- /** Precipitation amount (in unit system) */
36
- precipitation_probability?: number;
37
- /** Condition (e.g., "sunny", "cloudy", "rainy") */
38
- condition?: string;
39
- /** Pressure (in unit system) */
40
- pressure?: number;
41
- /** Cloud coverage (0-100) */
42
- cloud_coverage?: number;
43
- /** UV index */
44
- uv_index?: number;
45
- /** Additional forecast data */
46
- [key: string]: any;
47
- }
48
- /**
49
- * Weather forecast data for a single type
50
- */
51
- export interface WeatherForecastData {
52
- /** Entity ID */
53
- entityId: EntityId;
54
- /** Forecast type */
55
- type: ForecastType;
56
- /** Forecast entries */
57
- forecast: WeatherForecast[];
58
- /** Loading state */
59
- loading: boolean;
60
- /** Error if any */
61
- error: Error | null;
62
- /** Last fetched timestamp */
63
- lastFetched: number | null;
64
- }
65
- /**
66
- * Weather forecast data for multiple types
67
- */
68
- export interface WeatherForecastsData {
69
- /** Entity ID */
70
- entityId: EntityId;
71
- /** Forecast data by type */
72
- forecasts: Partial<Record<ForecastType, WeatherForecast[]>>;
73
- /** Loading states by type */
74
- loading: Partial<Record<ForecastType, boolean>>;
75
- /** Errors by type */
76
- errors: Partial<Record<ForecastType, Error | null>>;
77
- /** Last fetched timestamps by type */
78
- lastFetched: Partial<Record<ForecastType, number | null>>;
79
- }
80
- /**
81
- * Weather forecast data for multiple entities
82
- */
83
- export interface WeatherForecasts {
84
- /** Entity ID -> Forecast data */
85
- [entityId: EntityId]: WeatherForecastsData;
86
- }
87
- /**
88
- * Options for forecast queries
89
- */
90
- export interface ForecastQueryOptions {
91
- /** Forecast type(s) to fetch */
92
- type?: ForecastType;
93
- /** Multiple forecast types to fetch */
94
- types?: ForecastType[];
95
- }
96
- /**
97
- * Single entity forecast query options
98
- */
99
- export interface EntityForecastQueryOptions {
100
- /** Forecast type(s) to fetch */
101
- type?: ForecastType;
102
- /** Multiple forecast types to fetch */
103
- types?: ForecastType[];
104
- }
105
- /**
106
- * Forecast query result for a single type
107
- */
108
- export interface ForecastResult {
109
- /** Forecast data */
110
- data: WeatherForecastData | null;
111
- /** Loading state */
112
- loading: boolean;
113
- /** Error if any */
114
- error: Error | null;
115
- }
116
- /**
117
- * Forecast query result for multiple types
118
- */
119
- export interface ForecastsResult {
120
- /** Forecast data */
121
- data: WeatherForecastsData | null;
122
- /** Loading states by type */
123
- loading: Partial<Record<ForecastType, boolean>>;
124
- /** Errors by type */
125
- errors: Partial<Record<ForecastType, Error | null>>;
126
- }