@glasshome/sync-layer 0.10.0 → 0.10.1

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.js CHANGED
@@ -1,4 +1,4 @@
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-BAfgOjMk.js";
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-DssLNusE.js";
2
2
  import { t as runHaBridgeWorker } from "./worker-main-B6eeHPDQ.js";
3
3
  import { produce } from "solid-js/store";
4
4
  //#region src/core/reducers.ts
@@ -1034,7 +1034,8 @@ function demoHistory(entityIds, startMs, endMs, toWallMs = (ms) => ms) {
1034
1034
  const startC = Math.max(startMs, endC - DAY_MS);
1035
1035
  if (startC >= endC) return result;
1036
1036
  const log = demoCallLog();
1037
- const modelStartMs = log.length > 0 ? Math.min(startC, log[0].simMs) : startC;
1037
+ const first = log[0];
1038
+ const modelStartMs = first ? Math.min(startC, first.simMs) : startC;
1038
1039
  const replayModel = demoReplayModel(modelStartMs);
1039
1040
  if (!replayModel) return result;
1040
1041
  const replay = replayModel;
@@ -1053,15 +1054,15 @@ function demoHistory(entityIds, startMs, endMs, toWallMs = (ms) => ms) {
1053
1054
  record(replay.nowMs);
1054
1055
  let logIdx = 0;
1055
1056
  while (replay.nowMs < endC) {
1056
- const nextLogMs = logIdx < log.length ? log[logIdx].simMs : Number.POSITIVE_INFINITY;
1057
+ const next = log[logIdx];
1058
+ const nextLogMs = next ? next.simMs : Number.POSITIVE_INFINITY;
1057
1059
  const windowBoundary = replay.nowMs < startC ? startC : Number.POSITIVE_INFINITY;
1058
1060
  const targetMs = Math.min(replay.nowMs + STEP_MS, endC, nextLogMs, windowBoundary);
1059
1061
  replay.advanceTo(targetMs, STEP_MS);
1060
1062
  record(replay.nowMs);
1061
- if (logIdx < log.length && log[logIdx].simMs === replay.nowMs) {
1062
- const entry = log[logIdx];
1063
- replay.dispatch(entry.call);
1064
- applyVisitorHolds(replay, entry.call.entityIds);
1063
+ if (next && next.simMs === replay.nowMs) {
1064
+ replay.dispatch(next.call);
1065
+ applyVisitorHolds(replay, next.call.entityIds);
1065
1066
  logIdx++;
1066
1067
  record(replay.nowMs);
1067
1068
  }
@@ -1097,7 +1098,7 @@ async function fetchHistory(options) {
1097
1098
  const endMs = timeMap.toSim((endTime ?? /* @__PURE__ */ new Date()).getTime());
1098
1099
  const energyStepMs = timeMap.toSim(6e4) - timeMap.toSim(0);
1099
1100
  const toWallSeconds = (simSeconds) => Math.round(timeMap.toWall(simSeconds * 1e3) / 1e3);
1100
- const replayed = demoHistory(entityIds.filter((id) => !isEnergyEntity(id)), startMs, endMs, timeMap.toWall);
1101
+ const replayed = demoHistory(entityIds.filter((id) => !isEnergyEntity(id)), startMs, endMs, (ms) => timeMap.toWall(ms));
1101
1102
  const result = {};
1102
1103
  for (const id of entityIds) result[id] = isEnergyEntity(id) ? synthesizeEnergyHistory(id, startMs, endMs, energyStepMs).map((p) => ({
1103
1104
  s: p.s,
@@ -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-BAfgOjMk.js";
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-DssLNusE.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
@@ -1244,18 +1244,18 @@ const fan = {
1244
1244
  on: percentage > 0
1245
1245
  };
1246
1246
  }
1247
- case "set_preset_mode": return data.preset_mode != null ? {
1247
+ case "set_preset_mode": return typeof data.preset_mode === "string" ? {
1248
1248
  ...s,
1249
- presetMode: String(data.preset_mode),
1249
+ presetMode: data.preset_mode,
1250
1250
  on: true
1251
1251
  } : s;
1252
1252
  case "oscillate": return data.oscillating != null ? {
1253
1253
  ...s,
1254
1254
  oscillating: Boolean(data.oscillating)
1255
1255
  } : s;
1256
- case "set_direction": return data.direction != null ? {
1256
+ case "set_direction": return typeof data.direction === "string" ? {
1257
1257
  ...s,
1258
- direction: String(data.direction)
1258
+ direction: data.direction
1259
1259
  } : s;
1260
1260
  default: return s;
1261
1261
  }
@@ -1508,17 +1508,17 @@ const climate = {
1508
1508
  if (data.target_temp_high != null) next.targetTempHigh = Number(data.target_temp_high);
1509
1509
  return next;
1510
1510
  }
1511
- case "set_hvac_mode": return data.hvac_mode != null ? {
1511
+ case "set_hvac_mode": return typeof data.hvac_mode === "string" ? {
1512
1512
  ...s,
1513
- hvacMode: String(data.hvac_mode)
1513
+ hvacMode: data.hvac_mode
1514
1514
  } : s;
1515
- case "set_fan_mode": return data.fan_mode != null ? {
1515
+ case "set_fan_mode": return typeof data.fan_mode === "string" ? {
1516
1516
  ...s,
1517
- fanMode: String(data.fan_mode)
1517
+ fanMode: data.fan_mode
1518
1518
  } : s;
1519
- case "set_preset_mode": return data.preset_mode != null ? {
1519
+ case "set_preset_mode": return typeof data.preset_mode === "string" ? {
1520
1520
  ...s,
1521
- presetMode: String(data.preset_mode)
1521
+ presetMode: data.preset_mode
1522
1522
  } : s;
1523
1523
  default: return s;
1524
1524
  }
@@ -1593,9 +1593,9 @@ const waterHeater = {
1593
1593
  ...s,
1594
1594
  targetTemp: Number(data.temperature)
1595
1595
  } : s;
1596
- case "set_operation_mode": return data.operation_mode != null ? {
1596
+ case "set_operation_mode": return typeof data.operation_mode === "string" ? {
1597
1597
  ...s,
1598
- mode: String(data.operation_mode)
1598
+ mode: data.operation_mode
1599
1599
  } : s;
1600
1600
  case "set_away_mode": return data.away_mode != null ? {
1601
1601
  ...s,
@@ -1698,9 +1698,9 @@ const ACTUATORS = {
1698
1698
  ...s,
1699
1699
  volume: Number(data.volume_level)
1700
1700
  } : s;
1701
- case "select_source": return data.source != null ? {
1701
+ case "select_source": return typeof data.source === "string" ? {
1702
1702
  ...s,
1703
- source: String(data.source)
1703
+ source: data.source
1704
1704
  } : s;
1705
1705
  default: return s;
1706
1706
  }
@@ -2018,7 +2018,7 @@ const weather = {
2018
2018
  const sunUp = solarElevation(ctx.nowMs, ctx.world.latitude, ctx.world.longitude) > -.833;
2019
2019
  const dateKey = localTime$1(ctx.nowMs, ctx.world.timeZone).dateKey;
2020
2020
  const noiseVal = ctx.noise(`weather:condition:${dateKey}`);
2021
- const forecast = Array.from({ length: 7 }, (_, i) => weatherForecastDay(ctx.nowMs, ctx.world, i, ctx.noise));
2021
+ const forecast = Array.from({ length: 7 }, (_, i) => weatherForecastDay(ctx.nowMs, ctx.world, i, (key) => ctx.noise(key)));
2022
2022
  return { [id]: {
2023
2023
  state: weatherCondition(cloud, sunUp, noiseVal),
2024
2024
  attributes: {
@@ -2890,7 +2890,8 @@ function toCategory(c) {
2890
2890
  return c ?? null;
2891
2891
  }
2892
2892
  function entityEntry(p, seed, name, createdIso) {
2893
- const platform = String(p.spec.params.integration ?? "demo");
2893
+ const integration = p.spec.params.integration;
2894
+ const platform = typeof integration === "string" ? integration : "demo";
2894
2895
  return {
2895
2896
  aliases: [],
2896
2897
  area_id: null,
@@ -2925,7 +2926,8 @@ function entityEntry(p, seed, name, createdIso) {
2925
2926
  };
2926
2927
  }
2927
2928
  function deviceEntry(owner, id, createdIso) {
2928
- const platform = String(owner.params.integration ?? "demo");
2929
+ const integration = owner.params.integration;
2930
+ const platform = typeof integration === "string" ? integration : "demo";
2929
2931
  const entry = `${platform}_entry`;
2930
2932
  return {
2931
2933
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/sync-layer",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "Type-safe, reactive state synchronization layer for Home Assistant",
5
5
  "repository": {
6
6
  "type": "git",