@glasshome/sync-layer 0.1.14 → 0.1.16
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/core/store.d.ts +2 -0
- package/dist/demo/demo-data.d.ts +1 -1
- package/dist/demo/demo-provider.d.ts +7 -0
- package/dist/demo/energy-sim.d.ts +106 -0
- package/dist/demo-data-CavpxBw3.js +1186 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +102 -8
- package/dist/solid/hooks.d.ts +11 -0
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +31 -4
- package/dist/testing/index.js +23 -2
- package/dist/testing/mock.d.ts +6 -1
- package/package.json +3 -3
- package/dist/demo-data-D1ofmMa4.js +0 -608
package/dist/core/store.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface GlassHomeState {
|
|
|
23
23
|
connectionError: Error | null;
|
|
24
24
|
/** Home Assistant base URL */
|
|
25
25
|
hassUrl: string | null;
|
|
26
|
+
/** Home Assistant core config (unit system, locale, currency); null until loaded */
|
|
27
|
+
config: import("@glasshome/ha-types").HassConfig | null;
|
|
26
28
|
/** Live entity state (keyed by entity_id) */
|
|
27
29
|
entities: Record<EntityId, HassEntity>;
|
|
28
30
|
/** Entity registry entries (keyed by entity_id) */
|
package/dist/demo/demo-data.d.ts
CHANGED
|
@@ -19,6 +19,6 @@ export interface DemoFixtures {
|
|
|
19
19
|
*
|
|
20
20
|
* Entities span lights, sensors, binary sensors, climate, covers,
|
|
21
21
|
* locks, switches, media player, weather, camera, scenes, and buttons
|
|
22
|
-
* across
|
|
22
|
+
* across 6 areas: living_room, bedroom, kitchen, entry, utility, garage.
|
|
23
23
|
*/
|
|
24
24
|
export declare function createDemoFixtures(): DemoFixtures;
|
|
@@ -21,6 +21,13 @@ export declare function loadDemoData(): Promise<void>;
|
|
|
21
21
|
* Unload demo data and reset to disconnected state.
|
|
22
22
|
*/
|
|
23
23
|
export declare function unloadDemoData(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Start the demo energy ticker. Updates the energy sensors and `sun.sun`
|
|
26
|
+
* every 5 seconds. Idempotent: clears any prior interval first. SSR-safe.
|
|
27
|
+
*/
|
|
28
|
+
export declare function startDemoEnergyTicker(): void;
|
|
29
|
+
/** Stop the demo energy ticker if running. */
|
|
30
|
+
export declare function stopDemoEnergyTicker(): void;
|
|
24
31
|
/**
|
|
25
32
|
* Apply an optimistic state update for demo mode.
|
|
26
33
|
*
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
/**
|
|
94
|
+
* Synthesize statistics buckets for one energy entity across a window.
|
|
95
|
+
*
|
|
96
|
+
* `mean`/`min`/`max` come from 5-minute power samples in the bucket; `sum` is
|
|
97
|
+
* the energy in Wh (mean W times bucket hours). `sum` is cumulative across the
|
|
98
|
+
* window, matching HA's monotonically increasing meter semantics.
|
|
99
|
+
*/
|
|
100
|
+
export declare function synthesizeEnergyStatistics(entityId: string, startMs: number, endMs: number, period: "hour" | "day"): DemoStatisticBucket[];
|
|
101
|
+
/** The demo energy dashboard preferences wiring the simulated sensors. */
|
|
102
|
+
export declare function demoEnergyPreferences(): {
|
|
103
|
+
energy_sources: Array<Record<string, unknown>>;
|
|
104
|
+
device_consumption: Array<Record<string, unknown>>;
|
|
105
|
+
};
|
|
106
|
+
export {};
|