@glasshome/sync-layer 0.10.1 → 0.11.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
|
@@ -1158,6 +1158,10 @@ declare function createDemoFixtures(): DemoFixtures;
|
|
|
1158
1158
|
//#region src/worker/protocol.d.ts
|
|
1159
1159
|
type ConnState = "connected" | "disconnected" | "reconnecting";
|
|
1160
1160
|
type ConnReason = "invalid_auth" | "ping_timeout";
|
|
1161
|
+
interface SocketClose {
|
|
1162
|
+
code: number;
|
|
1163
|
+
reason: string;
|
|
1164
|
+
}
|
|
1161
1165
|
//#endregion
|
|
1162
1166
|
//#region src/worker/bridge-client.d.ts
|
|
1163
1167
|
/**
|
|
@@ -1176,7 +1180,7 @@ interface BridgeConnectOptions {
|
|
|
1176
1180
|
proxyTicket?: string;
|
|
1177
1181
|
}
|
|
1178
1182
|
interface BridgeEvents {
|
|
1179
|
-
onConnState?: (state: ConnState, reason?: ConnReason) => void;
|
|
1183
|
+
onConnState?: (state: ConnState, reason?: ConnReason, close?: SocketClose) => void;
|
|
1180
1184
|
onReadyAfterReconnect?: () => void;
|
|
1181
1185
|
onInvalidAuth?: () => void;
|
|
1182
1186
|
onDenial?: (denial: {
|
|
@@ -1247,4 +1251,4 @@ declare function claimHostApi(): HostApi | null;
|
|
|
1247
1251
|
//#region src/index.d.ts
|
|
1248
1252
|
declare const VERSION = "0.2.1";
|
|
1249
1253
|
//#endregion
|
|
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 };
|
|
1254
|
+
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 SocketClose, 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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as setPrivilegedConn, A as unloadDemoData, B as getAreaView, C as demoTimeMap, D as resetDemo, E as loadDemoHouse, F as MAX_HISTORY_POINTS, G as getEntityView, H as buildEntityView, I as appendHistoryPoint, J as forceResubscribe, K as getEntityViews, L as bulkAppendHistoryPoints, M as demoEnergyPreferences, N as isEnergyEntity, O as startDemoEnergyTicker, P as synthesizeEnergyHistory, Q as privilegedConn, R as buildAreaView, S as demoReplayModel, T as loadDemoData, U as entityViewEquals, V as getAreaViews, W as getAllEntityViews, X as setManagerConnection, Y as registerEntity, Z as setResubscribeHandler, _ as applyDemoServiceCall, a as fetchForecastData, b as demoCallLog, c as normalizeStatisticTime, d as callService, et as setState, f as sendCommand, g as updateEntity, h as turnOn, i as fetchForecast, j as demoAssetUrl, k as stopDemoEnergyTicker, l as batchEntityUpdates, m as turnOff, o as fetchForecasts, p as toggle, q as extractDomain, s as fetchStatisticsDuringPeriod, t as forceResubscribeCalendars, tt as state, u as batchServiceCalls, v as applyVisitorHolds, w as isDemoMode, x as demoModel, y as createDemoFixtures, z as buildDeviceView } from "./track-
|
|
2
|
-
import { t as runHaBridgeWorker } from "./worker-main-
|
|
1
|
+
import { $ as setPrivilegedConn, A as unloadDemoData, B as getAreaView, C as demoTimeMap, D as resetDemo, E as loadDemoHouse, F as MAX_HISTORY_POINTS, G as getEntityView, H as buildEntityView, I as appendHistoryPoint, J as forceResubscribe, K as getEntityViews, L as bulkAppendHistoryPoints, M as demoEnergyPreferences, N as isEnergyEntity, O as startDemoEnergyTicker, P as synthesizeEnergyHistory, Q as privilegedConn, R as buildAreaView, S as demoReplayModel, T as loadDemoData, U as entityViewEquals, V as getAreaViews, W as getAllEntityViews, X as setManagerConnection, Y as registerEntity, Z as setResubscribeHandler, _ as applyDemoServiceCall, a as fetchForecastData, b as demoCallLog, c as normalizeStatisticTime, d as callService, et as setState, f as sendCommand, g as updateEntity, h as turnOn, i as fetchForecast, j as demoAssetUrl, k as stopDemoEnergyTicker, l as batchEntityUpdates, m as turnOff, o as fetchForecasts, p as toggle, q as extractDomain, s as fetchStatisticsDuringPeriod, t as forceResubscribeCalendars, tt as state, u as batchServiceCalls, v as applyVisitorHolds, w as isDemoMode, x as demoModel, y as createDemoFixtures, z as buildDeviceView } from "./track-BmoU1-vZ.js";
|
|
2
|
+
import { t as runHaBridgeWorker } from "./worker-main-CVQN_7V9.js";
|
|
3
3
|
import { produce } from "solid-js/store";
|
|
4
4
|
//#region src/core/reducers.ts
|
|
5
5
|
/**
|
|
@@ -1368,7 +1368,7 @@ function createHaBridge(worker, events = {}) {
|
|
|
1368
1368
|
break;
|
|
1369
1369
|
case "conn":
|
|
1370
1370
|
connState = msg.state;
|
|
1371
|
-
events.onConnState?.(msg.state, msg.reason);
|
|
1371
|
+
events.onConnState?.(msg.state, msg.reason, msg.close);
|
|
1372
1372
|
if (msg.reason === "invalid_auth") events.onInvalidAuth?.();
|
|
1373
1373
|
break;
|
|
1374
1374
|
case "ready_after_reconnect":
|
package/dist/solid/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as getEntityView, Q as privilegedConn, R as buildAreaView, U as entityViewEquals, V as getAreaViews, Y as registerEntity, d as callService, et as setState, h as turnOn, m as turnOff, n as trackCalendarEvents, p as toggle, q as extractDomain, r as buildDemoForecast, s as fetchStatisticsDuringPeriod, tt as state, w as isDemoMode } from "../track-
|
|
1
|
+
import { G as getEntityView, Q as privilegedConn, R as buildAreaView, U as entityViewEquals, V as getAreaViews, Y as registerEntity, d as callService, et as setState, h as turnOn, m as turnOff, n as trackCalendarEvents, p as toggle, q as extractDomain, r as buildDemoForecast, s as fetchStatisticsDuringPeriod, tt as state, w as isDemoMode } from "../track-BmoU1-vZ.js";
|
|
2
2
|
import { produce } from "solid-js/store";
|
|
3
3
|
import { createEffect, createMemo, createResource, onCleanup } from "solid-js";
|
|
4
4
|
//#region src/weather/track.ts
|
|
@@ -504,7 +504,19 @@ const WEEKDAYS = {
|
|
|
504
504
|
Fri: 5,
|
|
505
505
|
Sat: 6
|
|
506
506
|
};
|
|
507
|
+
const RECENT_LIMIT = 256;
|
|
508
|
+
const recent = /* @__PURE__ */ new Map();
|
|
507
509
|
function parts(ms, timeZone) {
|
|
510
|
+
const key = `${timeZone}|${ms}`;
|
|
511
|
+
let p = recent.get(key);
|
|
512
|
+
if (!p) {
|
|
513
|
+
if (recent.size >= RECENT_LIMIT) recent.clear();
|
|
514
|
+
p = readParts(ms, timeZone);
|
|
515
|
+
recent.set(key, p);
|
|
516
|
+
}
|
|
517
|
+
return p;
|
|
518
|
+
}
|
|
519
|
+
function readParts(ms, timeZone) {
|
|
508
520
|
const out = {};
|
|
509
521
|
for (const p of formatter(timeZone).formatToParts(ms)) out[p.type] = p.value;
|
|
510
522
|
return {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as runHaBridgeWorker } from "../worker-main-
|
|
1
|
+
import { t as runHaBridgeWorker } from "../worker-main-CVQN_7V9.js";
|
|
2
2
|
export { runHaBridgeWorker };
|
|
@@ -254,10 +254,20 @@ function runHaBridgeWorker(scope) {
|
|
|
254
254
|
const auth = proxyAuth(url);
|
|
255
255
|
const proxyWsUrl = buildProxyWsUrl(scope, proxyWsPath, proxyTicket);
|
|
256
256
|
const proxiedAuth = new Proxy(auth, { get: (target, prop) => prop === "wsUrl" ? proxyWsUrl : Reflect.get(target, prop) });
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
let lastClose;
|
|
258
|
+
const socketFactory = async (options) => {
|
|
259
|
+
const socket = await createSocket({
|
|
260
|
+
...options,
|
|
261
|
+
auth: proxiedAuth
|
|
262
|
+
});
|
|
263
|
+
socket.addEventListener("close", (ev) => {
|
|
264
|
+
lastClose = {
|
|
265
|
+
code: ev.code,
|
|
266
|
+
reason: ev.reason
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
return socket;
|
|
270
|
+
};
|
|
261
271
|
try {
|
|
262
272
|
conn = await createConnection({
|
|
263
273
|
auth,
|
|
@@ -274,7 +284,8 @@ function runHaBridgeWorker(scope) {
|
|
|
274
284
|
}
|
|
275
285
|
conn.addEventListener("disconnected", () => post({
|
|
276
286
|
k: "conn",
|
|
277
|
-
state: "disconnected"
|
|
287
|
+
state: "disconnected",
|
|
288
|
+
...lastClose ? { close: lastClose } : {}
|
|
278
289
|
}));
|
|
279
290
|
conn.addEventListener("reconnect-error", (_c, err) => post(reconnectErrorMessage(err)));
|
|
280
291
|
let everReady = false;
|
package/package.json
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glasshome/sync-layer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Type-safe, reactive state synchronization layer for Home Assistant",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"home-assistant",
|
|
7
|
+
"reactive",
|
|
8
|
+
"smart-home",
|
|
9
|
+
"solidjs",
|
|
10
|
+
"typescript",
|
|
11
|
+
"websocket"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/glasshome/sync-layer#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/glasshome/sync-layer/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "GlassHome Labs",
|
|
5
19
|
"repository": {
|
|
6
20
|
"type": "git",
|
|
7
21
|
"url": "https://github.com/glasshome/sync-layer.git"
|
|
8
22
|
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
9
26
|
"type": "module",
|
|
27
|
+
"sideEffects": true,
|
|
10
28
|
"main": "./dist/index.js",
|
|
11
29
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"sideEffects": true,
|
|
13
30
|
"exports": {
|
|
14
31
|
".": {
|
|
15
32
|
"@glasshome/source": "./src/index.ts",
|
|
@@ -33,59 +50,45 @@
|
|
|
33
50
|
},
|
|
34
51
|
"./package.json": "./package.json"
|
|
35
52
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"solid-js": "^1.9.0"
|
|
39
|
-
},
|
|
40
|
-
"peerDependenciesMeta": {
|
|
41
|
-
"@glasshome/ha-types": {
|
|
42
|
-
"optional": false
|
|
43
|
-
},
|
|
44
|
-
"solid-js": {
|
|
45
|
-
"optional": true
|
|
46
|
-
}
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
47
55
|
},
|
|
48
|
-
"files": [
|
|
49
|
-
"dist"
|
|
50
|
-
],
|
|
51
56
|
"scripts": {
|
|
52
57
|
"build": "tsdown && tsc --noEmit && bun scripts/check-widget-reachable-surface.ts",
|
|
53
58
|
"dev": "tsdown --watch",
|
|
54
59
|
"test": "bun test",
|
|
55
|
-
"lint": "tsc --noEmit",
|
|
60
|
+
"lint": "oxlint --type-aware . && oxfmt --check . && tsc --noEmit",
|
|
56
61
|
"gen:demo-ids": "bun scripts/gen-demo-ids.ts",
|
|
57
62
|
"check:dead": "fallow dead-code --fail-on-issues"
|
|
58
63
|
},
|
|
59
64
|
"dependencies": {
|
|
60
|
-
"
|
|
61
|
-
"
|
|
65
|
+
"@glasshome/widget-contract": "0.3.0",
|
|
66
|
+
"home-assistant-js-websocket": "^9.6.0"
|
|
62
67
|
},
|
|
63
68
|
"devDependencies": {
|
|
64
69
|
"@glasshome/ha-types": "0.2.0",
|
|
65
70
|
"@types/bun": "^1.4.0",
|
|
66
71
|
"fallow": "3.17.0",
|
|
72
|
+
"oxfmt": "0.65.0",
|
|
73
|
+
"oxlint": "1.81.0",
|
|
74
|
+
"oxlint-tsgolint": "7.0.2001",
|
|
67
75
|
"solid-js": "^1.9.0",
|
|
68
76
|
"tsdown": "^0.22.14",
|
|
69
77
|
"typescript": "^7.0.2"
|
|
70
78
|
},
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
"
|
|
79
|
+
"peerDependencies": {
|
|
80
|
+
"@glasshome/ha-types": "0.2.0",
|
|
81
|
+
"solid-js": "^1.9.0"
|
|
74
82
|
},
|
|
75
|
-
"
|
|
76
|
-
"
|
|
83
|
+
"peerDependenciesMeta": {
|
|
84
|
+
"@glasshome/ha-types": {
|
|
85
|
+
"optional": false
|
|
86
|
+
},
|
|
87
|
+
"solid-js": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
77
90
|
},
|
|
78
91
|
"engines": {
|
|
79
92
|
"node": ">=18"
|
|
80
|
-
}
|
|
81
|
-
"keywords": [
|
|
82
|
-
"home-assistant",
|
|
83
|
-
"websocket",
|
|
84
|
-
"typescript",
|
|
85
|
-
"reactive",
|
|
86
|
-
"solidjs",
|
|
87
|
-
"smart-home"
|
|
88
|
-
],
|
|
89
|
-
"author": "GlassHome Labs",
|
|
90
|
-
"license": "MIT"
|
|
93
|
+
}
|
|
91
94
|
}
|