Skip to content

Commit 69b06c4

Browse files
authored
Add default validator to easy resource (#764)
1 parent 43b10ed commit 69b06c4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/viam/resource/easy_resource.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inspect
22
import re
33
from abc import ABCMeta
4-
from typing import Callable, ClassVar, Mapping, Union
4+
from typing import Callable, ClassVar, Mapping, Sequence, Union
55

66
from viam.proto.app.robot import ComponentConfig
77
from viam.proto.common import ResourceName
@@ -121,6 +121,19 @@ def new(cls, config: ComponentConfig, dependencies: Mapping[ResourceName, Resour
121121
self.reconfigure(config, dependencies)
122122
return self
123123

124+
@classmethod
125+
def validate_config(cls, config: ComponentConfig) -> Sequence[str]:
126+
"""This method allows you to validate the configuration object received from the machine,
127+
as well as to return any implicit dependencies based on that `config`.
128+
129+
Args:
130+
config (ComponentConfig): The configuration for this resource
131+
132+
Returns:
133+
Sequence[str]: A list of implicit dependencies
134+
"""
135+
return []
136+
124137
@classmethod
125138
def register(cls):
126139
"""
@@ -133,7 +146,7 @@ def register(cls):
133146
Registry.register_resource_creator(
134147
cls.SUBTYPE,
135148
cls.MODEL,
136-
ResourceCreatorRegistration(cls.new), # pyright: ignore [reportArgumentType]
149+
ResourceCreatorRegistration(cls.new, cls.validate_config), # pyright: ignore [reportArgumentType]
137150
)
138151

139152
def reconfigure(self, config: ComponentConfig, dependencies: Mapping[ResourceName, ResourceBase]):

0 commit comments

Comments
 (0)