@glasshome/sync-layer 0.8.0 → 0.8.2

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
@@ -1207,6 +1207,7 @@ declare function applyDemoServiceCall(_domain: string, service: string, _service
1207
1207
  //#endregion
1208
1208
  //#region src/worker/protocol.d.ts
1209
1209
  type ConnState = "connected" | "disconnected" | "reconnecting";
1210
+ type ConnReason = "invalid_auth" | "ping_timeout";
1210
1211
  //#endregion
1211
1212
  //#region src/worker/bridge-client.d.ts
1212
1213
  /**
@@ -1225,7 +1226,7 @@ interface BridgeConnectOptions {
1225
1226
  proxyTicket?: string;
1226
1227
  }
1227
1228
  interface BridgeEvents {
1228
- onConnState?: (state: ConnState) => void;
1229
+ onConnState?: (state: ConnState, reason?: ConnReason) => void;
1229
1230
  onReadyAfterReconnect?: () => void;
1230
1231
  onInvalidAuth?: () => void;
1231
1232
  onDenial?: (denial: {
@@ -1264,7 +1265,7 @@ declare function createHaBridge(worker: Worker, events?: BridgeEvents): HaBridge
1264
1265
  */
1265
1266
  declare function attachBridgeToStore(bridge: HaBridge, hassUrl: string, mediaProxyBase?: string): Promise<void>;
1266
1267
  /** Map worker connection-state messages onto the store. */
1267
- declare function applyBridgeConnState(state: "connected" | "disconnected" | "reconnecting"): void;
1268
+ declare function applyBridgeConnState(state: "connecting" | "connected" | "disconnected" | "reconnecting"): void;
1268
1269
  /** Re-sync after the worker reports a completed reconnect. */
1269
1270
  declare function reloadAfterBridgeReconnect(bridge: HaBridge): Promise<void>;
1270
1271
  /** Detach on shutdown; the caller terminates the worker itself. */
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { A as extractDomain, B as state, C as startDemoEnergyTicker, D as demoEnergyPreferences, E as createDemoFixtures, F as forceResubscribeCalendars, L as privilegedConn, M as registerEntity, N as setManagerConnection, O as isEnergyEntity, P as setResubscribeHandler, R as setPrivilegedConn, S as loadDemoData, T as unloadDemoData, _ as turnOff, a as getAreaView, b as applyDemoServiceCall, c as entityViewEquals, d as getEntityViews, f as batchEntityUpdates, g as toggle, h as sendCommand, i as buildDeviceView, j as forceResubscribe, k as synthesizeEnergyHistory, l as getAllEntityViews, m as callService, n as normalizeStatisticTime, o as getAreaViews, p as batchServiceCalls, r as buildAreaView, s as buildEntityView, t as fetchStatisticsDuringPeriod, u as getEntityView, v as turnOn, w as stopDemoEnergyTicker, x as isDemoMode, y as updateEntity, z as setState } from "./statistics-DyCCTwv2.js";
2
- import { t as runHaBridgeWorker } from "./worker-main-D_wyGAIG.js";
2
+ import { t as runHaBridgeWorker } from "./worker-main-DamaVb7B.js";
3
3
  import "home-assistant-js-websocket";
4
4
  import { produce } from "solid-js/store";
5
5
  //#region src/core/reducers.ts
@@ -1797,7 +1797,7 @@ function createHaBridge(worker, events = {}) {
1797
1797
  break;
1798
1798
  case "conn":
1799
1799
  connState = msg.state;
1800
- events.onConnState?.(msg.state);
1800
+ events.onConnState?.(msg.state, msg.reason);
1801
1801
  if (msg.reason === "invalid_auth") events.onInvalidAuth?.();
1802
1802
  break;
1803
1803
  case "ready_after_reconnect":
@@ -1,2 +1,2 @@
1
- import { t as runHaBridgeWorker } from "../worker-main-D_wyGAIG.js";
1
+ import { t as runHaBridgeWorker } from "../worker-main-DamaVb7B.js";
2
2
  export { runHaBridgeWorker };
@@ -214,7 +214,14 @@ function runHaBridgeWorker(scope) {
214
214
  stopHeartbeat();
215
215
  heartbeat = setInterval(() => {
216
216
  const timer = new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("ping timeout")), HEARTBEAT_TIMEOUT_MS));
217
- Promise.race([c.ping(), timer]).catch(() => c.reconnect());
217
+ Promise.race([c.ping(), timer]).catch(() => {
218
+ post({
219
+ k: "conn",
220
+ state: "reconnecting",
221
+ reason: "ping_timeout"
222
+ });
223
+ c.reconnect();
224
+ });
218
225
  }, HEARTBEAT_INTERVAL_MS);
219
226
  }
220
227
  function stopHeartbeat() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/sync-layer",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Type-safe, reactive state synchronization layer for Home Assistant",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,11 +51,11 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "home-assistant-js-websocket": "^9.6.0",
54
- "@glasshome/widget-contract": "0.2.0"
54
+ "@glasshome/widget-contract": "0.2.1"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@glasshome/ha-types": "0.1.2",
58
- "@types/bun": "latest",
58
+ "@types/bun": "^1.4.0",
59
59
  "solid-js": "^1.9.0",
60
60
  "tsdown": "^0.22.14",
61
61
  "typescript": "^7.0.2"