viam-sdk 0.25.2__py3-none-linux_armv7l.whl → 0.62.0__py3-none-linux_armv7l.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of viam-sdk might be problematic. Click here for more details.
- viam/app/_logs.py +3 -6
- viam/app/app_client.py +606 -262
- viam/app/billing_client.py +60 -18
- viam/app/data_client.py +1086 -315
- viam/app/ml_training_client.py +51 -48
- viam/app/provisioning_client.py +3 -5
- viam/app/viam_client.py +105 -11
- viam/components/arm/__init__.py +1 -25
- viam/components/arm/arm.py +21 -22
- viam/components/arm/client.py +27 -30
- viam/components/arm/service.py +3 -3
- viam/components/audio_in/__init__.py +24 -0
- viam/components/audio_in/audio_in.py +74 -0
- viam/components/audio_in/client.py +76 -0
- viam/components/audio_in/service.py +83 -0
- viam/components/audio_input/__init__.py +1 -1
- viam/components/audio_input/audio_input.py +4 -3
- viam/components/audio_input/client.py +19 -8
- viam/components/audio_input/service.py +10 -0
- viam/components/audio_out/__init__.py +21 -0
- viam/components/audio_out/audio_out.py +72 -0
- viam/components/audio_out/client.py +67 -0
- viam/components/audio_out/service.py +63 -0
- viam/components/base/__init__.py +2 -10
- viam/components/base/base.py +20 -20
- viam/components/base/client.py +27 -30
- viam/components/board/__init__.py +2 -25
- viam/components/board/board.py +39 -77
- viam/components/board/client.py +39 -73
- viam/components/button/__init__.py +10 -0
- viam/components/button/button.py +41 -0
- viam/components/button/client.py +52 -0
- viam/components/button/service.py +46 -0
- viam/components/camera/__init__.py +1 -1
- viam/components/camera/camera.py +31 -22
- viam/components/camera/client.py +30 -20
- viam/components/camera/service.py +14 -12
- viam/components/component_base.py +10 -7
- viam/components/encoder/__init__.py +1 -1
- viam/components/encoder/client.py +15 -16
- viam/components/encoder/encoder.py +9 -9
- viam/components/gantry/__init__.py +1 -13
- viam/components/gantry/client.py +41 -28
- viam/components/gantry/gantry.py +48 -17
- viam/components/gantry/service.py +21 -5
- viam/components/generic/__init__.py +1 -1
- viam/components/generic/client.py +11 -7
- viam/components/generic/generic.py +3 -3
- viam/components/gripper/__init__.py +3 -12
- viam/components/gripper/client.py +43 -20
- viam/components/gripper/gripper.py +87 -12
- viam/components/gripper/service.py +32 -3
- viam/components/input/__init__.py +1 -14
- viam/components/input/client.py +22 -23
- viam/components/input/input.py +18 -12
- viam/components/motor/__init__.py +1 -21
- viam/components/motor/client.py +36 -42
- viam/components/motor/motor.py +24 -24
- viam/components/movement_sensor/__init__.py +1 -1
- viam/components/movement_sensor/client.py +33 -40
- viam/components/movement_sensor/movement_sensor.py +12 -12
- viam/components/pose_tracker/__init__.py +1 -1
- viam/components/pose_tracker/client.py +9 -8
- viam/components/pose_tracker/pose_tracker.py +2 -2
- viam/components/power_sensor/__init__.py +1 -1
- viam/components/power_sensor/client.py +15 -18
- viam/components/power_sensor/power_sensor.py +12 -12
- viam/components/sensor/__init__.py +1 -1
- viam/components/sensor/client.py +9 -8
- viam/components/sensor/sensor.py +5 -5
- viam/components/servo/__init__.py +1 -13
- viam/components/servo/client.py +18 -18
- viam/components/servo/servo.py +12 -12
- viam/components/switch/__init__.py +10 -0
- viam/components/switch/client.py +83 -0
- viam/components/switch/service.py +72 -0
- viam/components/switch/switch.py +95 -0
- viam/gen/app/agent/v1/agent_pb2.py +40 -29
- viam/gen/app/agent/v1/agent_pb2.pyi +73 -11
- viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +45 -42
- viam/gen/app/data/v1/data_grpc.py +98 -2
- viam/gen/app/data/v1/data_pb2.py +238 -119
- viam/gen/app/data/v1/data_pb2.pyi +804 -34
- viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
- viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +57 -0
- viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +387 -0
- viam/gen/app/dataset/v1/dataset_grpc.py +10 -2
- viam/gen/app/dataset/v1/dataset_pb2.py +38 -31
- viam/gen/app/dataset/v1/dataset_pb2.pyi +36 -1
- viam/gen/app/datasync/v1/data_sync_grpc.py +1 -1
- viam/gen/app/datasync/v1/data_sync_pb2.py +61 -51
- viam/gen/app/datasync/v1/data_sync_pb2.pyi +52 -12
- viam/gen/app/mlinference/__init__.py +0 -0
- viam/gen/app/mlinference/v1/__init__.py +0 -0
- viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
- viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
- viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
- viam/gen/app/mltraining/v1/ml_training_grpc.py +18 -2
- viam/gen/app/mltraining/v1/ml_training_pb2.py +134 -101
- viam/gen/app/mltraining/v1/ml_training_pb2.pyi +193 -7
- viam/gen/app/packages/v1/packages_pb2.py +43 -40
- viam/gen/app/v1/app_grpc.py +290 -2
- viam/gen/app/v1/app_pb2.py +670 -453
- viam/gen/app/v1/app_pb2.pyi +3133 -947
- viam/gen/app/v1/billing_grpc.py +34 -2
- viam/gen/app/v1/billing_pb2.py +94 -35
- viam/gen/app/v1/billing_pb2.pyi +314 -61
- viam/gen/app/v1/end_user_pb2.py +50 -29
- viam/gen/app/v1/robot_pb2.py +120 -111
- viam/gen/app/v1/robot_pb2.pyi +137 -15
- viam/gen/common/v1/common_pb2.py +86 -66
- viam/gen/common/v1/common_pb2.pyi +184 -8
- viam/gen/component/arm/v1/arm_grpc.py +18 -2
- viam/gen/component/arm/v1/arm_pb2.py +68 -55
- viam/gen/component/arm/v1/arm_pb2.pyi +73 -3
- viam/gen/component/audioin/__init__.py +0 -0
- viam/gen/component/audioin/v1/__init__.py +0 -0
- viam/gen/component/audioin/v1/audioin_grpc.py +54 -0
- viam/gen/component/audioin/v1/audioin_pb2.py +34 -0
- viam/gen/component/audioin/v1/audioin_pb2.pyi +94 -0
- viam/gen/component/audioinput/v1/audioinput_pb2.py +35 -32
- viam/gen/component/audioout/__init__.py +0 -0
- viam/gen/component/audioout/v1/__init__.py +0 -0
- viam/gen/component/audioout/v1/audioout_grpc.py +54 -0
- viam/gen/component/audioout/v1/audioout_pb2.py +32 -0
- viam/gen/component/audioout/v1/audioout_pb2.pyi +47 -0
- viam/gen/component/base/v1/base_pb2.py +57 -54
- viam/gen/component/board/v1/board_pb2.py +93 -90
- viam/gen/component/button/__init__.py +0 -0
- viam/gen/component/button/v1/__init__.py +0 -0
- viam/gen/component/button/v1/button_grpc.py +38 -0
- viam/gen/component/button/v1/button_pb2.py +28 -0
- viam/gen/component/button/v1/button_pb2.pyi +39 -0
- viam/gen/component/camera/v1/camera_pb2.py +58 -55
- viam/gen/component/camera/v1/camera_pb2.pyi +31 -7
- viam/gen/component/encoder/v1/encoder_pb2.py +35 -32
- viam/gen/component/gantry/v1/gantry_grpc.py +9 -1
- viam/gen/component/gantry/v1/gantry_pb2.py +56 -51
- viam/gen/component/generic/v1/generic_pb2.py +15 -12
- viam/gen/component/gripper/v1/gripper_grpc.py +18 -2
- viam/gen/component/gripper/v1/gripper_pb2.py +48 -37
- viam/gen/component/gripper/v1/gripper_pb2.pyi +43 -1
- viam/gen/component/inputcontroller/v1/input_controller_pb2.py +45 -42
- viam/gen/component/motor/v1/motor_pb2.py +77 -74
- viam/gen/component/movementsensor/v1/movementsensor_pb2.py +69 -66
- viam/gen/component/posetracker/v1/pose_tracker_pb2.py +25 -22
- viam/gen/component/powersensor/v1/powersensor_pb2.py +33 -30
- viam/gen/component/sensor/v1/sensor_pb2.py +17 -14
- viam/gen/component/servo/v1/servo_pb2.py +41 -38
- viam/gen/component/switch/__init__.py +0 -0
- viam/gen/component/switch/v1/__init__.py +0 -0
- viam/gen/component/switch/v1/switch_grpc.py +54 -0
- viam/gen/component/switch/v1/switch_pb2.py +40 -0
- viam/gen/component/switch/v1/switch_pb2.pyi +116 -0
- viam/gen/component/testecho/v1/testecho_pb2.py +29 -26
- viam/gen/module/v1/module_pb2.py +36 -33
- viam/gen/module/v1/module_pb2.pyi +7 -2
- viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +26 -23
- viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +23 -20
- viam/gen/proto/rpc/v1/auth_pb2.py +27 -24
- viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +35 -32
- viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +62 -57
- viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +18 -4
- viam/gen/provisioning/v1/provisioning_grpc.py +10 -2
- viam/gen/provisioning/v1/provisioning_pb2.py +38 -31
- viam/gen/provisioning/v1/provisioning_pb2.pyi +20 -2
- viam/gen/robot/v1/robot_grpc.py +61 -29
- viam/gen/robot/v1/robot_pb2.py +186 -155
- viam/gen/robot/v1/robot_pb2.pyi +278 -59
- viam/gen/service/datamanager/v1/data_manager_grpc.py +11 -2
- viam/gen/service/datamanager/v1/data_manager_pb2.py +27 -17
- viam/gen/service/datamanager/v1/data_manager_pb2.pyi +47 -1
- viam/gen/service/discovery/__init__.py +0 -0
- viam/gen/service/discovery/v1/__init__.py +0 -0
- viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
- viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
- viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
- viam/gen/service/generic/v1/generic_pb2.py +13 -10
- viam/gen/service/mlmodel/v1/mlmodel_pb2.py +75 -72
- viam/gen/service/motion/v1/motion_pb2.py +118 -85
- viam/gen/service/motion/v1/motion_pb2.pyi +130 -68
- viam/gen/service/navigation/v1/navigation_pb2.py +75 -72
- viam/gen/service/sensors/v1/sensors_pb2.py +59 -56
- viam/gen/service/shell/v1/shell_pb2.py +35 -32
- viam/gen/service/slam/v1/slam_pb2.py +43 -40
- viam/gen/service/slam/v1/slam_pb2.pyi +1 -1
- viam/gen/service/video/__init__.py +0 -0
- viam/gen/service/video/v1/__init__.py +0 -0
- viam/gen/service/video/v1/video_grpc.py +39 -0
- viam/gen/service/video/v1/video_pb2.py +29 -0
- viam/gen/service/video/v1/video_pb2.pyi +72 -0
- viam/gen/service/vision/v1/vision_pb2.py +60 -57
- viam/gen/service/vision/v1/vision_pb2.pyi +28 -3
- viam/gen/service/worldstatestore/__init__.py +0 -0
- viam/gen/service/worldstatestore/v1/__init__.py +0 -0
- viam/gen/service/worldstatestore/v1/world_state_store_grpc.py +55 -0
- viam/gen/service/worldstatestore/v1/world_state_store_pb2.py +39 -0
- viam/gen/service/worldstatestore/v1/world_state_store_pb2.pyi +171 -0
- viam/gen/stream/v1/stream_grpc.py +17 -1
- viam/gen/stream/v1/stream_pb2.py +34 -21
- viam/gen/stream/v1/stream_pb2.pyi +79 -1
- viam/gen/tagger/v1/tagger_pb2.py +9 -8
- viam/logging.py +77 -18
- viam/media/audio.py +28 -0
- viam/media/utils/pil/__init__.py +7 -3
- viam/media/video.py +80 -17
- viam/module/module.py +111 -38
- viam/module/resource_data_consumer.py +41 -0
- viam/module/service.py +9 -1
- viam/module/types.py +2 -4
- viam/proto/app/__init__.py +199 -0
- viam/proto/app/agent/__init__.py +5 -2
- viam/proto/app/billing.py +31 -4
- viam/proto/app/cloudslam/__init__.py +1 -0
- viam/proto/app/data/__init__.py +63 -0
- viam/proto/app/datapipelines/__init__.py +56 -0
- viam/proto/app/dataset/__init__.py +5 -0
- viam/proto/app/datasync/__init__.py +3 -0
- viam/proto/app/end_user.py +1 -0
- viam/proto/app/mlinference/__init__.py +15 -0
- viam/proto/app/mltraining/__init__.py +13 -0
- viam/proto/app/packages/__init__.py +1 -0
- viam/proto/app/robot.py +7 -0
- viam/proto/common/__init__.py +15 -0
- viam/proto/component/arm/__init__.py +7 -0
- viam/proto/component/audioin/__init__.py +16 -0
- viam/proto/component/audioinput/__init__.py +1 -0
- viam/proto/component/audioout/__init__.py +15 -0
- viam/proto/component/base/__init__.py +1 -0
- viam/proto/component/board/__init__.py +1 -0
- viam/proto/component/button/__init__.py +15 -0
- viam/proto/component/camera/__init__.py +1 -0
- viam/proto/component/encoder/__init__.py +1 -0
- viam/proto/component/gantry/__init__.py +1 -0
- viam/proto/component/generic/__init__.py +1 -0
- viam/proto/component/gripper/__init__.py +5 -0
- viam/proto/component/inputcontroller/__init__.py +1 -0
- viam/proto/component/motor/__init__.py +1 -0
- viam/proto/component/movementsensor/__init__.py +1 -0
- viam/proto/component/posetracker/__init__.py +1 -0
- viam/proto/component/powersensor/__init__.py +1 -0
- viam/proto/component/sensor/__init__.py +1 -0
- viam/proto/component/servo/__init__.py +1 -0
- viam/proto/component/switch/__init__.py +26 -0
- viam/proto/component/testecho/__init__.py +1 -0
- viam/proto/module/__init__.py +1 -0
- viam/proto/provisioning/__init__.py +5 -0
- viam/proto/robot/__init__.py +29 -8
- viam/proto/rpc/auth.py +1 -0
- viam/proto/rpc/examples/echo/__init__.py +1 -0
- viam/proto/rpc/examples/echoresource/__init__.py +1 -0
- viam/proto/rpc/webrtc/grpc.py +1 -0
- viam/proto/rpc/webrtc/signaling.py +3 -0
- viam/proto/service/datamanager/__init__.py +9 -1
- viam/proto/service/discovery/__init__.py +15 -0
- viam/proto/service/generic/__init__.py +1 -0
- viam/proto/service/mlmodel/__init__.py +1 -0
- viam/proto/service/motion/__init__.py +3 -0
- viam/proto/service/navigation/__init__.py +1 -0
- viam/proto/service/sensors/__init__.py +1 -0
- viam/proto/service/shell/__init__.py +1 -0
- viam/proto/service/slam/__init__.py +1 -0
- viam/proto/service/video/__init__.py +15 -0
- viam/proto/service/vision/__init__.py +1 -0
- viam/proto/service/worldstatestore/__init__.py +32 -0
- viam/proto/stream/__init__.py +11 -0
- viam/py.typed +0 -0
- viam/resource/base.py +12 -8
- viam/resource/easy_resource.py +24 -13
- viam/resource/manager.py +6 -5
- viam/resource/registry.py +39 -51
- viam/resource/rpc_client_base.py +33 -1
- viam/resource/types.py +13 -14
- viam/robot/client.py +190 -122
- viam/robot/service.py +2 -50
- viam/rpc/dial.py +54 -4
- viam/rpc/libviam_rust_utils.so +0 -0
- viam/rpc/server.py +25 -11
- viam/rpc/types.py +2 -4
- viam/services/discovery/__init__.py +12 -0
- viam/services/discovery/client.py +55 -0
- viam/services/discovery/discovery.py +52 -0
- viam/services/discovery/service.py +43 -0
- viam/services/generic/__init__.py +1 -1
- viam/services/generic/client.py +8 -5
- viam/services/generic/generic.py +2 -2
- viam/services/mlmodel/__init__.py +1 -1
- viam/services/mlmodel/client.py +17 -7
- viam/services/mlmodel/mlmodel.py +23 -12
- viam/services/mlmodel/service.py +5 -2
- viam/services/mlmodel/utils.py +11 -1
- viam/services/motion/__init__.py +2 -2
- viam/services/motion/client.py +32 -32
- viam/services/motion/motion.py +66 -62
- viam/services/navigation/__init__.py +1 -1
- viam/services/navigation/client.py +30 -20
- viam/services/navigation/navigation.py +23 -23
- viam/services/service_base.py +13 -9
- viam/services/service_client_base.py +3 -3
- viam/services/slam/__init__.py +1 -1
- viam/services/slam/client.py +15 -10
- viam/services/slam/slam.py +11 -11
- viam/services/vision/__init__.py +1 -1
- viam/services/vision/client.py +31 -24
- viam/services/vision/service.py +8 -8
- viam/services/vision/vision.py +36 -53
- viam/services/worldstatestore/__init__.py +18 -0
- viam/services/worldstatestore/client.py +94 -0
- viam/services/worldstatestore/service.py +55 -0
- viam/services/worldstatestore/worldstatestore.py +90 -0
- viam/sessions_client.py +115 -46
- viam/streams.py +3 -6
- viam/utils.py +44 -14
- viam/version_metadata.py +4 -0
- {viam_sdk-0.25.2.dist-info → viam_sdk-0.62.0.dist-info}/METADATA +27 -28
- viam_sdk-0.62.0.dist-info/RECORD +514 -0
- {viam_sdk-0.25.2.dist-info → viam_sdk-0.62.0.dist-info}/WHEEL +1 -1
- viam/gen/proto/rpc/examples/fileupload/v1/fileupload_grpc.py +0 -27
- viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.py +0 -18
- viam/gen/proto/rpc/examples/fileupload/v1/fileupload_pb2.pyi +0 -45
- viam/proto/rpc/examples/fileupload/__init__.py +0 -18
- viam/services/sensors/__init__.py +0 -5
- viam/services/sensors/client.py +0 -65
- viam_sdk-0.25.2.dist-info/LICENSE +0 -202
- viam_sdk-0.25.2.dist-info/RECORD +0 -442
- /viam/gen/{proto/rpc/examples/fileupload → app/datapipelines}/__init__.py +0 -0
- /viam/gen/{proto/rpc/examples/fileupload → app/datapipelines}/v1/__init__.py +0 -0
- /LICENSE → /viam_sdk-0.62.0.dist-info/licenses/LICENSE +0 -0
viam/resource/registry.py
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
2
|
from threading import Lock
|
|
3
|
-
from typing import TYPE_CHECKING,
|
|
3
|
+
from typing import TYPE_CHECKING, Callable, ClassVar, Dict, Generic, Mapping, Type, TypeVar
|
|
4
4
|
|
|
5
|
-
from google.protobuf.struct_pb2 import Struct
|
|
6
5
|
from grpclib.client import Channel
|
|
7
6
|
|
|
8
7
|
from viam.errors import DuplicateResourceError, ResourceNotFoundError, ValidationError
|
|
9
|
-
from viam.proto.robot import Status
|
|
10
8
|
|
|
11
9
|
from .base import ResourceBase
|
|
12
10
|
|
|
13
11
|
if TYPE_CHECKING:
|
|
14
12
|
from .rpc_service_base import ResourceRPCServiceBase
|
|
15
|
-
from .types import Model, ResourceCreator,
|
|
13
|
+
from .types import API, Model, ResourceCreator, Validator
|
|
16
14
|
|
|
17
15
|
Resource = TypeVar("Resource", bound=ResourceBase)
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
async def default_create_status(resource: ResourceBase) -> Status:
|
|
21
|
-
return Status(name=resource.get_resource_name(resource.name), status=Struct())
|
|
22
|
-
|
|
23
|
-
|
|
24
18
|
@dataclass
|
|
25
19
|
class ResourceCreatorRegistration:
|
|
26
20
|
"""An object representing a resource creator to be registered.
|
|
@@ -33,7 +27,7 @@ class ResourceCreatorRegistration:
|
|
|
33
27
|
"""A function that can create a resource given a mapping of dependencies (``ResourceName`` to ``ResourceBase``
|
|
34
28
|
"""
|
|
35
29
|
|
|
36
|
-
validator: "Validator" = lambda x: []
|
|
30
|
+
validator: "Validator" = lambda x: ([], [])
|
|
37
31
|
"""A function that can validate a resource and return implicit dependencies.
|
|
38
32
|
|
|
39
33
|
If called without a validator function, default to a function returning an empty Sequence
|
|
@@ -63,12 +57,6 @@ class ResourceRegistration(Generic[Resource]):
|
|
|
63
57
|
"""A function that will create the RPC client for this resource
|
|
64
58
|
"""
|
|
65
59
|
|
|
66
|
-
create_status: Callable[[Resource], Coroutine[Any, Any, Status]] = default_create_status
|
|
67
|
-
"""A function to create a Status object for this resource.
|
|
68
|
-
|
|
69
|
-
If the resource does not provide a custom status type, the default implementation can be used.
|
|
70
|
-
"""
|
|
71
|
-
|
|
72
60
|
|
|
73
61
|
class Registry:
|
|
74
62
|
"""The global registry of robotic parts.
|
|
@@ -82,44 +70,44 @@ class Registry:
|
|
|
82
70
|
resource using ``Registry.register(...)``.
|
|
83
71
|
"""
|
|
84
72
|
|
|
85
|
-
|
|
73
|
+
_APIS: ClassVar[Dict["API", ResourceRegistration]] = {}
|
|
86
74
|
_RESOURCES: ClassVar[Dict[str, ResourceCreatorRegistration]] = {}
|
|
87
75
|
_lock: ClassVar[Lock] = Lock()
|
|
88
76
|
|
|
89
77
|
@classmethod
|
|
90
|
-
def
|
|
91
|
-
"""Register a
|
|
78
|
+
def register_api(cls, registration: ResourceRegistration[Resource]):
|
|
79
|
+
"""Register a API with the Registry
|
|
92
80
|
|
|
93
81
|
Args:
|
|
94
|
-
registration (ResourceRegistration): Object containing registration data for the
|
|
82
|
+
registration (ResourceRegistration): Object containing registration data for the API
|
|
95
83
|
|
|
96
84
|
Raises:
|
|
97
|
-
DuplicateResourceError: Raised if the
|
|
85
|
+
DuplicateResourceError: Raised if the API to register is already in the registry
|
|
98
86
|
ValidationError: Raised if registration is missing any necessary parameters
|
|
99
87
|
"""
|
|
100
88
|
with cls._lock:
|
|
101
|
-
if registration.resource_type.
|
|
102
|
-
raise DuplicateResourceError(str(registration.resource_type.
|
|
89
|
+
if registration.resource_type.API in cls._APIS:
|
|
90
|
+
raise DuplicateResourceError(str(registration.resource_type.API))
|
|
103
91
|
|
|
104
92
|
if registration.resource_type and registration.rpc_service and registration.create_rpc_client:
|
|
105
|
-
cls.
|
|
93
|
+
cls._APIS[registration.resource_type.API] = registration
|
|
106
94
|
else:
|
|
107
95
|
raise ValidationError("Passed resource registration does not have correct parameters")
|
|
108
96
|
|
|
109
97
|
@classmethod
|
|
110
|
-
def register_resource_creator(cls,
|
|
111
|
-
"""Register a specific ``Model`` and validator function for the specific resource ``
|
|
98
|
+
def register_resource_creator(cls, api: "API", model: "Model", registration: ResourceCreatorRegistration):
|
|
99
|
+
"""Register a specific ``Model`` and validator function for the specific resource ``API`` with the Registry
|
|
112
100
|
|
|
113
101
|
Args:
|
|
114
|
-
|
|
102
|
+
api (API): The API of the resource
|
|
115
103
|
model (Model): The Model of the resource
|
|
116
104
|
registration (ResourceCreatorRegistration): The registration functions of the model
|
|
117
105
|
|
|
118
106
|
Raises:
|
|
119
|
-
DuplicateResourceError: Raised if the
|
|
107
|
+
DuplicateResourceError: Raised if the API and Model pairing is already registered
|
|
120
108
|
ValidationError: Raised if registration does not have creator
|
|
121
109
|
"""
|
|
122
|
-
key = f"{
|
|
110
|
+
key = f"{api}/{model}"
|
|
123
111
|
with cls._lock:
|
|
124
112
|
if key in cls._RESOURCES:
|
|
125
113
|
raise DuplicateResourceError(key)
|
|
@@ -130,78 +118,78 @@ class Registry:
|
|
|
130
118
|
raise ValidationError("A creator function was not provided")
|
|
131
119
|
|
|
132
120
|
@classmethod
|
|
133
|
-
def
|
|
134
|
-
"""Lookup and retrieve a registered
|
|
121
|
+
def lookup_api(cls, api: "API") -> ResourceRegistration:
|
|
122
|
+
"""Lookup and retrieve a registered API by its name
|
|
135
123
|
|
|
136
124
|
Args:
|
|
137
|
-
|
|
125
|
+
api (str): The API of the resource
|
|
138
126
|
|
|
139
127
|
Raises:
|
|
140
|
-
ResourceNotFoundError: Raised if the
|
|
128
|
+
ResourceNotFoundError: Raised if the API is not registered
|
|
141
129
|
|
|
142
130
|
Returns:
|
|
143
131
|
ResourceRegistration: The registration object of the resource
|
|
144
132
|
"""
|
|
145
133
|
with cls._lock:
|
|
146
134
|
try:
|
|
147
|
-
return cls.
|
|
135
|
+
return cls._APIS[api]
|
|
148
136
|
except KeyError:
|
|
149
|
-
raise ResourceNotFoundError(
|
|
137
|
+
raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
|
|
150
138
|
|
|
151
139
|
@classmethod
|
|
152
|
-
def lookup_resource_creator(cls,
|
|
153
|
-
"""Lookup and retrieve a registered resource creator by its
|
|
140
|
+
def lookup_resource_creator(cls, api: "API", model: "Model") -> "ResourceCreator":
|
|
141
|
+
"""Lookup and retrieve a registered resource creator by its API and model
|
|
154
142
|
|
|
155
143
|
Args:
|
|
156
|
-
|
|
144
|
+
api (API): The API of the resource
|
|
157
145
|
model (Model): The Model of the resource
|
|
158
146
|
|
|
159
147
|
Raises:
|
|
160
|
-
ResourceNotFoundError: Raised if the
|
|
148
|
+
ResourceNotFoundError: Raised if the API Model pairing is not registered
|
|
161
149
|
|
|
162
150
|
Returns:
|
|
163
151
|
ResourceCreator: The function to create the resource
|
|
164
152
|
"""
|
|
165
153
|
with cls._lock:
|
|
166
154
|
try:
|
|
167
|
-
return cls._RESOURCES[f"{
|
|
155
|
+
return cls._RESOURCES[f"{api}/{model}"].creator
|
|
168
156
|
except KeyError:
|
|
169
|
-
raise ResourceNotFoundError(
|
|
157
|
+
raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
|
|
170
158
|
|
|
171
159
|
@classmethod
|
|
172
|
-
def lookup_validator(cls,
|
|
173
|
-
"""Lookup and retrieve a registered validator function by its
|
|
160
|
+
def lookup_validator(cls, api: "API", model: "Model") -> "Validator":
|
|
161
|
+
"""Lookup and retrieve a registered validator function by its API and model. If there is none, return None
|
|
174
162
|
|
|
175
163
|
Args:
|
|
176
|
-
|
|
164
|
+
api (API): The API of the resource
|
|
177
165
|
model (Model): The Model of the resource
|
|
178
166
|
|
|
179
167
|
Returns:
|
|
180
168
|
Validator: The function to validate the resource
|
|
181
169
|
"""
|
|
182
170
|
try:
|
|
183
|
-
return cls._RESOURCES[f"{
|
|
171
|
+
return cls._RESOURCES[f"{api}/{model}"].validator
|
|
184
172
|
except AttributeError:
|
|
185
|
-
return lambda x: []
|
|
173
|
+
return lambda x: ([], [])
|
|
186
174
|
except KeyError:
|
|
187
|
-
raise ResourceNotFoundError(
|
|
175
|
+
raise ResourceNotFoundError(api.resource_type, api.resource_subtype)
|
|
188
176
|
|
|
189
177
|
@classmethod
|
|
190
|
-
def
|
|
178
|
+
def REGISTERED_APIS(cls) -> Mapping["API", ResourceRegistration]:
|
|
191
179
|
"""The dictionary of all registered resources
|
|
192
|
-
- Key:
|
|
180
|
+
- Key: API of the resource
|
|
193
181
|
- Value: The registration object for the resource
|
|
194
182
|
|
|
195
183
|
Returns:
|
|
196
|
-
Mapping[
|
|
184
|
+
Mapping[API, ResourceRegistration]: All registered resources
|
|
197
185
|
"""
|
|
198
186
|
with cls._lock:
|
|
199
|
-
return cls.
|
|
187
|
+
return cls._APIS.copy()
|
|
200
188
|
|
|
201
189
|
@classmethod
|
|
202
190
|
def REGISTERED_RESOURCE_CREATORS(cls) -> Mapping[str, "ResourceCreatorRegistration"]:
|
|
203
191
|
"""The dictionary of all registered resources
|
|
204
|
-
- Key:
|
|
192
|
+
- Key: API/model
|
|
205
193
|
- Value: The ResourceCreatorRegistration for the resource
|
|
206
194
|
|
|
207
195
|
Returns:
|
viam/resource/rpc_client_base.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from random import choice
|
|
2
|
+
from string import ascii_lowercase
|
|
3
|
+
from typing import Any, Dict, Protocol, runtime_checkable
|
|
2
4
|
|
|
3
5
|
from grpclib.client import Channel
|
|
4
6
|
|
|
@@ -12,6 +14,36 @@ class ResourceRPCClientBase(Protocol):
|
|
|
12
14
|
Resource RPC clients must inherit from this class
|
|
13
15
|
"""
|
|
14
16
|
|
|
17
|
+
class Metadata:
|
|
18
|
+
metadata: Dict[str, str] = {}
|
|
19
|
+
|
|
20
|
+
def enable_debug_logging(self, key: str = ""):
|
|
21
|
+
"""Enables server-side debug logging for resource methods.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
key (str): The key to associate debug logs with. If not provided, will default to a randomly generated string value.
|
|
25
|
+
"""
|
|
26
|
+
if key == "":
|
|
27
|
+
key = "".join(choice(ascii_lowercase) for i in range(6))
|
|
28
|
+
self.metadata["dtname"] = key
|
|
29
|
+
|
|
30
|
+
def disable_debug_logging(self):
|
|
31
|
+
"""Disables server-side debug logging for resource methods."""
|
|
32
|
+
del self.metadata["dtname"]
|
|
33
|
+
|
|
34
|
+
def add_metadata(self, key: str, value: str):
|
|
35
|
+
"""Adds a key-value pair to the metadata"""
|
|
36
|
+
self.metadata[key] = value
|
|
37
|
+
|
|
38
|
+
def delete_metadata(self, key: str):
|
|
39
|
+
"""Removes a key-value pair from the metadata by key"""
|
|
40
|
+
del self.metadata[key]
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def proto(self):
|
|
44
|
+
"""Returns metadata in a gRPC-appropriate form"""
|
|
45
|
+
return [(k, v) for k, v in self.metadata.items()]
|
|
46
|
+
|
|
15
47
|
channel: Channel
|
|
16
48
|
client: Any
|
|
17
49
|
|
viam/resource/types.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import re
|
|
2
2
|
import sys
|
|
3
|
-
from typing import TYPE_CHECKING, Callable, ClassVar, Mapping, Optional, Protocol, Sequence, runtime_checkable
|
|
3
|
+
from typing import TYPE_CHECKING, Callable, ClassVar, Mapping, Optional, Protocol, Sequence, Tuple, runtime_checkable
|
|
4
4
|
|
|
5
5
|
if sys.version_info >= (3, 10):
|
|
6
6
|
from typing import TypeAlias
|
|
@@ -20,7 +20,7 @@ RESOURCE_TYPE_COMPONENT = "component"
|
|
|
20
20
|
RESOURCE_TYPE_SERVICE = "service"
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
class
|
|
23
|
+
class API:
|
|
24
24
|
"""Represents a known component/service (resource) API"""
|
|
25
25
|
|
|
26
26
|
namespace: str
|
|
@@ -41,45 +41,45 @@ class Subtype:
|
|
|
41
41
|
return f"{self.namespace}:{self.resource_type}:{self.resource_subtype}"
|
|
42
42
|
|
|
43
43
|
def __repr__(self) -> str:
|
|
44
|
-
return f"<viam.resource.types.
|
|
44
|
+
return f"<viam.resource.types.API {str(self)} at {hex(id(self))}>"
|
|
45
45
|
|
|
46
46
|
def __hash__(self) -> int:
|
|
47
47
|
return hash(str(self))
|
|
48
48
|
|
|
49
49
|
def __eq__(self, other: object) -> bool:
|
|
50
|
-
if isinstance(other,
|
|
50
|
+
if isinstance(other, API):
|
|
51
51
|
return str(self) == str(other)
|
|
52
52
|
return False
|
|
53
53
|
|
|
54
54
|
@classmethod
|
|
55
55
|
def from_resource_name(cls, resource_name: ResourceName) -> Self:
|
|
56
|
-
"""Convert a ```ResourceName``` into a ```
|
|
56
|
+
"""Convert a ```ResourceName``` into a ```API```
|
|
57
57
|
|
|
58
58
|
Args:
|
|
59
59
|
resource_name (viam.proto.common.ResourceName): The ResourceName to convert
|
|
60
60
|
|
|
61
61
|
Returns:
|
|
62
|
-
Self: A new
|
|
62
|
+
Self: A new API
|
|
63
63
|
"""
|
|
64
64
|
return cls(resource_name.namespace, resource_name.type, resource_name.subtype)
|
|
65
65
|
|
|
66
66
|
@classmethod
|
|
67
67
|
def from_string(cls, string: str) -> Self:
|
|
68
|
-
"""Create a ```
|
|
68
|
+
"""Create a ```API``` from its string representation (namespace:resource_type:resource_subtype)
|
|
69
69
|
|
|
70
70
|
Args:
|
|
71
|
-
string (str): The
|
|
71
|
+
string (str): The API as a string
|
|
72
72
|
|
|
73
73
|
Raises:
|
|
74
|
-
ValueError: Raised if the string does not represent a valid
|
|
74
|
+
ValueError: Raised if the string does not represent a valid API
|
|
75
75
|
|
|
76
76
|
Returns:
|
|
77
|
-
Self: A new
|
|
77
|
+
Self: A new API
|
|
78
78
|
"""
|
|
79
79
|
regex = re.compile(r"^([\w-]+):([\w-]+):([\w-]+)$")
|
|
80
80
|
match = regex.match(string)
|
|
81
81
|
if not match:
|
|
82
|
-
raise ValueError(f"{string} is not a valid
|
|
82
|
+
raise ValueError(f"{string} is not a valid API")
|
|
83
83
|
return cls(match.group(1), match.group(2), match.group(3))
|
|
84
84
|
|
|
85
85
|
|
|
@@ -203,12 +203,11 @@ def resource_name_from_string(string: str) -> ResourceName:
|
|
|
203
203
|
|
|
204
204
|
|
|
205
205
|
ResourceCreator: TypeAlias = Callable[[ComponentConfig, Mapping[ResourceName, "ResourceBase"]], "ResourceBase"]
|
|
206
|
-
Validator: TypeAlias = Callable[[ComponentConfig], Sequence[str]]
|
|
206
|
+
Validator: TypeAlias = Callable[[ComponentConfig], Tuple[Sequence[str], Sequence[str]]]
|
|
207
207
|
|
|
208
208
|
|
|
209
209
|
@runtime_checkable
|
|
210
210
|
class SupportsGetGeometries(Protocol):
|
|
211
211
|
"""The SupportsGetGeometries protocol defines the requirements for a resource to call get_geometries."""
|
|
212
212
|
|
|
213
|
-
async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None) -> GetGeometriesResponse:
|
|
214
|
-
...
|
|
213
|
+
async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None, **kwargs) -> GetGeometriesResponse: ...
|