|
30 | 30 | "# Please excuse the boilerplate\n", |
31 | 31 | "%autoawait asyncio\n", |
32 | 32 | "import warnings\n", |
33 | | - "warnings.filterwarnings('ignore')" |
| 33 | + "\n", |
| 34 | + "warnings.filterwarnings(\"ignore\")" |
34 | 35 | ] |
35 | 36 | }, |
36 | 37 | { |
|
47 | 48 | "from viam.robot.client import RobotClient\n", |
48 | 49 | "from viam.rpc.dial import DialOptions\n", |
49 | 50 | "\n", |
| 51 | + "\n", |
50 | 52 | "async def connect() -> RobotClient:\n", |
51 | | - " options = RobotClient.Options(\n", |
52 | | - " dial_options=DialOptions(insecure=True, disable_webrtc=True),\n", |
53 | | - " log_level=logging.FATAL\n", |
54 | | - " )\n", |
55 | | - " return await RobotClient.at_address('localhost:9091', options)" |
| 53 | + " options = RobotClient.Options(dial_options=DialOptions(insecure=True, disable_webrtc=True), log_level=logging.FATAL)\n", |
| 54 | + " return await RobotClient.at_address(\"localhost:9091\", options)" |
56 | 55 | ] |
57 | 56 | }, |
58 | 57 | { |
|
132 | 131 | "from viam.robot.client import RobotClient\n", |
133 | 132 | "from viam.rpc.dial import DialOptions, dial\n", |
134 | 133 | "\n", |
| 134 | + "\n", |
135 | 135 | "async def connect_with_channel() -> RobotClient:\n", |
136 | | - " async with await dial('localhost:9091', DialOptions(insecure=True, disable_webrtc=True)) as channel:\n", |
| 136 | + " async with await dial(\"localhost:9091\", DialOptions(insecure=True, disable_webrtc=True)) as channel:\n", |
137 | 137 | " return await RobotClient.with_channel(channel, RobotClient.Options(refresh_interval=10, log_level=logging.FATAL))\n", |
138 | 138 | "\n", |
| 139 | + "\n", |
139 | 140 | "robot = await connect_with_channel()\n", |
140 | 141 | "print(robot.resource_names)\n", |
141 | 142 | "await robot.close()" |
|
167 | 168 | "image.save(\"foo.png\")\n", |
168 | 169 | "\n", |
169 | 170 | "# Don't forget to close the robot when you're done!\n", |
170 | | - "await robot.close()\n" |
| 171 | + "await robot.close()" |
171 | 172 | ] |
172 | 173 | }, |
173 | 174 | { |
|
210 | 211 | "source": [ |
211 | 212 | "from viam.services.vision import VisionClient\n", |
212 | 213 | "\n", |
| 214 | + "\n", |
213 | 215 | "async def vision():\n", |
214 | 216 | " robot = await connect_with_channel()\n", |
215 | 217 | " vision = VisionClient.from_robot(robot)\n", |
|
884 | 886 | "from pygments.lexers import PythonLexer\n", |
885 | 887 | "from pygments.formatters import HtmlFormatter\n", |
886 | 888 | "import IPython\n", |
887 | | - "with open('my_cool_arm.py') as f:\n", |
| 889 | + "\n", |
| 890 | + "with open(\"my_cool_arm.py\") as f:\n", |
888 | 891 | " code = f.read()\n", |
889 | 892 | "\n", |
890 | 893 | "formatter = HtmlFormatter()\n", |
891 | | - "IPython.display.HTML('<style type=\"text/css\">{}</style>{}'.format(\n", |
892 | | - " formatter.get_style_defs('.highlight'),\n", |
893 | | - " highlight(code, PythonLexer(), formatter)))" |
| 894 | + "IPython.display.HTML(\n", |
| 895 | + " '<style type=\"text/css\">{}</style>{}'.format(formatter.get_style_defs(\".highlight\"), highlight(code, PythonLexer(), formatter))\n", |
| 896 | + ")" |
894 | 897 | ] |
895 | 898 | }, |
896 | 899 | { |
|
938 | 941 | "\n", |
939 | 942 | "from my_cool_arm import MyCoolArm\n", |
940 | 943 | "\n", |
| 944 | + "\n", |
941 | 945 | "async def main():\n", |
942 | | - " srv = Server([MyCoolArm('my-arm')])\n", |
| 946 | + " srv = Server([MyCoolArm(\"my-arm\")])\n", |
943 | 947 | " await srv.serve()\n", |
944 | 948 | "\n", |
945 | | - "if __name__ == '__main__':\n", |
| 949 | + "\n", |
| 950 | + "if __name__ == \"__main__\":\n", |
946 | 951 | " try:\n", |
947 | 952 | " asyncio.run(main())\n", |
948 | 953 | " except:\n", |
|
1124 | 1129 | "source": [ |
1125 | 1130 | "from IPython.core.display import display, Image\n", |
1126 | 1131 | "\n", |
1127 | | - "display(Image(filename='./codediff.png'))" |
| 1132 | + "display(Image(filename=\"./codediff.png\"))" |
1128 | 1133 | ] |
1129 | 1134 | }, |
1130 | 1135 | { |
|
1160 | 1165 | "from viam.rpc.dial import DialOptions, Credentials\n", |
1161 | 1166 | "from viam.app.viam_client import ViamClient\n", |
1162 | 1167 | "\n", |
| 1168 | + "\n", |
1163 | 1169 | "async def connect() -> ViamClient:\n", |
1164 | | - " dial_options = DialOptions.with_api_key(api_key='<API_KEY>', api_key_id='<API_KEY_ID>')\n", |
| 1170 | + " dial_options = DialOptions.with_api_key(api_key=\"<API_KEY>\", api_key_id=\"<API_KEY_ID>\")\n", |
1165 | 1171 | " return await ViamClient.create_from_dial_options(dial_options)" |
1166 | 1172 | ] |
1167 | 1173 | }, |
|
1191 | 1197 | "from viam.app.app_client import AppClient\n", |
1192 | 1198 | "from viam.rpc.dial import _dial_direct\n", |
1193 | 1199 | "\n", |
| 1200 | + "\n", |
1194 | 1201 | "class MockViamClient:\n", |
1195 | 1202 | " @classmethod\n", |
1196 | 1203 | " async def create_viam_client(cls) -> Self:\n", |
|
1199 | 1206 | " self.data_client = DataClient(channel=self._channel, metadata={})\n", |
1200 | 1207 | " self.app_client = AppClient(channel=self._channel, metadata={})\n", |
1201 | 1208 | " return self\n", |
1202 | | - " \n", |
| 1209 | + "\n", |
1203 | 1210 | " _channel: Channel\n", |
1204 | 1211 | " data_client: DataClient\n", |
1205 | 1212 | " app_client: AppClient\n", |
1206 | 1213 | "\n", |
1207 | 1214 | " def close(self):\n", |
1208 | 1215 | " self._channel.close()\n", |
1209 | 1216 | "\n", |
1210 | | - "viam_client = await MockViamClient.create_viam_client()\n" |
| 1217 | + "\n", |
| 1218 | + "viam_client = await MockViamClient.create_viam_client()" |
1211 | 1219 | ] |
1212 | 1220 | }, |
1213 | 1221 | { |
|
1260 | 1268 | "from datetime import datetime\n", |
1261 | 1269 | "\n", |
1262 | 1270 | "left_motor_filter = data_client.create_filter(\n", |
1263 | | - " component_name=\"left_motor\",\n", |
1264 | | - " start_time=datetime(2023, 6, 5, 11),\n", |
1265 | | - " end_time=datetime(2023, 6, 5, 13, 30),\n", |
1266 | | - " tags=[\"speed_test_run\"]\n", |
| 1271 | + " component_name=\"left_motor\", start_time=datetime(2023, 6, 5, 11), end_time=datetime(2023, 6, 5, 13, 30), tags=[\"speed_test_run\"]\n", |
1267 | 1272 | ")\n", |
1268 | 1273 | "\n", |
1269 | 1274 | "data = await data_client.tabular_data_by_filter(filter=left_motor_filter)\n", |
|
1290 | 1295 | "time_received_1 = datetime(2023, 6, 5, 11, 0, 3)\n", |
1291 | 1296 | "\n", |
1292 | 1297 | "await data_client.tabular_data_capture_upload(\n", |
1293 | | - " part_id=\"<ID>\", # Unique ID of the relevant robot part.\n", |
1294 | | - " component_type='rdk:component:motor',\n", |
1295 | | - " component_name='left_motor',\n", |
1296 | | - " method_name='IsPowered',\n", |
| 1298 | + " part_id=\"<ID>\", # Unique ID of the relevant robot part.\n", |
| 1299 | + " component_type=\"rdk:component:motor\",\n", |
| 1300 | + " component_name=\"left_motor\",\n", |
| 1301 | + " method_name=\"IsPowered\",\n", |
1297 | 1302 | " method_parameters=None,\n", |
1298 | 1303 | " tags=[\"tag_1\", \"tag_2\"],\n", |
1299 | 1304 | " data_request_times=[(time_requested_1, time_received_1)],\n", |
1300 | | - " tabular_data=[{'PowerPCT': 0, 'IsPowered': False}]\n", |
| 1305 | + " tabular_data=[{\"PowerPCT\": 0, \"IsPowered\": False}],\n", |
1301 | 1306 | ")" |
1302 | 1307 | ] |
1303 | 1308 | }, |
|
1353 | 1358 | "for location in my_locations:\n", |
1354 | 1359 | " more_robots = await app_client.list_robots(location_id=location.id)\n", |
1355 | 1360 | " robots += more_robots\n", |
1356 | | - " \n", |
| 1361 | + "\n", |
1357 | 1362 | "for robot in robots:\n", |
1358 | 1363 | " print(robot.name)" |
1359 | 1364 | ] |
|
1439 | 1444 | "assert logs[0].caller is not None\n", |
1440 | 1445 | "for item in logs[0].caller.items():\n", |
1441 | 1446 | " print(f\"{item[0]}: {item[1]}\")\n", |
1442 | | - " \n", |
| 1447 | + "\n", |
1443 | 1448 | "print(f\"\\n*****PROTO*****\\n\")\n", |
1444 | 1449 | "print(logs[0].proto.caller)" |
1445 | 1450 | ] |
|
0 commit comments