Skip to content

Commit

Permalink
Add age_ns environment query
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Sep 18, 2023
1 parent 0c43204 commit 9552cb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions runtimepy/channel/environment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,14 @@ def __eq__(self, other) -> bool:
return bool(
self.channels == other.channels and self.enums == other.enums
)

def age_ns(self, key: _RegistryKey) -> int:
"""Get the age of an entity based on registry key."""

chan = self.get(key)
if chan is not None:
prim = chan[0].raw
else:
prim = self.fields[key].raw

return prim.age_ns()
3 changes: 3 additions & 0 deletions tests/channel/environment/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def test_channel_environment_create_basic():
result = env.channel("sample_channel", "bool", enum=enum)
assert result

assert env.age_ns("sample_channel")

name = "test_field"
underlying = Uint8()

Expand All @@ -38,6 +40,7 @@ def test_channel_environment_create_basic():

assert proc.command("set test_field true")
assert underlying.value == 1
assert env.age_ns("test_field")

assert proc.command("set test_field false")
assert underlying.value == 0
Expand Down

0 comments on commit 9552cb3

Please sign in to comment.