Skip to content

Commit cf26d8a

Browse files
RSDK-2870: use api instead of subtype (#824)
1 parent a587b46 commit cf26d8a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+278
-273
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The SDK provides a number of abstract base components and services (collectively
122122
1. Define all requirements of the resource in `{RESOURCE_NAME}.py`
123123
1. Implement the gRPC service for the new resource in `service.py`
124124
1. Create a gRPC client for the new resource in `client.py`
125-
1. Register the subtype and define package exports in `__init__.py`
125+
1. Register the API and define package exports in `__init__.py`
126126
1. Write tests for the new resource and add the resource to `tests.mocks.{components|services}`
127127
1. If the resource is a component, add the component to `examples.server.v1.components` and its corresponding concrete type in `examples.server.v1.server`
128128

docs/examples/module_step2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def close(self):
3535

3636

3737
async def main():
38-
Registry.register_resource_creator(Sensor.SUBTYPE, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new))
38+
Registry.register_resource_creator(Sensor.API, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new))
3939

4040

4141
if __name__ == "__main__":

docs/examples/module_step2_optional.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def close(self):
5757

5858

5959
async def main():
60-
Registry.register_resource_creator(Sensor.SUBTYPE, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new, MySensor.validate_config))
60+
Registry.register_resource_creator(Sensor.API, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new, MySensor.validate_config))
6161

6262

6363
if __name__ == "__main__":

docs/examples/module_step3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ async def main():
4040
This function creates and starts a new module, after adding all desired resource model.
4141
Resource creators must be registered to the resource registry before the module adds the resource model.
4242
"""
43-
Registry.register_resource_creator(Sensor.SUBTYPE, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new))
43+
Registry.register_resource_creator(Sensor.API, MySensor.MODEL, ResourceCreatorRegistration(MySensor.new))
4444

4545
module = Module.from_args()
46-
module.add_model_from_registry(Sensor.SUBTYPE, MySensor.MODEL)
46+
module.add_model_from_registry(Sensor.API, MySensor.MODEL)
4747
await module.start()
4848

4949

examples/complex_module/src/arm/my_arm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ async def close(self):
115115
LOGGER.info(f"{self.name} is closed.")
116116

117117

118-
Registry.register_resource_creator(Arm.SUBTYPE, MyArm.MODEL, ResourceCreatorRegistration(MyArm.new))
118+
Registry.register_resource_creator(Arm.API, MyArm.MODEL, ResourceCreatorRegistration(MyArm.new))

examples/complex_module/src/base/my_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ async def get_geometries(self) -> List[Geometry]:
147147
raise NotImplementedError()
148148

149149

150-
Registry.register_resource_creator(Base.SUBTYPE, MyBase.MODEL, ResourceCreatorRegistration(MyBase.new, MyBase.validate_config))
150+
Registry.register_resource_creator(Base.API, MyBase.MODEL, ResourceCreatorRegistration(MyBase.new, MyBase.validate_config))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
This file registers the Gizmo subtype with the Viam Registry, as well as the specific MyGizmo model.
2+
This file registers the Gizmo API with the Viam Registry, as well as the specific MyGizmo model.
33
"""
44

55
from viam.components.motor import * # noqa: F403 Need to import motor so the component registers itself
66
from viam.resource.registry import Registry, ResourceRegistration
77

88
from .api import Gizmo, GizmoClient, GizmoService
99

10-
Registry.register_subtype(ResourceRegistration(Gizmo, GizmoService, lambda name, channel: GizmoClient(name, channel)))
10+
Registry.register_api(ResourceRegistration(Gizmo, GizmoService, lambda name, channel: GizmoClient(name, channel)))

examples/complex_module/src/gizmo/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
and the gRPC client that will be able to make calls to this component.
77
88
In this example, the ``Gizmo`` abstract class defines what functionality is required for all Gizmos. It extends ``ComponentBase``,
9-
as all component types must. It also defines its specific ``SUBTYPE``, which is used internally to keep track of supported types.
9+
as all component types must. It also defines its specific ``API``, which is used internally to keep track of supported types.
1010
1111
The ``GizmoService`` implements the gRPC service for the Gizmo. This will allow other robots and clients to make requests of the Gizmo.
1212
It extends both from ``GizmoServiceBase`` and ``ResourceRPCServiceBase``. The former is the gRPC service as defined by the proto,
@@ -28,7 +28,7 @@
2828
from viam.components.component_base import ComponentBase
2929
from viam.components.generic.client import do_command
3030
from viam.resource.rpc_service_base import ResourceRPCServiceBase
31-
from viam.resource.types import RESOURCE_TYPE_COMPONENT, Subtype
31+
from viam.resource.types import RESOURCE_TYPE_COMPONENT, API
3232
from viam.utils import ValueTypes
3333

3434
from ..proto.gizmo_grpc import GizmoServiceBase, GizmoServiceStub
@@ -49,7 +49,7 @@
4949
class Gizmo(ComponentBase):
5050
"""Example component to use with the example module."""
5151

52-
SUBTYPE: Final = Subtype("acme", RESOURCE_TYPE_COMPONENT, "gizmo")
52+
API: Final = API("acme", RESOURCE_TYPE_COMPONENT, "gizmo")
5353

5454
@abc.abstractmethod
5555
async def do_one(self, arg1: str, **kwargs) -> bool:

examples/complex_module/src/gizmo/my_gizmo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def validate_config(cls, config: ComponentConfig) -> Sequence[str]:
3838
# can raise errors that will be returned to the parent through gRPC. Validate functions can
3939
# also return a sequence of strings representing the implicit dependencies of the resource.
4040
if "invalid" in config.attributes.fields:
41-
raise Exception(f"'invalid' attribute not allowed for model {cls.SUBTYPE}:{cls.MODEL}")
41+
raise Exception(f"'invalid' attribute not allowed for model {cls.API}:{cls.MODEL}")
4242
arg1 = config.attributes.fields["arg1"].string_value
4343
if arg1 == "":
4444
raise Exception("A arg1 attribute is required for Gizmo component.")
@@ -79,4 +79,4 @@ async def close(self):
7979
LOGGER.info(f"{self.name} is closed.")
8080

8181

82-
Registry.register_resource_creator(Gizmo.SUBTYPE, MyGizmo.MODEL, ResourceCreatorRegistration(MyGizmo.new, MyGizmo.validate_config))
82+
Registry.register_resource_creator(Gizmo.API, MyGizmo.MODEL, ResourceCreatorRegistration(MyGizmo.new, MyGizmo.validate_config))

examples/complex_module/src/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ async def main():
1515
Resource models must be pre-registered. For an example, see the `gizmo.__init__.py` file.
1616
"""
1717
module = Module.from_args()
18-
module.add_model_from_registry(Gizmo.SUBTYPE, MyGizmo.MODEL)
19-
module.add_model_from_registry(SummationService.SUBTYPE, MySummationService.MODEL)
20-
module.add_model_from_registry(Arm.SUBTYPE, MyArm.MODEL)
21-
module.add_model_from_registry(Base.SUBTYPE, MyBase.MODEL)
18+
module.add_model_from_registry(Gizmo.API, MyGizmo.MODEL)
19+
module.add_model_from_registry(SummationService.API, MySummationService.MODEL)
20+
module.add_model_from_registry(Arm.API, MyArm.MODEL)
21+
module.add_model_from_registry(Base.API, MyBase.MODEL)
2222
await module.start()
2323

2424

0 commit comments

Comments
 (0)