diff --git a/runtimepy/channel/environment/base.py b/runtimepy/channel/environment/base.py index ec18ab4a..48d80ada 100644 --- a/runtimepy/channel/environment/base.py +++ b/runtimepy/channel/environment/base.py @@ -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() diff --git a/tests/channel/environment/test_create.py b/tests/channel/environment/test_create.py index 058a077f..a9aa9e17 100644 --- a/tests/channel/environment/test_create.py +++ b/tests/channel/environment/test_create.py @@ -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() @@ -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