Skip to content

Commit

Permalink
Refactor metadata handling in DisplayBuffer
Browse files Browse the repository at this point in the history
Added `metadata` property  with logic to update the display only
if the new value differs from the current one
  • Loading branch information
andreztz committed Jun 25, 2024
1 parent 3bc688b commit 5616ff1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions xradios/tui/buffers/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit 5616ff1

Please sign in to comment.