From b239087018fdfee2508b58b5f582e4391944941a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=2E=20Santos?= Date: Tue, 25 Jun 2024 18:56:45 -0300 Subject: [PATCH] Refactor metadata handling in DisplayBuffer Added `metadata` property with logic to update the display only if the new value differs from the current one --- xradios/tui/buffers/display.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xradios/tui/buffers/display.py b/xradios/tui/buffers/display.py index 7331695..318cda2 100644 --- a/xradios/tui/buffers/display.py +++ b/xradios/tui/buffers/display.py @@ -19,7 +19,17 @@ def __init__(self, **kwargs): super().__init__( document=Document(content, 0), read_only=True, name=DISPLAY_BUFFER ) - self.metadata = None + self._metadata = None + + @property + def metadata(self): + return self._metadata + + @metadata.setter + def metadata(self, value): + if value != self._metadata: + self._metadata = value + self.update(value) def clear(self): self.set_document(Document('', 0), bypass_readonly=True) @@ -31,9 +41,8 @@ async def run(self): except Exception: pass else: - if result != self.metadata and all(result.values()): + if all(result.values()): self.metadata = result - self.update(result) await asyncio.sleep(30) def update(self, metadata):