@glasshome/sync-layer 0.10.2 → 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
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-B6eeHPDQ.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":
@@ -1,2 +1,2 @@
1
- import { t as runHaBridgeWorker } from "../worker-main-B6eeHPDQ.js";
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
- const socketFactory = (options) => createSocket({
258
- ...options,
259
- auth: proxiedAuth
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/sync-layer",
3
- "version": "0.10.2",
3
+ "version": "0.11.0",
4
4
  "description": "Type-safe, reactive state synchronization layer for Home Assistant",
5
5
  "keywords": [
6
6
  "home-assistant",