@glasshome/sync-layer 0.9.0 → 0.10.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.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as HassEntity, C as DeviceRegistryEntry, D as EntityView, E as EntityId, F as StatisticData, I as StatisticMetadata, L as UnsubscribeFunc, M as LabelRegistryEntry, N as MapFunc, O as FloorId, P as PredicateFunc, R as extractDomain, S as DeviceId, T as EntityDomain, _ as AreaId, a as toggle, b as Callback, c as updateEntity, d as EntityUpdateFields, f as ServiceCallContext, g as CalendarWindowOptions, h as CalendarEventsData, i as sendCommand, j as LabelId, k as FloorRegistryEntry, l as CommandOptions, m as CalendarEvent, n as batchServiceCalls, o as turnOff, p as ServiceTarget, r as callService, s as turnOn, t as batchEntityUpdates, u as CommandResult, v as AreaRegistryEntry, w as DeviceView, x as ConnectionState, y as AreaView } from "./service-C8H42I-Q.js";
1
+ import { A as HassEntity, C as DeviceRegistryEntry, D as EntityView, E as EntityId, F as StatisticData, I as StatisticMetadata, L as UnsubscribeFunc, M as LabelRegistryEntry, N as MapFunc, O as FloorId, P as PredicateFunc, R as extractDomain, S as DeviceId, T as EntityDomain, _ as AreaId, a as toggle, b as Callback, c as updateEntity, d as EntityUpdateFields, f as ServiceCallContext, g as CalendarWindowOptions, h as CalendarEventsData, i as sendCommand, j as LabelId, k as FloorRegistryEntry, l as CommandOptions, m as CalendarEvent, n as batchServiceCalls, o as turnOff, p as ServiceTarget, r as callService, s as turnOn, t as batchEntityUpdates, u as CommandResult, v as AreaRegistryEntry, w as DeviceView, x as ConnectionState, y as AreaView } from "./service-B1gegd-N.js";
2
2
  import { WorkerScope, runHaBridgeWorker } from "./worker/worker-main.js";
3
- import { Auth, ConnectionOptions as ConnectionOptions$1 } from "home-assistant-js-websocket";
4
3
  import { Store } from "solid-js/store";
4
+ import { Auth, ConnectionOptions as ConnectionOptions$1 } from "home-assistant-js-websocket";
5
5
  import { CapabilityGrant } from "@glasshome/widget-contract";
6
6
  import { CallServiceRequest, CoreEventType, Domain, EntityCategory, EntityRegistryEntry, EntityRegistryEntry as EntityRegistryEntry$1, EventStateChangedData, HAEvent, HAEvent as HAEvent$1, HassConfig, HassUnitSystem, RegistryEntryDisabler, RegistryEntryHider, ServiceCall, ServiceName, WsCommandType, WsResult } from "@glasshome/ha-types";
7
7
  //#region src/camera/types.d.ts
@@ -440,7 +440,7 @@ interface OAuthOptions {
440
440
  //#endregion
441
441
  //#region src/connection/manager.d.ts
442
442
  /**
443
- * Options for initializing a connection
443
+ * @deprecated Nothing reads these options since the worker bridge became the only connection. Removed in 2.0.0.
444
444
  */
445
445
  interface ConnectionOptions {
446
446
  url: string;
@@ -460,32 +460,13 @@ declare function disconnect(): void;
460
460
  */
461
461
  declare function isConnected(): boolean;
462
462
  /**
463
- * Get the underlying socket's connected flag.
464
- *
465
- * Exposed so apps can render a connection indicator in the UI. Distinct from
466
- * `isConnected()` which reflects the manager's internal lifecycle state.
463
+ * Get the connection's connected flag, for a connection indicator in the UI.
467
464
  */
468
465
  declare function getConnectionState(): boolean;
469
466
  //#endregion
470
467
  //#region src/connection/types.d.ts
471
468
  /**
472
- * Unified connection interface for Home Assistant connections
473
- *
474
- * This interface is implemented by both:
475
- * - MockConnection (for testing)
476
- * - Wrapped HA Connection (for production)
477
- *
478
- * @example
479
- * ```typescript
480
- * // In tests
481
- * const mockConn: SyncLayerConnection = new MockConnection(fixtures);
482
- * await syncLayer.connect({ connection: mockConn });
483
- *
484
- * // In production
485
- * const haConn = await createConnection({ auth });
486
- * const wrappedConn: SyncLayerConnection = wrapHAConnection(haConn);
487
- * await syncLayer.connect({ connection: wrappedConn });
488
- * ```
469
+ * Connection interface the store talks to; implemented by the worker bridge.
489
470
  */
490
471
  interface SyncLayerConnection {
491
472
  /**
@@ -571,7 +552,7 @@ interface SyncLayerConnection {
571
552
  * await unsubscribe();
572
553
  * ```
573
554
  */
574
- subscribeMessage<T>(callback: (message: T) => void, message: any): Promise<() => Promise<void>>;
555
+ subscribeMessage<T>(callback: (message: T) => void, message: unknown): Promise<() => Promise<void>>;
575
556
  /**
576
557
  * Send a message and wait for response
577
558
  *
@@ -588,7 +569,7 @@ interface SyncLayerConnection {
588
569
  * });
589
570
  * ```
590
571
  */
591
- sendMessagePromise<T>(message: any): Promise<T>;
572
+ sendMessagePromise<T>(message: unknown): Promise<T>;
592
573
  /**
593
574
  * Add event listener for WebSocket messages
594
575
  *
@@ -621,25 +602,6 @@ declare global {
621
602
  */
622
603
  declare function registerEntity(entityId: EntityId): () => void;
623
604
  //#endregion
624
- //#region src/query/area-builder.d.ts
625
- interface AreaQueryBuilder$1 {
626
- byFloor(floorId: FloorId): AreaQueryBuilder$1;
627
- byLabel(labelId: LabelId): AreaQueryBuilder$1;
628
- where(predicate: PredicateFunc<AreaView>): AreaQueryBuilder$1;
629
- orderBy(key: keyof AreaView | string, direction?: "asc" | "desc"): AreaQueryBuilder$1;
630
- get(): AreaView[];
631
- first(): AreaView | undefined;
632
- subscribe(callback: Callback<AreaView[]>): UnsubscribeFunc;
633
- }
634
- /**
635
- * Create a query builder for areas
636
- */
637
- declare function areas(): AreaQueryBuilder$1;
638
- /**
639
- * Create a query for a single area
640
- */
641
- declare function area(areaId: AreaId): AreaView | undefined;
642
- //#endregion
643
605
  //#region src/query/types.d.ts
644
606
  /**
645
607
  * Main query builder interface for multiple entities
@@ -795,7 +757,7 @@ interface AreaQueryBuilder {
795
757
  /**
796
758
  * Order results by a key
797
759
  */
798
- orderBy(key: keyof AreaView | string, direction?: "asc" | "desc"): AreaQueryBuilder;
760
+ orderBy(key: keyof AreaView | (string & {}), direction?: "asc" | "desc"): AreaQueryBuilder;
799
761
  /**
800
762
  * Execute query and get results
801
763
  */
@@ -835,6 +797,16 @@ interface EntityQueryBuilder {
835
797
  subscribe(callback: Callback<EntityView | undefined>): UnsubscribeFunc;
836
798
  }
837
799
  //#endregion
800
+ //#region src/query/area-builder.d.ts
801
+ /**
802
+ * Create a query builder for areas
803
+ */
804
+ declare function areas(): AreaQueryBuilder;
805
+ /**
806
+ * Create a query for a single area
807
+ */
808
+ declare function area(areaId: AreaId): AreaView | undefined;
809
+ //#endregion
838
810
  //#region src/query/builder.d.ts
839
811
  /**
840
812
  * Create a query builder for multiple entities
@@ -889,7 +861,7 @@ declare function refreshStream(entityId: EntityId, format?: StreamFormat): Promi
889
861
  * - battery: `stat_energy_from`, `stat_energy_to`
890
862
  */
891
863
  interface EnergySource {
892
- type: "grid" | "solar" | "battery" | "gas" | "water" | string;
864
+ type: "grid" | "solar" | "battery" | "gas" | "water" | (string & {});
893
865
  stat_energy_from?: string;
894
866
  stat_energy_to?: string;
895
867
  flow_from?: Array<{
@@ -1041,7 +1013,7 @@ declare function fetchEntityHistory(entityId: EntityId, options: EntityHistoryQu
1041
1013
  */
1042
1014
  declare function historyStateToTimeline(s: EntityHistoryState): TimelineState;
1043
1015
  //#endregion
1044
- //#region src/history/query.d.ts
1016
+ //#region src/history/points.d.ts
1045
1017
  interface HistoryPoint {
1046
1018
  entityId: EntityId;
1047
1019
  stateValue: string;
@@ -1051,12 +1023,6 @@ interface HistoryPoint {
1051
1023
  }
1052
1024
  /** Hard cap on retained points per entity timeline. */
1053
1025
  declare const MAX_HISTORY_POINTS = 5760;
1054
- /** Check if an entity has active history tracking. */
1055
- declare function isHistoryTracked(entityId: EntityId): boolean;
1056
- /** Start tracking history for an entity. Fetches initial backfill. */
1057
- declare function trackEntityHistory(entityId: EntityId, options: EntityHistoryQueryOptions): Promise<EntityHistoryData>;
1058
- /** Release one tracker. The entity's data is cleared only when the last one goes. */
1059
- declare function untrackEntityHistory(entityId: EntityId): void;
1060
1026
  /**
1061
1027
  * Append a state change to an entity's history.
1062
1028
  * Called by the entity subscription handler when a tracked entity changes.
@@ -1068,6 +1034,14 @@ declare function appendHistoryPoint(entityId: EntityId, stateValue: string, attr
1068
1034
  */
1069
1035
  declare function bulkAppendHistoryPoints(points: HistoryPoint[]): void;
1070
1036
  //#endregion
1037
+ //#region src/history/query.d.ts
1038
+ /** Check if an entity has active history tracking. */
1039
+ declare function isHistoryTracked(entityId: EntityId): boolean;
1040
+ /** Start tracking history for an entity. Fetches initial backfill. */
1041
+ declare function trackEntityHistory(entityId: EntityId, options: EntityHistoryQueryOptions): Promise<EntityHistoryData>;
1042
+ /** Release one tracker. The entity's data is cleared only when the last one goes. */
1043
+ declare function untrackEntityHistory(entityId: EntityId): void;
1044
+ //#endregion
1071
1045
  //#region src/history/statistics.d.ts
1072
1046
  /**
1073
1047
  * A single statistics bucket for one statistic id.
@@ -1148,62 +1122,38 @@ declare function refreshForecast(entityId: EntityId, type: ForecastType): Promis
1148
1122
  */
1149
1123
  declare function refreshForecasts(entityId: EntityId, types: ForecastType[]): Promise<WeatherForecastsData>;
1150
1124
  //#endregion
1151
- //#region src/demo/demo-data.d.ts
1125
+ //#region src/demo/demo-provider.d.ts
1126
+ type DemoClockOption = "live" | {
1127
+ pinned: string;
1128
+ seed: number;
1129
+ timeZone?: string;
1130
+ };
1131
+ interface DemoHouseOptions {
1132
+ clock: DemoClockOption;
1133
+ search?: string;
1134
+ }
1152
1135
  interface DemoFixtures {
1153
1136
  entities: Record<string, HassEntity>;
1154
1137
  entityRegistry: Record<string, EntityRegistryEntry$1>;
1155
1138
  areas: Record<string, AreaRegistryEntry>;
1156
1139
  devices: Record<string, DeviceRegistryEntry>;
1157
1140
  }
1158
- /**
1159
- * Create ~30 curated apartment entity fixtures.
1160
- *
1161
- * Entities span lights, sensors, binary sensors, climate, covers,
1162
- * locks, switches, media player, weather, camera, scenes, and buttons
1163
- * across 6 areas: living_room, bedroom, kitchen, entry, utility, garage.
1164
- */
1165
- declare function createDemoFixtures(): DemoFixtures;
1166
- //#endregion
1167
- //#region src/demo/demo-provider.d.ts
1168
- /**
1169
- * Demo Mode Provider
1170
- *
1171
- * Loads demo fixtures into the SolidJS store and provides
1172
- * optimistic local state updates for service calls (toggle, turnOn, turnOff).
1173
- *
1174
- * @packageDocumentation
1175
- */
1176
- /**
1177
- * Whether demo mode is currently active.
1178
- */
1179
1141
  declare function isDemoMode(): boolean;
1180
- /**
1181
- * Load demo fixtures into the SolidJS store.
1182
- *
1183
- * Populates entities, entity registry, areas, and devices.
1184
- * Sets connection state to "connected" (pretend connected).
1185
- */
1186
- declare function loadDemoData(): Promise<void>;
1187
- /**
1188
- * Unload demo data and reset to disconnected state.
1189
- */
1142
+ declare function loadDemoHouse(opts: DemoHouseOptions): Promise<void>;
1190
1143
  declare function unloadDemoData(): void;
1191
- /**
1192
- * Start the demo energy ticker. Updates the energy sensors and `sun.sun`
1193
- * every 5 seconds. Idempotent: clears any prior interval first. SSR-safe.
1194
- */
1144
+ declare function resetDemo(): Promise<void>;
1145
+ /** @deprecated since 0.10.0, use loadDemoHouse({ clock: "live" }) */
1146
+ declare function loadDemoData(): Promise<void>;
1147
+ /** @deprecated since 0.10.0, the demo ticker starts with loadDemoHouse */
1195
1148
  declare function startDemoEnergyTicker(): void;
1196
- /** Stop the demo energy ticker if running. */
1149
+ /** @deprecated since 0.10.0, the demo ticker stops with unloadDemoData */
1197
1150
  declare function stopDemoEnergyTicker(): void;
1198
- /**
1199
- * Apply an optimistic state update for demo mode.
1200
- *
1201
- * When a service call is made in demo mode, this updates the entity
1202
- * state locally (no WebSocket message sent). State resets on page refresh.
1203
- */
1204
- declare function applyDemoServiceCall(_domain: string, service: string, _serviceData?: Record<string, any>, target?: {
1151
+ /** @deprecated since 0.10.0, service calls reach the demo through callService */
1152
+ declare function applyDemoServiceCall(domain: string, service: string, serviceData?: Record<string, unknown>, target?: {
1205
1153
  entity_id?: string | string[];
1206
1154
  }): void;
1155
+ /** @deprecated since 0.10.0, use loadDemoHouse */
1156
+ declare function createDemoFixtures(): DemoFixtures;
1207
1157
  //#endregion
1208
1158
  //#region src/worker/protocol.d.ts
1209
1159
  type ConnState = "connected" | "disconnected" | "reconnecting";
@@ -1280,6 +1230,8 @@ interface HostApi {
1280
1230
  createHaBridge: typeof createHaBridge;
1281
1231
  disconnect: typeof disconnect;
1282
1232
  loadDemoData: typeof loadDemoData;
1233
+ loadDemoHouse: typeof loadDemoHouse;
1234
+ resetDemo: typeof resetDemo;
1283
1235
  unloadDemoData: typeof unloadDemoData;
1284
1236
  }
1285
1237
  /**
@@ -1295,4 +1247,4 @@ declare function claimHostApi(): HostApi | null;
1295
1247
  //#region src/index.d.ts
1296
1248
  declare const VERSION = "0.2.1";
1297
1249
  //#endregion
1298
- export { type AreaId, type AreaQueryBuilder, type AreaView, type BridgeConnectOptions, type BridgeEvents, BridgeInvalidAuthError, type CalendarEvent, type CalendarEventsData, type CalendarWindowOptions, type CallServiceRequest, type CameraStream, type CameraStreamData, type CameraStreams, type CommandOptions, type CommandResult, type ConnState, type ConnectionOptions, type ConnectionState, type CoreEventType, DOMAINS_USE_LAST_UPDATED, type DeviceId, type DeviceView, type Domain, type EnergyDeviceConsumption, type EnergyPreferences, type EnergySource, type EntitiesQueryBuilder, type EntityCategory, type EntityDomain, type EntityForecastQueryOptions, type EntityHistoryData, type EntityHistoryQueryOptions, type EntityHistoryResult, type EntityHistoryState, type EntityId, type EntityQueryBuilder, type EntityRegistryEntry, type EntityStreamQueryOptions, type EntityUpdateFields, type EntityView, type EventStateChangedData, type ForecastQueryOptions, type ForecastResult, type ForecastType, type ForecastsResult, type GlassHomeState, type HAEvent, type HaBridge, type HassConfig, type HassEntity, type HassUnitSystem, type HistoryData, type HistoryPoint, type HistoryQueryOptions, type HistoryResult, type HistoryStates, type HostApi, LINE_ATTRIBUTES_TO_KEEP, MAX_HISTORY_POINTS, NEED_ATTRIBUTE_DOMAINS, type RegistryEntryDisabler, type RegistryEntryHider, type ServiceCall, type ServiceCallContext, type ServiceName, type ServiceTarget, type StatisticValue, type StatisticsPeriod, type StatisticsQueryOptions, type StreamFormat, type StreamQueryOptions, type StreamResult, type SyncLayerConnection, type TimelineState, type UnsubscribeFunc, VERSION, type WeatherForecast, type WeatherForecastData, type WeatherForecasts, type WeatherForecastsData, type WorkerScope, type WsCommandType, type WsResult, appendHistoryPoint, applyDemoServiceCall, area, areas, batchEntityUpdates, batchServiceCalls, buildAreaView, buildDeviceView, buildEntityView, bulkAppendHistoryPoints, callService, claimHostApi, createDemoFixtures, entities, entitiesByAreaAndDomain, entitiesWhere, entity, entityIdHistoryNeedsAttributes, entityViewEquals, extractDomain, fetchEnergyPreferences, fetchEntityHistory, fetchForecast, fetchForecastData, fetchForecasts, fetchHistory, fetchStatisticsDuringPeriod, fetchStream, fetchStreamData, getAllEntityViews, getAreaView, getAreaViews, getConnectionState, getEntityView, getEntityViews, getForecast, getForecasts, getStream, getWebRtcClientConfig, hassMediaUrl, historyStateToTimeline, isConnected, isDemoMode, isHistoryTracked, normalizeStatisticTime, refreshForecast, refreshForecasts, refreshStream, registerEntity, runHaBridgeWorker, searchEntities, sendCommand, sendWebRtcCandidate, startDemoEnergyTicker, startWebRtcSession, state, stopDemoEnergyTicker, toggle, trackEntityHistory, turnOff, turnOn, untrackEntityHistory, updateEntity };
1250
+ export { type AreaId, type AreaQueryBuilder, type AreaView, type BridgeConnectOptions, type BridgeEvents, BridgeInvalidAuthError, type CalendarEvent, type CalendarEventsData, type CalendarWindowOptions, type CallServiceRequest, type CameraStream, type CameraStreamData, type CameraStreams, type CommandOptions, type CommandResult, type ConnState, type ConnectionOptions, type ConnectionState, type CoreEventType, DOMAINS_USE_LAST_UPDATED, type DemoClockOption, type DemoHouseOptions, type DeviceId, type DeviceView, type Domain, type EnergyDeviceConsumption, type EnergyPreferences, type EnergySource, type EntitiesQueryBuilder, type EntityCategory, type EntityDomain, type EntityForecastQueryOptions, type EntityHistoryData, type EntityHistoryQueryOptions, type EntityHistoryResult, type EntityHistoryState, type EntityId, type EntityQueryBuilder, type EntityRegistryEntry, type EntityStreamQueryOptions, type EntityUpdateFields, type EntityView, type EventStateChangedData, type ForecastQueryOptions, type ForecastResult, type ForecastType, type ForecastsResult, type GlassHomeState, type HAEvent, type HaBridge, type HassConfig, type HassEntity, type HassUnitSystem, type HistoryData, type HistoryPoint, type HistoryQueryOptions, type HistoryResult, type HistoryStates, type HostApi, LINE_ATTRIBUTES_TO_KEEP, MAX_HISTORY_POINTS, NEED_ATTRIBUTE_DOMAINS, type RegistryEntryDisabler, type RegistryEntryHider, type ServiceCall, type ServiceCallContext, type ServiceName, type ServiceTarget, type StatisticValue, type StatisticsPeriod, type StatisticsQueryOptions, type StreamFormat, type StreamQueryOptions, type StreamResult, type SyncLayerConnection, type TimelineState, type UnsubscribeFunc, VERSION, type WeatherForecast, type WeatherForecastData, type WeatherForecasts, type WeatherForecastsData, type WorkerScope, type WsCommandType, type WsResult, appendHistoryPoint, applyDemoServiceCall, area, areas, batchEntityUpdates, batchServiceCalls, buildAreaView, buildDeviceView, buildEntityView, bulkAppendHistoryPoints, callService, claimHostApi, createDemoFixtures, entities, entitiesByAreaAndDomain, entitiesWhere, entity, entityIdHistoryNeedsAttributes, entityViewEquals, extractDomain, fetchEnergyPreferences, fetchEntityHistory, fetchForecast, fetchForecastData, fetchForecasts, fetchHistory, fetchStatisticsDuringPeriod, fetchStream, fetchStreamData, getAllEntityViews, getAreaView, getAreaViews, getConnectionState, getEntityView, getEntityViews, getForecast, getForecasts, getStream, getWebRtcClientConfig, hassMediaUrl, historyStateToTimeline, isConnected, isDemoMode, isHistoryTracked, normalizeStatisticTime, refreshForecast, refreshForecasts, refreshStream, registerEntity, runHaBridgeWorker, searchEntities, sendCommand, sendWebRtcCandidate, startDemoEnergyTicker, startWebRtcSession, state, stopDemoEnergyTicker, toggle, trackEntityHistory, turnOff, turnOn, untrackEntityHistory, updateEntity };