|
1 | 1 | import abc |
2 | | -from typing import TYPE_CHECKING, Any, SupportsBytes, ClassVar, SupportsFloat, List, Mapping, Optional, cast, Union |
| 2 | +from typing import ( |
| 3 | + TYPE_CHECKING, |
| 4 | + Any, |
| 5 | + ClassVar, |
| 6 | + List, |
| 7 | + Mapping, |
| 8 | + Optional, |
| 9 | + SupportsBytes, |
| 10 | + SupportsFloat, |
| 11 | + Union, |
| 12 | + cast, |
| 13 | +) |
3 | 14 |
|
4 | 15 | from typing_extensions import Self |
5 | 16 |
|
6 | 17 | from viam.operations import Operation |
7 | | -from viam.proto.common import ResourceName |
| 18 | +from viam.resource.types import ResourceBase |
8 | 19 |
|
9 | 20 | if TYPE_CHECKING: |
10 | 21 | from viam.resource.types import Subtype |
|
14 | 25 | ValueTypes = Union[bool, SupportsBytes, SupportsFloat, List, Mapping, str, None] |
15 | 26 |
|
16 | 27 |
|
17 | | -class ComponentBase(abc.ABC): |
| 28 | +class ComponentBase(abc.ABC, ResourceBase): |
18 | 29 | """ |
19 | 30 | Base component. |
20 | 31 | All components must inherit from this class. |
21 | 32 | """ |
22 | 33 |
|
23 | 34 | SUBTYPE: ClassVar["Subtype"] |
24 | 35 |
|
25 | | - name: str |
26 | | - |
27 | 36 | def __init__(self, name: str): |
28 | 37 | self.name = name |
29 | 38 |
|
30 | | - @classmethod |
31 | | - def get_resource_name(cls, name: str) -> ResourceName: |
32 | | - """ |
33 | | - Get the ResourceName for this component type with the given name |
34 | | -
|
35 | | - Args: |
36 | | - name (str): The name of the Component |
37 | | - """ |
38 | | - return ResourceName( |
39 | | - namespace=cls.SUBTYPE.namespace, |
40 | | - type=cls.SUBTYPE.resource_type, |
41 | | - subtype=cls.SUBTYPE.resource_subtype, |
42 | | - name=name, |
43 | | - ) |
44 | | - |
45 | 39 | @classmethod |
46 | 40 | def from_robot(cls, robot: "RobotClient", name: str) -> Self: |
47 | 41 | """Get the component named ``name`` from the provided robot. |
@@ -72,15 +66,4 @@ def get_operation(self, kwargs: Mapping[str, Any]) -> Operation: |
72 | 66 | return kwargs.get(Operation.ARG_NAME, Operation._noop()) |
73 | 67 |
|
74 | 68 | async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None, **kwargs) -> Mapping[str, ValueTypes]: |
75 | | - """Send/Receive arbitrary commands |
76 | | -
|
77 | | - Args: |
78 | | - command (Mapping[str, ValueTypes]): The command to execute |
79 | | -
|
80 | | - Raises: |
81 | | - NotImplementedError: Raised if the component does not support arbitrary commands |
82 | | -
|
83 | | - Returns: |
84 | | - Mapping[str, ValueTypes]: Result of the executed command |
85 | | - """ |
86 | 69 | raise NotImplementedError() |
0 commit comments