@riddix/hamh 2.1.0-alpha.573 → 2.1.0-alpha.575

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.
@@ -175948,21 +175948,21 @@ var ROOM_MODE_BASE = 100;
175948
175948
  function isRoomMode(mode) {
175949
175949
  return mode >= ROOM_MODE_BASE;
175950
175950
  }
175951
+ var cleaningSessions = /* @__PURE__ */ new WeakMap();
175952
+ function getSession(agent) {
175953
+ let session = cleaningSessions.get(agent);
175954
+ if (!session) {
175955
+ session = {
175956
+ completedAreas: /* @__PURE__ */ new Set(),
175957
+ lastCurrentArea: null,
175958
+ activeAreas: [],
175959
+ loggedShortCircuits: /* @__PURE__ */ new Set()
175960
+ };
175961
+ cleaningSessions.set(agent, session);
175962
+ }
175963
+ return session;
175964
+ }
175951
175965
  var RvcRunModeServerBase = class extends RvcRunModeServer {
175952
- /** Areas that the vacuum has already finished cleaning in this session */
175953
- completedAreas = /* @__PURE__ */ new Set();
175954
- /** Last known currentArea — used to detect room transitions */
175955
- lastCurrentArea = null;
175956
- /** Snapshot of selectedAreas taken when cleaning starts.
175957
- * The start handler clears serviceArea.state.selectedAreas after
175958
- * dispatching the HA action to prevent re-dispatch, but progress
175959
- * tracking needs the original list for the entire cleaning session. */
175960
- activeAreas = [];
175961
- /** Diagnostic short-circuit reasons already logged this session.
175962
- * updateCurrentRoomFromSensor() is called on every HA state event;
175963
- * without this guard a failing path would flood the log. Cleared
175964
- * when the vacuum returns to Idle. */
175965
- loggedShortCircuits = /* @__PURE__ */ new Set();
175966
175966
  async initialize() {
175967
175967
  await super.initialize();
175968
175968
  const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
@@ -175973,6 +175973,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175973
175973
  if (!entity.state || !entity.state.attributes) {
175974
175974
  return;
175975
175975
  }
175976
+ const s = getSession(this.agent);
175976
175977
  const previousMode = this.state.currentMode;
175977
175978
  const newMode = this.state.config.getCurrentMode(entity.state, this.agent);
175978
175979
  applyPatchState(
@@ -175989,12 +175990,12 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175989
175990
  if (previousMode !== newMode) {
175990
175991
  if (newMode === 0 /* Idle */) {
175991
175992
  this.trySetCurrentArea(null);
175992
- this.completedAreas.clear();
175993
- this.lastCurrentArea = null;
175994
- this.loggedShortCircuits.clear();
175993
+ s.completedAreas.clear();
175994
+ s.lastCurrentArea = null;
175995
+ s.loggedShortCircuits.clear();
175995
175996
  } else if (newMode === 1 /* Cleaning */) {
175996
- if (this.activeAreas.length > 0 && this.lastCurrentArea === null) {
175997
- this.trySetCurrentArea(this.activeAreas[0]);
175997
+ if (s.activeAreas.length > 0 && s.lastCurrentArea === null) {
175998
+ this.trySetCurrentArea(s.activeAreas[0]);
175998
175999
  }
175999
176000
  }
176000
176001
  }
@@ -176008,8 +176009,9 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176008
176009
  * surfacing the silent paths that would otherwise be invisible.
176009
176010
  */
176010
176011
  logShortCircuitOnce(reason, message) {
176011
- if (this.loggedShortCircuits.has(reason)) return;
176012
- this.loggedShortCircuits.add(reason);
176012
+ const s = getSession(this.agent);
176013
+ if (s.loggedShortCircuits.has(reason)) return;
176014
+ s.loggedShortCircuits.add(reason);
176013
176015
  logger189.info(message);
176014
176016
  }
176015
176017
  /**
@@ -176018,6 +176020,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176018
176020
  */
176019
176021
  updateCurrentRoomFromSensor() {
176020
176022
  try {
176023
+ const s = getSession(this.agent);
176021
176024
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
176022
176025
  const currentRoomEntityId = homeAssistant.state.mapping?.currentRoomEntity;
176023
176026
  if (!currentRoomEntityId) {
@@ -176036,7 +176039,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176036
176039
  );
176037
176040
  return;
176038
176041
  }
176039
- if (this.activeAreas.length === 0) {
176042
+ if (s.activeAreas.length === 0) {
176040
176043
  this.logShortCircuitOnce(
176041
176044
  "no-active-areas",
176042
176045
  `currentRoom sensor: activeAreas empty while cleaning \u2014 sensor=${currentRoomEntityId} state="${roomState.state}"`
@@ -176049,13 +176052,13 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176049
176052
  const roomName = roomState.state;
176050
176053
  let matchedAreaId = null;
176051
176054
  if (segmentId != null) {
176052
- if (this.activeAreas.includes(segmentId)) {
176055
+ if (s.activeAreas.includes(segmentId)) {
176053
176056
  matchedAreaId = segmentId;
176054
176057
  }
176055
176058
  }
176056
176059
  if (matchedAreaId === null && segmentId != null) {
176057
176060
  for (const area of serviceArea.state.supportedAreas) {
176058
- if (this.activeAreas.includes(area.areaId) && area.areaId % 1e4 === segmentId) {
176061
+ if (s.activeAreas.includes(area.areaId) && area.areaId % 1e4 === segmentId) {
176059
176062
  matchedAreaId = area.areaId;
176060
176063
  break;
176061
176064
  }
@@ -176065,23 +176068,23 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176065
176068
  const area = serviceArea.state.supportedAreas.find(
176066
176069
  (a) => a.areaInfo.locationInfo?.locationName?.toLowerCase() === roomName.toLowerCase()
176067
176070
  );
176068
- if (area && this.activeAreas.includes(area.areaId)) {
176071
+ if (area && s.activeAreas.includes(area.areaId)) {
176069
176072
  matchedAreaId = area.areaId;
176070
176073
  }
176071
176074
  }
176072
176075
  if (matchedAreaId === null) {
176073
176076
  logger189.info(
176074
- `currentRoom sensor: no match for "${roomName}" (segmentId=${segmentId}), activeAreas=[${this.activeAreas.join(", ")}], supportedAreas=[${serviceArea.state.supportedAreas.map((a) => `${a.areaId}:${a.areaInfo.locationInfo?.locationName}`).join(", ")}]`
176077
+ `currentRoom sensor: no match for "${roomName}" (segmentId=${segmentId}), activeAreas=[${s.activeAreas.join(", ")}], supportedAreas=[${serviceArea.state.supportedAreas.map((a) => `${a.areaId}:${a.areaInfo.locationInfo?.locationName}`).join(", ")}]`
176075
176078
  );
176076
176079
  return;
176077
176080
  }
176078
- if (matchedAreaId === this.lastCurrentArea) return;
176079
- if (this.lastCurrentArea !== null) {
176080
- this.completedAreas.add(this.lastCurrentArea);
176081
+ if (matchedAreaId === s.lastCurrentArea) return;
176082
+ if (s.lastCurrentArea !== null) {
176083
+ s.completedAreas.add(s.lastCurrentArea);
176081
176084
  }
176082
- this.lastCurrentArea = matchedAreaId;
176085
+ s.lastCurrentArea = matchedAreaId;
176083
176086
  logger189.info(
176084
- `currentRoom sensor: transition to area ${matchedAreaId} ("${roomName}"), completed: [${[...this.completedAreas].join(", ")}]`
176087
+ `currentRoom sensor: transition to area ${matchedAreaId} ("${roomName}"), completed: [${[...s.completedAreas].join(", ")}]`
176085
176088
  );
176086
176089
  this.trySetCurrentArea(matchedAreaId);
176087
176090
  } catch (e) {
@@ -176118,17 +176121,18 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176118
176121
  * matter.js property getters during transaction pre-commit.
176119
176122
  */
176120
176123
  updateProgress(serviceArea, areaId) {
176121
- if (this.activeAreas.length === 0) return;
176124
+ const s = getSession(this.agent);
176125
+ if (s.activeAreas.length === 0) return;
176122
176126
  const state = serviceArea.state;
176123
176127
  if (areaId === null) {
176124
- state.progress = this.activeAreas.map((id) => ({
176128
+ state.progress = s.activeAreas.map((id) => ({
176125
176129
  areaId: id,
176126
176130
  status: ServiceArea3.OperationalStatus.Completed
176127
176131
  }));
176128
176132
  } else {
176129
- state.progress = this.activeAreas.map((id) => ({
176133
+ state.progress = s.activeAreas.map((id) => ({
176130
176134
  areaId: id,
176131
- status: id === areaId ? ServiceArea3.OperationalStatus.Operating : this.completedAreas.has(id) ? ServiceArea3.OperationalStatus.Completed : ServiceArea3.OperationalStatus.Pending
176135
+ status: id === areaId ? ServiceArea3.OperationalStatus.Operating : s.completedAreas.has(id) ? ServiceArea3.OperationalStatus.Completed : ServiceArea3.OperationalStatus.Pending
176132
176136
  }));
176133
176137
  }
176134
176138
  }
@@ -176150,6 +176154,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176150
176154
  }
176151
176155
  }
176152
176156
  changeToMode(request) {
176157
+ const s = getSession(this.agent);
176153
176158
  const homeAssistant = this.agent.get(HomeAssistantEntityBehavior);
176154
176159
  const { newMode } = request;
176155
176160
  if (newMode !== this.state.currentMode && !this.state.supportedModes.some((m) => m.mode === newMode)) {
@@ -176162,8 +176167,8 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176162
176167
  try {
176163
176168
  const serviceArea = this.agent.get(ServiceAreaBehavior);
176164
176169
  if (serviceArea.state.selectedAreas?.length > 0) {
176165
- this.activeAreas = [...serviceArea.state.selectedAreas];
176166
- this.trySetCurrentArea(this.activeAreas[0]);
176170
+ s.activeAreas = [...serviceArea.state.selectedAreas];
176171
+ this.trySetCurrentArea(s.activeAreas[0]);
176167
176172
  homeAssistant.callAction(this.state.config.start(void 0, this.agent));
176168
176173
  this.state.currentMode = newMode;
176169
176174
  return {
@@ -176175,7 +176180,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176175
176180
  }
176176
176181
  if (this.state.config.cleanRoom) {
176177
176182
  const areaId = this.findAreaIdForMode(newMode);
176178
- this.activeAreas = areaId !== null ? [areaId] : [];
176183
+ s.activeAreas = areaId !== null ? [areaId] : [];
176179
176184
  this.trySetCurrentArea(areaId);
176180
176185
  homeAssistant.callAction(
176181
176186
  this.state.config.cleanRoom(newMode, this.agent)
@@ -176192,8 +176197,8 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176192
176197
  try {
176193
176198
  const serviceArea = this.agent.get(ServiceAreaBehavior);
176194
176199
  if (serviceArea.state.selectedAreas?.length > 0) {
176195
- this.activeAreas = [...serviceArea.state.selectedAreas];
176196
- this.trySetCurrentArea(this.activeAreas[0]);
176200
+ s.activeAreas = [...serviceArea.state.selectedAreas];
176201
+ this.trySetCurrentArea(s.activeAreas[0]);
176197
176202
  }
176198
176203
  } catch {
176199
176204
  }
@@ -176202,9 +176207,9 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
176202
176207
  }
176203
176208
  case 0 /* Idle */:
176204
176209
  this.trySetCurrentArea(null);
176205
- this.completedAreas.clear();
176206
- this.lastCurrentArea = null;
176207
- this.activeAreas = [];
176210
+ s.completedAreas.clear();
176211
+ s.lastCurrentArea = null;
176212
+ s.activeAreas = [];
176208
176213
  homeAssistant.callAction(
176209
176214
  this.state.config.returnToBase(void 0, this.agent)
176210
176215
  );
@@ -177986,21 +177991,6 @@ var advertisedOperationalStates = [
177986
177991
  OperationalState4.Docked
177987
177992
  ];
177988
177993
  var RvcOperationalStateServerBase = class extends RvcOperationalStateServer {
177989
- /**
177990
- * Alternating nonce that forces a structural difference in operationalError
177991
- * on every update call. matter.js's Datasource uses isDeepEqual to detect
177992
- * attribute changes — writing the same value is silently ignored, so no
177993
- * subscription report is generated. By toggling errorStateDetails between
177994
- * absent and "" (an optional, semantically meaningless field when
177995
- * errorStateId is NoError), we guarantee the struct is never deep-equal to
177996
- * its predecessor, which makes matter.js emit attrsChanged and produce a
177997
- * subscription report.
177998
- *
177999
- * This works around a matter.js 0.16.x bug where the subscription
178000
- * heartbeat timer (sendInterval) fails to fire for certain sessions,
178001
- * causing Apple Home (iOS via Apple TV proxy) to show "Updating...".
178002
- */
178003
- keepaliveNonce = false;
178004
177994
  async initialize() {
178005
177995
  this.state.operationalStateList = advertisedOperationalStates.map((id) => ({
178006
177996
  operationalStateId: id
@@ -178021,12 +178011,11 @@ var RvcOperationalStateServerBase = class extends RvcOperationalStateServer {
178021
178011
  this.agent
178022
178012
  );
178023
178013
  const previousState = this.state.operationalState;
178024
- this.keepaliveNonce = !this.keepaliveNonce;
178025
178014
  const errorStateId = newState === OperationalState4.Error ? ErrorState.Stuck : ErrorState.NoError;
178026
- const operationalError = { errorStateId };
178027
- if (this.keepaliveNonce) {
178028
- operationalError.errorStateDetails = "";
178029
- }
178015
+ const operationalError = {
178016
+ errorStateId,
178017
+ errorStateDetails: String(Date.now())
178018
+ };
178030
178019
  applyPatchState(
178031
178020
  this.state,
178032
178021
  {