Skip to content

Commit

Permalink
https://github.com/dvd-dev/hilo/issues/310
Browse files Browse the repository at this point in the history
Set internal state to assumed value (that one just set) to avoid a revert-to-original in the UI. We end up getting the actual value from SignalR later (0 to 10s later).
  • Loading branch information
nlz242 committed Dec 18, 2023
1 parent 88cf03c commit c69f0b1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pyhilo/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ async def _set_attribute(
) -> None:
if attribute in self.settable_attributes:
await self._api._set_device_attribute(self, attribute, value)
# Update internal state after sending request to API, assuming it will
# succeed and we will get a reading back form signalR. This avoids ui flickering.
self.update_readings(
DeviceReading(
**{
"deviceId": self.id,
"locationId": self.location_id,
"timeStampUTC": datetime.utcnow().isoformat(),
"value": value,
"device_attribute": attribute,
}
)
)
else:
LOG.warning(f"{self._tag} Invalid attribute {attribute} for device")

Expand Down

0 comments on commit c69f0b1

Please sign in to comment.