Skip to content

Commit d8d3d38

Browse files
committed
fix: public API devices stuck offline and sensor value flipping
1 parent 6de27a2 commit d8d3d38

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

custom_components/ecoflow_cloud/devices/status_tracker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def is_offline(self) -> bool:
8080

8181
@property
8282
def wants_status_poll(self) -> bool:
83-
"""True when status is uncertain and an explicit poll would help clarify."""
84-
return self.status == OnlineStatus.ASSUME_OFFLINE
83+
"""True when status is uncertain or offline and an explicit poll would help clarify."""
84+
return not self.is_online
8585

8686
@property
8787
def last_data_time(self) -> datetime:

custom_components/ecoflow_cloud/entities/__init__.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
self._attr_available = enabled
109109
self.__attributes_mapping: dict[str, str] = {}
110110
self.__attrs = OrderedDict[str, Any]()
111+
self._reset_done: bool = False
111112
if diagnostic is not None:
112113
self._attr_entity_category = EntityCategory.DIAGNOSTIC if diagnostic else None
113114

@@ -140,13 +141,22 @@ async def async_added_to_hass(self):
140141
# self.async_on_remove(d.dispose)
141142

142143
def _handle_coordinator_update(self) -> None:
143-
if self.coordinator.data.changed:
144-
self._updated(self.coordinator.data.data_holder.params)
145-
elif self._device.status_tracker.is_offline: # Device is offline
146-
# Reset sensors that should reset to default values
144+
params = self.coordinator.data.data_holder.params
145+
is_offline = self._device.status_tracker.is_offline
146+
147+
if is_offline and not self._reset_done:
147148
if isinstance(self, BaseSensorEntity) and self._attr_default_value is not None:
148-
self._mqtt_key_expr.update(self.coordinator.data.data_holder.params, self._attr_default_value)
149-
self._updated(self.coordinator.data.data_holder.params)
149+
self._mqtt_key_expr.update(params, self._attr_default_value)
150+
self._reset_done = True
151+
# fall through to _updated() to publish the reset value
152+
elif is_offline:
153+
return # already reset, ignore all ticks (including cached quota data) until back online
154+
elif self._reset_done:
155+
self._reset_done = False # first tick back online — restore immediately
156+
elif not self.coordinator.data.changed:
157+
return # online, no new data
158+
159+
self._updated(params)
150160

151161
def _updated(self, data: dict[str, Any]):
152162
# update attributes

0 commit comments

Comments
 (0)