-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
08fd0e9
commit 810cd06
Showing
5 changed files
with
63 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
cli/module_generate/_templates/python/src/models/tmpl-resource.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import ClassVar, Mapping, Sequence, Self | ||
from viam.proto.app.robot import ComponentConfig | ||
from viam.proto.common import ResourceName | ||
from viam.resource.base import ResourceBase | ||
from viam.resource.easy_resource import EasyResource | ||
from viam.resource.types import Model, ModelFamily | ||
from viam.{{ .ResourceType }}s.{{ .ResourceSubtype }} import {{ .ResourceSubtypePascal }} | ||
|
||
|
||
class {{ .ModelPascal }}({{ .ResourceSubtypePascal }}, EasyResource): | ||
MODEL: ClassVar[Model] = "{{ .ModelTriple }}" | ||
|
||
@classmethod | ||
def new(cls, config: ComponentConfig, dependencies: Mapping[ResourceName, ResourceBase]) -> Self: | ||
"""This method creates a new instance of this {{ .ResourceSubtype }}. | ||
The default implementation sets the name from the `config` parameter and then calls `reconfigure`. | ||
Args: | ||
config (ComponentConfig): The configuration for this resource | ||
dependencies (Mapping[ResourceName, ResourceBase]): The dependencies (both implicit and explicit) | ||
Returns: | ||
Self: The resource | ||
""" | ||
return super().new(config, dependencies) | ||
|
||
@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 [] | ||
|
||
def reconfigure(self, config: ComponentConfig, dependencies: Mapping[ResourceName, ResourceBase]): | ||
"""This method allows you to dynamically update your service when it receives a new `config` object. | ||
Args: | ||
config (ComponentConfig): The new configuration | ||
dependencies (Mapping[ResourceName, ResourceBase]): Any dependencies (both implicit and explicit) | ||
""" | ||
return super().reconfigure(config, dependencies) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters