@glasshome/sync-layer 0.4.0 → 0.5.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/connection/types.d.ts +0 -10
- package/dist/index.js +1340 -17
- package/dist/worker/worker-main.js +1 -1
- package/package.json +1 -6
- package/dist/demo-data-CcG2efdQ.js +0 -1225
- package/dist/testing/fixtures.d.ts +0 -161
- package/dist/testing/helpers.d.ts +0 -160
- package/dist/testing/index.d.ts +0 -13
- package/dist/testing/index.js +0 -2067
- package/dist/testing/mock-behaviors/base.d.ts +0 -73
- package/dist/testing/mock-behaviors/climate.d.ts +0 -22
- package/dist/testing/mock-behaviors/cover.d.ts +0 -22
- package/dist/testing/mock-behaviors/index.d.ts +0 -11
- package/dist/testing/mock-behaviors/light.d.ts +0 -20
- package/dist/testing/mock-behaviors/lock.d.ts +0 -20
- package/dist/testing/mock-behaviors/media_player.d.ts +0 -42
- package/dist/testing/mock-behaviors/registry.d.ts +0 -55
- package/dist/testing/mock-behaviors/switch.d.ts +0 -17
- package/dist/testing/mock.d.ts +0 -196
- package/dist/testing/types.d.ts +0 -87
- /package/dist/{worker-main-DTbzEKor.js → worker-main-Cf-k4f2N.js} +0 -0
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fixture utilities
|
|
3
|
-
*
|
|
4
|
-
* Helper functions for creating and loading test fixtures.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
export { createDemoFixtures } from "../demo/demo-data";
|
|
9
|
-
import type { EntityRegistryEntry } from "@glasshome/ha-types";
|
|
10
|
-
import type { HassEntity } from "../core/types";
|
|
11
|
-
import type { EntityHistoryState } from "../history/types";
|
|
12
|
-
import type { AreaRegistryEntry, DeviceRegistryEntry, Fixtures, FloorRegistryEntry, LabelRegistryEntry } from "./types";
|
|
13
|
-
/**
|
|
14
|
-
* Create a mock entity state
|
|
15
|
-
*
|
|
16
|
-
* @param entityId - Entity ID
|
|
17
|
-
* @param overrides - Optional field overrides
|
|
18
|
-
* @returns Mock entity state
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const light = createEntity('light.kitchen', {
|
|
23
|
-
* state: 'on',
|
|
24
|
-
* attributes: { brightness: 255 },
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare function createEntity(entityId: string, overrides?: Partial<HassEntity>): HassEntity;
|
|
29
|
-
/**
|
|
30
|
-
* Create a mock entity registry entry
|
|
31
|
-
*
|
|
32
|
-
* @param entityId - Entity ID
|
|
33
|
-
* @param overrides - Optional field overrides
|
|
34
|
-
* @returns Mock registry entry
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const entry = createEntityRegistryEntry('light.kitchen', {
|
|
39
|
-
* name: 'Kitchen Light',
|
|
40
|
-
* area_id: 'kitchen',
|
|
41
|
-
* });
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function createEntityRegistryEntry(entityId: string, overrides?: Partial<EntityRegistryEntry>): EntityRegistryEntry;
|
|
45
|
-
/**
|
|
46
|
-
* Create a mock area registry entry
|
|
47
|
-
*
|
|
48
|
-
* @param areaId - Area ID
|
|
49
|
-
* @param overrides - Optional field overrides
|
|
50
|
-
* @returns Mock area entry
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const area = createArea('kitchen', {
|
|
55
|
-
* name: 'Kitchen',
|
|
56
|
-
* floor_id: 'ground_floor',
|
|
57
|
-
* });
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare function createArea(areaId: string, overrides?: Partial<AreaRegistryEntry>): AreaRegistryEntry;
|
|
61
|
-
/**
|
|
62
|
-
* Create a mock device registry entry
|
|
63
|
-
*
|
|
64
|
-
* @param deviceId - Device ID
|
|
65
|
-
* @param overrides - Optional field overrides
|
|
66
|
-
* @returns Mock device entry
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* const device = createDevice('device_123', {
|
|
71
|
-
* name: 'Smart Light',
|
|
72
|
-
* area_id: 'kitchen',
|
|
73
|
-
* });
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export declare function createDevice(deviceId: string, overrides?: Partial<DeviceRegistryEntry>): DeviceRegistryEntry;
|
|
77
|
-
/**
|
|
78
|
-
* Create a mock floor registry entry
|
|
79
|
-
*
|
|
80
|
-
* @param floorId - Floor ID
|
|
81
|
-
* @param overrides - Optional field overrides
|
|
82
|
-
* @returns Mock floor entry
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const floor = createFloor('ground_floor', {
|
|
87
|
-
* name: 'Ground Floor',
|
|
88
|
-
* level: 0,
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
export declare function createFloor(floorId: string, overrides?: Partial<FloorRegistryEntry>): FloorRegistryEntry;
|
|
93
|
-
/**
|
|
94
|
-
* Create a mock label registry entry
|
|
95
|
-
*
|
|
96
|
-
* @param labelId - Label ID
|
|
97
|
-
* @param overrides - Optional field overrides
|
|
98
|
-
* @returns Mock label entry
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const label = createLabel('important', {
|
|
103
|
-
* name: 'Important',
|
|
104
|
-
* color: 'red',
|
|
105
|
-
* });
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export declare function createLabel(labelId: string, overrides?: Partial<LabelRegistryEntry>): LabelRegistryEntry;
|
|
109
|
-
/**
|
|
110
|
-
* Create a basic fixture set for testing
|
|
111
|
-
*
|
|
112
|
-
* @returns Complete fixture set with basic entities
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* const fixtures = createBasicFixtures();
|
|
117
|
-
* const mock = initMockHA(fixtures);
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
export declare function createBasicFixtures(): Fixtures;
|
|
121
|
-
/**
|
|
122
|
-
* Load fixtures from JSON
|
|
123
|
-
*
|
|
124
|
-
* @param json - JSON string or object
|
|
125
|
-
* @returns Parsed fixtures
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```typescript
|
|
129
|
-
* const fixtures = loadFixture(`{
|
|
130
|
-
* "entities": { ... },
|
|
131
|
-
* "entityRegistry": [ ... ]
|
|
132
|
-
* }`);
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
export declare function loadFixture(json: string | object): Partial<Fixtures>;
|
|
136
|
-
/**
|
|
137
|
-
* Create a fixture set from partial data
|
|
138
|
-
*
|
|
139
|
-
* Fills in missing fields with defaults.
|
|
140
|
-
*
|
|
141
|
-
* @param partial - Partial fixture data
|
|
142
|
-
* @returns Complete fixture set
|
|
143
|
-
*/
|
|
144
|
-
export declare function createFixture(partial?: Partial<Fixtures>): Fixtures;
|
|
145
|
-
/**
|
|
146
|
-
* Create a history state point
|
|
147
|
-
*
|
|
148
|
-
* @param state - State value
|
|
149
|
-
* @param timestamp - Unix timestamp in seconds
|
|
150
|
-
* @param attributes - Optional attributes
|
|
151
|
-
* @param lastChanged - Optional last changed timestamp (defaults to timestamp)
|
|
152
|
-
* @returns History state point
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* const historyState = createHistoryState("20.5", Math.floor(Date.now() / 1000) - 3600, {
|
|
157
|
-
* unit_of_measurement: "°C",
|
|
158
|
-
* });
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export declare function createHistoryState(state: string, timestamp: number, attributes?: Record<string, any>, lastChanged?: number): EntityHistoryState;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test helpers
|
|
3
|
-
*
|
|
4
|
-
* Utility functions for testing with the sync-layer.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
import type { EntityRegistryEntry } from "@glasshome/ha-types";
|
|
9
|
-
import { state } from "../core/store";
|
|
10
|
-
import type { EntityId, HassEntity } from "../core/types";
|
|
11
|
-
import type { MockConnection } from "./mock";
|
|
12
|
-
import type { RegistryUpdateOptions, StateChangeOptions } from "./types";
|
|
13
|
-
/**
|
|
14
|
-
* Wait for a condition to be true
|
|
15
|
-
*
|
|
16
|
-
* @param condition - Function that returns true when ready
|
|
17
|
-
* @param timeout - Maximum wait time in ms
|
|
18
|
-
* @param interval - Check interval in ms
|
|
19
|
-
* @returns Promise that resolves when condition is true
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* await waitFor(() => entity('light.kitchen').get()?.state === 'on', 1000);
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function waitFor(condition: () => boolean, timeout?: number, interval?: number): Promise<void>;
|
|
27
|
-
/**
|
|
28
|
-
* Simulate state change event
|
|
29
|
-
*
|
|
30
|
-
* Updates entity state and emits event through mock connection.
|
|
31
|
-
*
|
|
32
|
-
* @param mockConnection - MockConnection instance
|
|
33
|
-
* @param entityId - Entity ID
|
|
34
|
-
* @param updates - State updates
|
|
35
|
-
* @param options - Optional simulation options
|
|
36
|
-
* @returns Promise that resolves when update completes
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const mockConnection = new MockConnection(fixtures);
|
|
41
|
-
* await simulateStateChange(mockConnection, 'light.kitchen', {
|
|
42
|
-
* state: 'on',
|
|
43
|
-
* attributes: { brightness: 255 },
|
|
44
|
-
* });
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare function simulateStateChange(mockConnection: MockConnection, entityId: EntityId, updates: Partial<HassEntity>, options?: StateChangeOptions): Promise<void>;
|
|
48
|
-
/**
|
|
49
|
-
* Simulate registry update event
|
|
50
|
-
*
|
|
51
|
-
* Updates entity registry and emits event through mock connection.
|
|
52
|
-
*
|
|
53
|
-
* @param mockConnection - MockConnection instance
|
|
54
|
-
* @param entityId - Entity ID
|
|
55
|
-
* @param updates - Registry updates
|
|
56
|
-
* @param options - Optional simulation options
|
|
57
|
-
* @returns Promise that resolves when update completes
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const mockConnection = new MockConnection(fixtures);
|
|
62
|
-
* await simulateRegistryUpdate(mockConnection, 'light.kitchen', {
|
|
63
|
-
* name: 'New Name',
|
|
64
|
-
* area_id: 'bedroom',
|
|
65
|
-
* });
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
export declare function simulateRegistryUpdate(mockConnection: MockConnection, entityId: EntityId, updates: Partial<EntityRegistryEntry>, options?: RegistryUpdateOptions): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Simulate multiple state changes in sequence
|
|
71
|
-
*
|
|
72
|
-
* @param mockConnection - MockConnection instance
|
|
73
|
-
* @param changes - Array of state change configurations
|
|
74
|
-
* @param delayBetween - Delay between changes in ms
|
|
75
|
-
* @returns Promise that resolves when all changes complete
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ```typescript
|
|
79
|
-
* const mockConnection = new MockConnection(fixtures);
|
|
80
|
-
* await simulateStateChanges(mockConnection, [
|
|
81
|
-
* { entityId: 'light.kitchen', updates: { state: 'on' } },
|
|
82
|
-
* { entityId: 'light.living_room', updates: { state: 'on' } },
|
|
83
|
-
* ], 100);
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
export declare function simulateStateChanges(mockConnection: MockConnection, changes: Array<{
|
|
87
|
-
entityId: EntityId;
|
|
88
|
-
updates: Partial<HassEntity>;
|
|
89
|
-
}>, delayBetween?: number): Promise<void>;
|
|
90
|
-
/**
|
|
91
|
-
* Get current store state snapshot
|
|
92
|
-
*
|
|
93
|
-
* @returns Current store state
|
|
94
|
-
*/
|
|
95
|
-
export declare function getStoreSnapshot(): typeof state;
|
|
96
|
-
/**
|
|
97
|
-
* Get entity from store
|
|
98
|
-
*
|
|
99
|
-
* @param entityId - Entity ID
|
|
100
|
-
* @returns Entity state or undefined
|
|
101
|
-
*/
|
|
102
|
-
export declare function getEntityFromStore(entityId: EntityId): HassEntity | undefined;
|
|
103
|
-
/**
|
|
104
|
-
* Get entity registry entry from store
|
|
105
|
-
*
|
|
106
|
-
* @param entityId - Entity ID
|
|
107
|
-
* @returns Registry entry or undefined
|
|
108
|
-
*/
|
|
109
|
-
export declare function getEntityRegistryFromStore(entityId: EntityId): EntityRegistryEntry | undefined;
|
|
110
|
-
/**
|
|
111
|
-
* Check if entity exists in store
|
|
112
|
-
*
|
|
113
|
-
* @param entityId - Entity ID
|
|
114
|
-
* @returns True if entity exists
|
|
115
|
-
*/
|
|
116
|
-
export declare function entityExistsInStore(entityId: EntityId): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Delay for specified time
|
|
119
|
-
*
|
|
120
|
-
* @param ms - Milliseconds to delay
|
|
121
|
-
* @returns Promise that resolves after delay
|
|
122
|
-
*/
|
|
123
|
-
export declare function delay(ms: number): Promise<void>;
|
|
124
|
-
/**
|
|
125
|
-
* Wait for mock connection to complete
|
|
126
|
-
*
|
|
127
|
-
* Helper to ensure fixtures are loaded before running tests.
|
|
128
|
-
* Use after creating MockConnection and connecting.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* const mockConnection = new MockConnection(fixtures);
|
|
133
|
-
* await mockConnection.connect();
|
|
134
|
-
* await waitForConnection();
|
|
135
|
-
* // Now safe to run queries
|
|
136
|
-
* ```
|
|
137
|
-
*/
|
|
138
|
-
export declare function waitForConnection(): Promise<void>;
|
|
139
|
-
/**
|
|
140
|
-
* Create a spy function for testing
|
|
141
|
-
*
|
|
142
|
-
* @returns Spy function with call tracking
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* const spy = createSpy();
|
|
147
|
-
* entities().byDomain('light').subscribe(spy);
|
|
148
|
-
* // Check spy.calls, spy.callCount, etc.
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
export declare function createSpy<T = unknown>(): SpyFunction<T>;
|
|
152
|
-
/**
|
|
153
|
-
* Spy function interface
|
|
154
|
-
*/
|
|
155
|
-
export interface SpyFunction<T = unknown> {
|
|
156
|
-
(...args: T[]): void;
|
|
157
|
-
calls: T[][];
|
|
158
|
-
callCount: number;
|
|
159
|
-
reset(): void;
|
|
160
|
-
}
|
package/dist/testing/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Testing utilities for @glasshome/sync-layer
|
|
3
|
-
*
|
|
4
|
-
* Provides mock connections, fixtures, and helpers for testing
|
|
5
|
-
* Home Assistant integrations without a live backend.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
export type { AreaRegistryEntry, DeviceRegistryEntry, Fixtures, FloorRegistryEntry, LabelRegistryEntry, RegistryUpdateOptions, StateChangeOptions, } from "./types";
|
|
10
|
-
export { MockConnection } from "./mock";
|
|
11
|
-
export { createArea, createBasicFixtures, createDemoFixtures, createDevice, createEntity, createEntityRegistryEntry, createFixture, createFloor, createHistoryState, createLabel, loadFixture, } from "./fixtures";
|
|
12
|
-
export type { SpyFunction } from "./helpers";
|
|
13
|
-
export { createSpy, delay, entityExistsInStore, getEntityFromStore, getEntityRegistryFromStore, getStoreSnapshot, simulateRegistryUpdate, simulateStateChange, simulateStateChanges, waitFor, waitForConnection, } from "./helpers";
|