viam.resource.easy_resource
Attributes
Classes
EasyResource is a mixin that simplifies the process of creating Viam modules (extension programs) |
Functions
|
Class decorator which adds error implementations of abstract functions. This means they will fail |
Module Contents
- viam.resource.easy_resource.modelRegex
- viam.resource.easy_resource.logger
- viam.resource.easy_resource.stub_model(cls: abc.ABCMeta) abc.ABCMeta [source]
Class decorator which adds error implementations of abstract functions. This means they will fail when called, rather than the default where they fail when instantiated. This is intended for developers who want to build and test incrementally, not for production use.
Example
@stub_model class MyMotor(Motor, EasyResource):
MODEL = ‘viam:motor:easy-resource-example’
Normally this class would fail to instantiate. With the decorator, it will succeed but the unimplemented methods will throw errors at runtime.
- class viam.resource.easy_resource.EasyResource(name: str)[source]
EasyResource is a mixin that simplifies the process of creating Viam modules (extension programs) and resources (the resource classes provided by those extension programs).
Basic usage:
class MyModel(Sensor, EasyResource): MODEL = "my-org:sensor:my-sensor" async def get_readings(self, **kwargs): return {"ok": True}
See examples/easy_resource/main.py for extended usage.
- SUBTYPE: ClassVar[viam.resource.types.Subtype]
- MODEL: ClassVar[viam.resource.types.Model]
- classmethod __init_subclass__(register=True, **kwargs)[source]
When you subclass this mixin, it parses cls.MODEL and registers cls in global registry.
- name
- classmethod new(config: viam.proto.app.robot.ComponentConfig, dependencies: Mapping[viam.proto.common.ResourceName, viam.resource.base.ResourceBase])[source]
This is passed to register_resource_creator; the default implementation calls reconfigure() when an instance of your model is instantiated. You can override this in your subclass.
- classmethod validate_config(config: viam.proto.app.robot.ComponentConfig) Sequence[str] [source]
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.
- Parameters:
config (ComponentConfig) – The configuration for this resource
- Returns:
A list of implicit dependencies
- Return type:
Sequence[str]
- classmethod register()[source]
This adds the model to the global registry. It is called by __init_subclass__ and you typically won’t call it directly.
- reconfigure(config: viam.proto.app.robot.ComponentConfig, dependencies: Mapping[viam.proto.common.ResourceName, viam.resource.base.ResourceBase])[source]