@glasshome/sync-layer 0.9.0 → 0.9.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.
package/README.md CHANGED
@@ -15,23 +15,10 @@ bun add @glasshome/sync-layer @glasshome/ha-types
15
15
  ## Quick Start
16
16
 
17
17
  ```typescript
18
- import {
19
- initConnection,
20
- getConnection,
21
- state,
22
- entity,
23
- entities,
24
- callService,
25
- } from "@glasshome/sync-layer";
26
-
27
- // Connect to Home Assistant
28
- await initConnection({
29
- hassUrl: "http://homeassistant.local:8123",
30
- token: "YOUR_LONG_LIVED_ACCESS_TOKEN",
31
- });
18
+ import { entity, entities, callService } from "@glasshome/sync-layer";
32
19
 
33
- // Access reactive state
34
- console.log(state.connectionState); // "connected"
20
+ // The host app (GlassHome Dash) owns the Home Assistant connection: it runs the
21
+ // worker-backed bridge through claimHostApi(). Widgets only read and call.
35
22
 
36
23
  // Query a single entity
37
24
  const light = entity("light.living_room").get();
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<{
@@ -1201,7 +1173,7 @@ declare function stopDemoEnergyTicker(): void;
1201
1173
  * When a service call is made in demo mode, this updates the entity
1202
1174
  * state locally (no WebSocket message sent). State resets on page refresh.
1203
1175
  */
1204
- declare function applyDemoServiceCall(_domain: string, service: string, _serviceData?: Record<string, any>, target?: {
1176
+ declare function applyDemoServiceCall(_domain: string, service: string, serviceData?: Record<string, any>, target?: {
1205
1177
  entity_id?: string | string[];
1206
1178
  }): void;
1207
1179
  //#endregion