Skip to content

Commit 6bbe5cf

Browse files
committed
manual mypy fixes
1 parent fe65ca5 commit 6bbe5cf

4 files changed

Lines changed: 62 additions & 64 deletions

File tree

spot_wrapper/cam_webrtc_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class SpotCAMMediaStreamTrack(MediaStreamTrack):
16-
def __init__(self, track, queue):
16+
def __init__(self, track, queue) -> None:
1717
super().__init__()
1818
self.track = track
1919
self.queue = queue
@@ -36,7 +36,7 @@ def __init__(
3636
rtc_config,
3737
media_recorder=None,
3838
recorder_type=None,
39-
):
39+
) -> None:
4040
self.pc = RTCPeerConnection(configuration=rtc_config)
4141

4242
self.video_frame_queue = asyncio.Queue()
@@ -64,7 +64,7 @@ def get_sdp_offer_from_spot_cam(self, token):
6464
result = response.json()
6565
return result["id"], base64.b64decode(result["sdp"]).decode()
6666

67-
def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer):
67+
def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer)-> None:
6868
headers = {"Authorization": f"Bearer {token}"}
6969
server_url = f"https://{self.hostname}:{self.sdp_port}/{self.sdp_filename}"
7070

@@ -73,7 +73,7 @@ def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer):
7373
if r.status_code != 200:
7474
raise ValueError(r)
7575

76-
async def start(self):
76+
async def start(self) -> None:
7777
# first get a token
7878
try:
7979
token = self.get_bearer_token()
@@ -83,26 +83,26 @@ async def start(self):
8383
offer_id, sdp_offer = self.get_sdp_offer_from_spot_cam(token)
8484

8585
@self.pc.on("icegatheringstatechange")
86-
def _on_ice_gathering_state_change():
86+
def _on_ice_gathering_state_change()-> None:
8787
print(f"ICE gathering state changed to {self.pc.iceGatheringState}")
8888

8989
@self.pc.on("signalingstatechange")
90-
def _on_signaling_state_change():
90+
def _on_signaling_state_change()-> None:
9191
print(f"Signaling state changed to: {self.pc.signalingState}")
9292

9393
@self.pc.on("icecandidate")
94-
def _on_ice_candidate(event):
94+
def _on_ice_candidate(event)-> None:
9595
print(f"Received candidate: {event.candidate}")
9696

9797
@self.pc.on("iceconnectionstatechange")
98-
async def _on_ice_connection_state_change():
98+
async def _on_ice_connection_state_change()-> None:
9999
print(f"ICE connection state changed to: {self.pc.iceConnectionState}")
100100

101101
if self.pc.iceConnectionState == "checking":
102102
self.send_sdp_answer_to_spot_cam(token, offer_id, self.pc.localDescription.sdp.encode())
103103

104104
@self.pc.on("track")
105-
def _on_track(track):
105+
def _on_track(track)-> None:
106106
print(f"Received track: {track.kind}")
107107

108108
if self.media_recorder:

spot_wrapper/cam_wrapper.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class LEDPosition(enum.Enum):
5050
FRONT_RIGHT = 2
5151
REAR_RIGHT = 3
5252

53-
def __init__(self, robot: Robot, logger):
53+
def __init__(self, robot: Robot, logger) -> None:
5454
self.logger = logger
5555
self.client: LightingClient = robot.ensure_client(LightingClient.default_service_name)
5656

57-
def set_led_brightness(self, brightness):
57+
def set_led_brightness(self, brightness: float) -> None:
5858
"""
5959
Set the brightness of the LEDs to the specified brightness
6060
@@ -82,7 +82,7 @@ class PowerWrapper:
8282
Wrapper for power interaction
8383
"""
8484

85-
def __init__(self, robot: Robot, logger):
85+
def __init__(self, robot: Robot, logger) -> None:
8686
self.logger = logger
8787
self.client: PowerClient = robot.ensure_client(PowerClient.default_service_name)
8888

@@ -98,7 +98,7 @@ def set_power_status(
9898
aux1: typing.Optional[bool] = None,
9999
aux2: typing.Optional[bool] = None,
100100
external_mic: typing.Optional[bool] = None,
101-
):
101+
) -> None:
102102
"""
103103
Set power status for each of the devices
104104
@@ -116,7 +116,7 @@ def cycle_power(
116116
aux1: typing.Optional[bool] = None,
117117
aux2: typing.Optional[bool] = None,
118118
external_mic: typing.Optional[bool] = None,
119-
):
119+
) -> None:
120120
"""
121121
Cycle power of the specified devices
122122
@@ -134,7 +134,7 @@ class CompositorWrapper:
134134
Wrapper for compositor interaction
135135
"""
136136

137-
def __init__(self, robot: Robot, logger):
137+
def __init__(self, robot: Robot, logger) -> None:
138138
self.logger = logger
139139
self.client: CompositorClient = robot.ensure_client(CompositorClient.default_service_name)
140140

@@ -157,7 +157,7 @@ def get_visible_cameras(self):
157157
"""
158158
return self.client.get_visible_cameras()
159159

160-
def set_screen(self, screen: str):
160+
def set_screen(self, screen: str) -> None:
161161
"""
162162
Set the screen to be streamed over the network
163163
@@ -175,7 +175,7 @@ def get_screen(self) -> str:
175175
"""
176176
return self.client.get_screen()
177177

178-
def set_ir_colormap(self, colormap, min_temp, max_temp, auto_scale=True):
178+
def set_ir_colormap(self, colormap, min_temp: float, max_temp: float, auto_scale: bool=True) -> None:
179179
"""
180180
Set the colormap used for the IR camera
181181
@@ -188,7 +188,7 @@ def set_ir_colormap(self, colormap, min_temp, max_temp, auto_scale=True):
188188
"""
189189
self.client.set_ir_colormap(colormap, min_temp, max_temp, auto_scale)
190190

191-
def set_ir_meter_overlay(self, x, y, enable=True):
191+
def set_ir_meter_overlay(self, x: float, y: float, enable: bool=True) -> None:
192192
"""
193193
Set the reticle position on the Spot CAM IR.
194194
@@ -205,7 +205,7 @@ class HealthWrapper:
205205
Wrapper for health details
206206
"""
207207

208-
def __init__(self, robot, logger):
208+
def __init__(self, robot: Robot, logger) -> None:
209209
self.client: HealthClient = robot.ensure_client(HealthClient.default_service_name)
210210
self.logger = logger
211211

@@ -250,7 +250,7 @@ class AudioWrapper:
250250
Wrapper for audio commands on the camera
251251
"""
252252

253-
def __init__(self, robot, logger):
253+
def __init__(self, robot: Robot, logger) -> None:
254254
self.client: AudioClient = robot.ensure_client(AudioClient.default_service_name)
255255
self.logger = logger
256256

@@ -263,7 +263,7 @@ def list_sounds(self) -> typing.List[str]:
263263
"""
264264
return self.client.list_sounds()
265265

266-
def set_volume(self, percentage):
266+
def set_volume(self, percentage: float) -> None:
267267
"""
268268
Set the volume at which sounds should be played
269269
@@ -272,7 +272,7 @@ def set_volume(self, percentage):
272272
"""
273273
self.client.set_volume(percentage)
274274

275-
def get_volume(self):
275+
def get_volume(self) -> float:
276276
"""
277277
Get the current volume at which sounds are played
278278
@@ -281,7 +281,7 @@ def get_volume(self):
281281
"""
282282
return self.client.get_volume()
283283

284-
def play_sound(self, sound_name, gain=1.0):
284+
def play_sound(self, sound_name: str, gain: float=1.0) -> None:
285285
"""
286286
Play a sound which is on the device
287287
@@ -292,7 +292,7 @@ def play_sound(self, sound_name, gain=1.0):
292292
sound = audio_pb2.Sound(name=sound_name)
293293
self.client.play_sound(sound, gain)
294294

295-
def load_sound(self, sound_file, name):
295+
def load_sound(self, sound_file: str, name: str) -> None:
296296
"""
297297
Load a sound from a wav file and save it with the given name onto the device
298298
Args:
@@ -319,7 +319,7 @@ def load_sound(self, sound_file, name):
319319

320320
self.client.load_sound(sound, data)
321321

322-
def delete_sound(self, name):
322+
def delete_sound(self, name: str) -> None:
323323
"""
324324
Delete a sound from the device
325325
@@ -334,11 +334,11 @@ class StreamQualityWrapper:
334334
Wrapper for stream quality commands
335335
"""
336336

337-
def __init__(self, robot, logger):
337+
def __init__(self, robot: Robot, logger) -> None:
338338
self.client: StreamQualityClient = robot.ensure_client(StreamQualityClient.default_service_name)
339339
self.logger = logger
340340

341-
def set_stream_params(self, target_bitrate, refresh_interval, idr_interval, awb):
341+
def set_stream_params(self, target_bitrate: int, refresh_interval: int, idr_interval: int, awb) -> None:
342342
"""
343343
Set image compression and postprocessing parameters
344344
@@ -369,7 +369,7 @@ def get_stream_params(self) -> typing.Dict[str, int]:
369369

370370
return param_dict
371371

372-
def enable_congestion_control(self, enable):
372+
def enable_congestion_control(self, enable: bool) -> None:
373373
"""
374374
Enable congestion control on the receiver... not sure what this does
375375
@@ -402,7 +402,7 @@ class MediaLogWrapper:
402402
Some functionality adapted from https://github.com/boston-dynamics/spot-sdk/blob/master/python/examples/spot_cam/media_log.py
403403
"""
404404

405-
def __init__(self, robot, logger) -> None:
405+
def __init__(self, robot: Robot, logger) -> None:
406406
self.client: MediaLogClient = robot.ensure_client(MediaLogClient.default_service_name)
407407
self.logger = logger
408408

@@ -656,7 +656,7 @@ class PTZWrapper:
656656
Wrapper for controlling the PTZ unit
657657
"""
658658

659-
def __init__(self, robot, logger):
659+
def __init__(self, robot: Robot, logger) -> None:
660660
self.client: PtzClient = robot.ensure_client(PtzClient.default_service_name)
661661
self.logger = logger
662662
self.ptzs = {}
@@ -783,7 +783,7 @@ def get_ptz_velocity(self, ptz_name) -> PtzVelocity:
783783
"""
784784
return self.client.get_ptz_velocity(PtzDescription(name=ptz_name))
785785

786-
def set_ptz_velocity(self, ptz_name, pan, tilt, zoom):
786+
def set_ptz_velocity(self, ptz_name, pan, tilt, zoom) -> None:
787787
"""
788788
Set the velocity of the various axes of the specified ptz
789789
@@ -796,7 +796,7 @@ def set_ptz_velocity(self, ptz_name, pan, tilt, zoom):
796796
# We do not clamp the velocity to the limits, as it is a rate
797797
self.client.set_ptz_velocity(self._get_ptz_description(ptz_name), pan, tilt, zoom)
798798

799-
def initialise_lens(self):
799+
def initialise_lens(self) -> None:
800800
"""
801801
Initialises or resets ptz autofocus
802802
"""
@@ -819,12 +819,12 @@ class ImageStreamWrapper:
819819
def __init__(
820820
self,
821821
hostname: str,
822-
robot,
822+
robot: Robot,
823823
logger,
824824
sdp_port=31102,
825825
sdp_filename="h264.sdp",
826826
cam_ssl_cert_path=None,
827-
):
827+
) -> None:
828828
"""
829829
Initialise the wrapper
830830
@@ -838,7 +838,7 @@ def __init__(
838838
"""
839839
self.shutdown_flag = threading.Event()
840840
self.logger = logger
841-
self.last_image_time = None
841+
self.last_image_time: typing.Optional[datetime.datetime] = None
842842
self.image_lock = threading.Lock()
843843
loop = asyncio.new_event_loop()
844844
asyncio.set_event_loop(loop)
@@ -862,15 +862,15 @@ def __init__(
862862
self.async_thread = threading.Thread(target=loop.run_forever)
863863
self.async_thread.start()
864864

865-
async def _monitor_shutdown(self):
865+
async def _monitor_shutdown(self) -> None:
866866
while not self.shutdown_flag.is_set():
867867
await asyncio.sleep(1.0)
868868

869869
self.logger.info("Image stream wrapper received shutdown flag")
870870
await self.client.pc.close()
871871
asyncio.get_event_loop().stop()
872872

873-
async def _process_func(self):
873+
async def _process_func(self) -> None:
874874
while asyncio.get_event_loop().is_running():
875875
try:
876876
frame = await self.client.video_frame_queue.get()
@@ -895,7 +895,7 @@ async def _process_func(self):
895895

896896

897897
class SpotCamWrapper:
898-
def __init__(self, hostname, username, password, logger, port: typing.Optional[int] = None):
898+
def __init__(self, hostname, username, password, logger, port: typing.Optional[int] = None) -> None:
899899
self._hostname = hostname
900900
self._username = username
901901
self._password = password
@@ -935,6 +935,6 @@ def __init__(self, hostname, username, password, logger, port: typing.Optional[i
935935

936936
self._logger.info("Finished setting up spot cam wrapper components")
937937

938-
def shutdown(self):
938+
def shutdown(self)-> None:
939939
self._logger.info("Shutting down Spot CAM wrapper")
940940
self.image.shutdown_flag.set()

spot_wrapper/spot_arm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _manipulation_request(
8080
request_proto: manipulation_api_pb2,
8181
end_time_secs: typing.Optional[float] = None,
8282
timesync_endpoint: typing.Optional[TimeSyncEndpoint] = None,
83-
):
83+
) -> typing.Tuple[bool, str, typing.Optional[str]]:
8484
"""Generic function for sending requests to the manipulation api of a robot.
8585
Args:
8686
request_proto: manipulation_api_pb2 object to send to the robot.
@@ -97,7 +97,7 @@ def _manipulation_request(
9797
self._logger.error(f"Unable to execute manipulation command: {e}")
9898
return False, str(e), None
9999

100-
def manipulation_command(self, request: manipulation_api_pb2):
100+
def manipulation_command(self, request: manipulation_api_pb2) -> typing.Tuple[bool, str, typing.Optional[str]]:
101101
end_time = time.time() + self._max_command_duration
102102
return self._manipulation_request(
103103
request,
@@ -136,7 +136,7 @@ def ensure_arm_power_and_stand(self) -> typing.Tuple[bool, str]:
136136

137137
return True, "Spot has an arm, is powered on, and standing"
138138

139-
def wait_for_arm_command_to_complete(self, cmd_id, timeout_sec=None):
139+
def wait_for_arm_command_to_complete(self, cmd_id, timeout_sec: typing.Optional[float]=None) -> None:
140140
"""
141141
Wait until a command issued to the arm complets. Wrapper around the SDK function for convenience
142142
@@ -231,7 +231,7 @@ def make_arm_trajectory_command(
231231
arm_sync_robot_cmd = robot_command_pb2.RobotCommand(synchronized_command=sync_arm)
232232
return RobotCommandBuilder.build_synchro_command(arm_sync_robot_cmd)
233233

234-
def arm_joint_move(self, joint_targets) -> typing.Tuple[bool, str]:
234+
def arm_joint_move(self, joint_targets: typing.List[float]) -> typing.Tuple[bool, str]:
235235
# All perspectives are given when looking at the robot from behind after the unstow service is called
236236
# Joint1: 0.0 arm points to the front. positive: turn left, negative: turn right)
237237
# RANGE: -3.14 -> 3.14
@@ -295,7 +295,7 @@ def arm_joint_move(self, joint_targets) -> typing.Tuple[bool, str]:
295295
except Exception as e:
296296
return False, f"Exception occured during arm movement: {e}"
297297

298-
def create_wrench_from_forces_and_torques(self, forces, torques):
298+
def create_wrench_from_forces_and_torques(self, forces: typing.List[float], torques: typing.List[float]) -> geometry_pb2.Wrench:
299299
force = geometry_pb2.Vec3(x=forces[0], y=forces[1], z=forces[2])
300300
torque = geometry_pb2.Vec3(x=torques[0], y=torques[1], z=torques[2])
301301
return geometry_pb2.Wrench(force=force, torque=torque)
@@ -504,7 +504,7 @@ def hand_pose(self, data) -> typing.Tuple[bool, str]:
504504
def block_until_gripper_command_completes(
505505
robot_command_client: RobotCommandClient,
506506
cmd_id: int,
507-
timeout_sec: float = None,
507+
timeout_sec: typing.Optional[float] = None,
508508
) -> bool:
509509
"""
510510
Helper that blocks until a gripper command achieves a finishing state
@@ -544,7 +544,7 @@ def block_until_gripper_command_completes(
544544
def block_until_manipulation_completes(
545545
manipulation_client: ManipulationApiClient,
546546
cmd_id: int,
547-
timeout_sec: float = None,
547+
timeout_sec: typing.Optional[float] = None,
548548
) -> bool:
549549
"""
550550
Helper that blocks until the arm achieves a finishing state for the specific manipulation command.

0 commit comments

Comments
 (0)