Skip to content

Commit

Permalink
Nest update_frame_versions().
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Nov 24, 2024
1 parent 584b128 commit f624d1d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pyplumio/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,20 @@ def __init__(self, queue: asyncio.Queue[Frame], network: NetworkInfo) -> None:
super().__init__(queue)
self._frame_versions = {}
self._network = network
self.subscribe(ATTR_FRAME_VERSIONS, self._update_frame_versions)

async def _update_frame_versions(self, versions: dict[int, int]) -> None:
"""Check frame versions and update outdated frames."""
for frame_type, version in versions.items():
if (
is_known_frame_type(frame_type)
and self.supports_frame_type(frame_type)
and not self.has_frame_version(frame_type, version)
):
request = await Request.create(frame_type, recipient=self.address)
self.queue.put_nowait(request)
self._frame_versions[frame_type] = version

async def update_frame_versions(versions: dict[int, int]) -> None:
"""Check frame versions and update outdated frames."""
for frame_type, version in versions.items():
if (
is_known_frame_type(frame_type)
and self.supports_frame_type(frame_type)
and not self.has_frame_version(frame_type, version)
):
request = await Request.create(frame_type, recipient=self.address)
self.queue.put_nowait(request)
self._frame_versions[frame_type] = version

self.subscribe(ATTR_FRAME_VERSIONS, update_frame_versions)

def has_frame_version(self, frame_type: int, version: int | None = None) -> bool:
"""Return True if frame data is up to date, False otherwise."""
Expand Down

0 comments on commit f624d1d

Please sign in to comment.