@riddix/hamh 2.1.0-alpha.552 → 2.1.0-alpha.553

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.
@@ -175692,6 +175692,11 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175692
175692
  completedAreas = /* @__PURE__ */ new Set();
175693
175693
  /** Last known currentArea — used to detect room transitions */
175694
175694
  lastCurrentArea = null;
175695
+ /** Snapshot of selectedAreas taken when cleaning starts.
175696
+ * The start handler clears serviceArea.state.selectedAreas after
175697
+ * dispatching the HA action to prevent re-dispatch, but progress
175698
+ * tracking needs the original list for the entire cleaning session. */
175699
+ activeAreas = [];
175695
175700
  async initialize() {
175696
175701
  await super.initialize();
175697
175702
  const homeAssistant = await this.agent.load(HomeAssistantEntityBehavior);
@@ -175713,16 +175718,13 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175713
175718
  });
175714
175719
  if (previousMode !== newMode) {
175715
175720
  if (newMode === 0 /* Idle */) {
175721
+ this.trySetCurrentArea(null);
175716
175722
  this.completedAreas.clear();
175717
175723
  this.lastCurrentArea = null;
175718
- this.trySetCurrentArea(null);
175724
+ this.activeAreas = [];
175719
175725
  } else if (newMode === 1 /* Cleaning */) {
175720
- try {
175721
- const serviceArea = this.agent.get(ServiceAreaBehavior);
175722
- if (serviceArea.state.selectedAreas?.length > 0 && serviceArea.state.currentArea === null) {
175723
- this.trySetCurrentArea(serviceArea.state.selectedAreas[0]);
175724
- }
175725
- } catch {
175726
+ if (this.activeAreas.length > 0 && this.lastCurrentArea === null) {
175727
+ this.trySetCurrentArea(this.activeAreas[0]);
175726
175728
  }
175727
175729
  }
175728
175730
  }
@@ -175742,14 +175744,13 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175742
175744
  const stateProvider = this.agent.env.get(EntityStateProvider);
175743
175745
  const roomState = stateProvider.getState(currentRoomEntityId);
175744
175746
  if (!roomState || !roomState.state) return;
175747
+ if (this.activeAreas.length === 0) return;
175745
175748
  const serviceArea = this.agent.get(ServiceAreaBehavior);
175746
- const selectedAreas = serviceArea.state.selectedAreas;
175747
- if (!selectedAreas || selectedAreas.length === 0) return;
175748
175749
  const segmentId = roomState.attributes?.segment_id;
175749
175750
  const roomName = roomState.state;
175750
175751
  let matchedAreaId = null;
175751
175752
  if (segmentId != null) {
175752
- if (selectedAreas.includes(segmentId)) {
175753
+ if (this.activeAreas.includes(segmentId)) {
175753
175754
  matchedAreaId = segmentId;
175754
175755
  }
175755
175756
  }
@@ -175757,7 +175758,7 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175757
175758
  const area = serviceArea.state.supportedAreas.find(
175758
175759
  (a) => a.areaInfo.locationInfo?.locationName?.toLowerCase() === roomName.toLowerCase()
175759
175760
  );
175760
- if (area && selectedAreas.includes(area.areaId)) {
175761
+ if (area && this.activeAreas.includes(area.areaId)) {
175761
175762
  matchedAreaId = area.areaId;
175762
175763
  }
175763
175764
  }
@@ -175796,21 +175797,20 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175796
175797
  * - null: mark all areas as Completed (cleaning done)
175797
175798
  * - areaId: mark that area as Operating, others as Pending
175798
175799
  *
175799
- * Rebuilds progress from selectedAreas (plain number array) instead of
175800
- * reading managed state progress entries, which avoids infinite recursion
175801
- * in matter.js property getters during transaction pre-commit.
175800
+ * Uses the activeAreas snapshot (plain number array) instead of
175801
+ * managed state entries, which avoids infinite recursion in
175802
+ * matter.js property getters during transaction pre-commit.
175802
175803
  */
175803
175804
  updateProgress(serviceArea, areaId) {
175805
+ if (this.activeAreas.length === 0) return;
175804
175806
  const state = serviceArea.state;
175805
- const selectedAreas = serviceArea.state.selectedAreas;
175806
- if (!selectedAreas || selectedAreas.length === 0) return;
175807
175807
  if (areaId === null) {
175808
- state.progress = selectedAreas.map((id) => ({
175808
+ state.progress = this.activeAreas.map((id) => ({
175809
175809
  areaId: id,
175810
175810
  status: ServiceArea3.OperationalStatus.Completed
175811
175811
  }));
175812
175812
  } else {
175813
- state.progress = selectedAreas.map((id) => ({
175813
+ state.progress = this.activeAreas.map((id) => ({
175814
175814
  areaId: id,
175815
175815
  status: id === areaId ? ServiceArea3.OperationalStatus.Operating : this.completedAreas.has(id) ? ServiceArea3.OperationalStatus.Completed : ServiceArea3.OperationalStatus.Pending
175816
175816
  }));
@@ -175846,7 +175846,8 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175846
175846
  try {
175847
175847
  const serviceArea = this.agent.get(ServiceAreaBehavior);
175848
175848
  if (serviceArea.state.selectedAreas?.length > 0) {
175849
- this.trySetCurrentArea(serviceArea.state.selectedAreas[0]);
175849
+ this.activeAreas = [...serviceArea.state.selectedAreas];
175850
+ this.trySetCurrentArea(this.activeAreas[0]);
175850
175851
  homeAssistant.callAction(this.state.config.start(void 0, this.agent));
175851
175852
  this.state.currentMode = newMode;
175852
175853
  return {
@@ -175857,7 +175858,9 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175857
175858
  } catch {
175858
175859
  }
175859
175860
  if (this.state.config.cleanRoom) {
175860
- this.trySetCurrentArea(this.findAreaIdForMode(newMode));
175861
+ const areaId = this.findAreaIdForMode(newMode);
175862
+ this.activeAreas = areaId !== null ? [areaId] : [];
175863
+ this.trySetCurrentArea(areaId);
175861
175864
  homeAssistant.callAction(
175862
175865
  this.state.config.cleanRoom(newMode, this.agent)
175863
175866
  );
@@ -175873,7 +175876,8 @@ var RvcRunModeServerBase = class extends RvcRunModeServer {
175873
175876
  try {
175874
175877
  const serviceArea = this.agent.get(ServiceAreaBehavior);
175875
175878
  if (serviceArea.state.selectedAreas?.length > 0) {
175876
- this.trySetCurrentArea(serviceArea.state.selectedAreas[0]);
175879
+ this.activeAreas = [...serviceArea.state.selectedAreas];
175880
+ this.trySetCurrentArea(this.activeAreas[0]);
175877
175881
  }
175878
175882
  } catch {
175879
175883
  }