Skip to content

Commit

Permalink
Add default validator to easy resource (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
njooma authored Oct 11, 2024
1 parent 43b10ed commit 69b06c4
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/viam/resource/easy_resource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import re
from abc import ABCMeta
from typing import Callable, ClassVar, Mapping, Union
from typing import Callable, ClassVar, Mapping, Sequence, Union

from viam.proto.app.robot import ComponentConfig
from viam.proto.common import ResourceName
Expand Down Expand Up @@ -121,6 +121,19 @@ def new(cls, config: ComponentConfig, dependencies: Mapping[ResourceName, Resour
self.reconfigure(config, dependencies)
return self

@classmethod
def validate_config(cls, config: ComponentConfig) -> Sequence[str]:
"""This method allows you to validate the configuration object received from the machine,
as well as to return any implicit dependencies based on that `config`.
Args:
config (ComponentConfig): The configuration for this resource
Returns:
Sequence[str]: A list of implicit dependencies
"""
return []

@classmethod
def register(cls):
"""
Expand All @@ -133,7 +146,7 @@ def register(cls):
Registry.register_resource_creator(
cls.SUBTYPE,
cls.MODEL,
ResourceCreatorRegistration(cls.new), # pyright: ignore [reportArgumentType]
ResourceCreatorRegistration(cls.new, cls.validate_config), # pyright: ignore [reportArgumentType]
)

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

0 comments on commit 69b06c4

Please sign in to comment.