Skip to content

Commit

Permalink
lint, typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
stuqdog committed Sep 26, 2024
1 parent 46fe76f commit 55be528
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
28 changes: 14 additions & 14 deletions src/viam/components/board/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
StreamTicksResponse,
WriteAnalogRequest,
)
from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase
from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase, ResourceRPCClientBase
from viam.streams import StreamWithIterator
from viam.utils import ValueTypes, dict_to_struct, get_geometries, struct_to_dict

Expand All @@ -48,7 +48,7 @@ async def read(
timeout: Optional[float] = None,
**kwargs,
) -> Board.Analog.Value:
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = ReadAnalogReaderRequest(board_name=self.board.name, analog_reader_name=self.name, extra=dict_to_struct(extra))
return await self.board.client.ReadAnalogReader(request, timeout=timeout, metadata=md)

Expand All @@ -60,7 +60,7 @@ async def write(
timeout: Optional[float] = None,
**kwargs,
):
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = WriteAnalogRequest(name=self.board.name, pin=self.name, value=value, extra=dict_to_struct(extra))
await self.board.client.WriteAnalog(request, timeout=timeout, metadata=md)

Expand All @@ -77,7 +77,7 @@ async def value(
timeout: Optional[float] = None,
**kwargs,
) -> int:
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = GetDigitalInterruptValueRequest(board_name=self.board.name, digital_interrupt_name=self.name, extra=dict_to_struct(extra))
response: GetDigitalInterruptValueResponse = await self.board.client.GetDigitalInterruptValue(request, timeout=timeout, metadata=md)
return response.value
Expand All @@ -95,7 +95,7 @@ async def get(
timeout: Optional[float] = None,
**kwargs,
) -> bool:
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = GetGPIORequest(name=self.board.name, pin=self.name, extra=dict_to_struct(extra))
response: GetGPIOResponse = await self.board.client.GetGPIO(request, timeout=timeout, metadata=md)
return response.high
Expand All @@ -108,7 +108,7 @@ async def set(
timeout: Optional[float] = None,
**kwargs,
):
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = SetGPIORequest(name=self.board.name, pin=self.name, high=high, extra=dict_to_struct(extra))
await self.board.client.SetGPIO(request, timeout=timeout, metadata=md)

Expand All @@ -119,7 +119,7 @@ async def get_pwm(
timeout: Optional[float] = None,
**kwargs,
) -> float:
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = PWMRequest(name=self.board.name, pin=self.name, extra=dict_to_struct(extra))
response: PWMResponse = await self.board.client.PWM(request, timeout=timeout, metadata=md)
return response.duty_cycle_pct
Expand All @@ -132,7 +132,7 @@ async def set_pwm(
timeout: Optional[float] = None,
**kwargs,
):
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = SetPWMRequest(name=self.board.name, pin=self.name, duty_cycle_pct=duty_cycle, extra=dict_to_struct(extra))
await self.board.client.SetPWM(request, timeout=timeout, metadata=md)

Expand All @@ -143,7 +143,7 @@ async def get_pwm_frequency(
timeout: Optional[float] = None,
**kwargs,
) -> int:
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = PWMFrequencyRequest(name=self.board.name, pin=self.name, extra=dict_to_struct(extra))
response: PWMFrequencyResponse = await self.board.client.PWMFrequency(request, timeout=timeout, metadata=md)
return response.frequency_hz
Expand All @@ -156,7 +156,7 @@ async def set_pwm_frequency(
timeout: Optional[float] = None,
**kwargs,
):
md = kwargs.get('metadata', self.Metadata()).proto
md = kwargs.get('metadata', ResourceRPCClientBase.Metadata()).proto
request = SetPWMFrequencyRequest(name=self.board.name, pin=self.name, frequency_hz=frequency, extra=dict_to_struct(extra))
await self.board.client.SetPWMFrequency(request, timeout=timeout, metadata=md)

Expand Down Expand Up @@ -226,7 +226,7 @@ async def set_power_mode(

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
md = kwargs.get('metadata', self.Metadata())
return await get_geometries(self.client, self.name, extra, timeout)
return await get_geometries(self.client, self.name, extra, timeout, md)

async def write_analog(
self,
Expand All @@ -248,17 +248,17 @@ async def stream_ticks(
extra: Optional[Dict[str, Any]] = None,
**kwargs,
) -> TickStream:
md = kwargs.get('metadata', self.Metadata()).proto
names = []
for di in interrupts:
names.append(di.name)
request = StreamTicksRequest(name=self.name, pin_names=names, extra=dict_to_struct(extra))

async def read():
md = kwargs.get('metadata', self.Metadata()).proto
tick_stream: ClientStream[StreamTicksRequest, StreamTicksResponse]
async with self.client.StreamTicks.open() as tick_stream:
async with self.client.StreamTicks.open(metadata=md) as tick_stream:
try:
await tick_stream.send_message(request, end=True, metadata=md)
await tick_stream.send_message(request, end=True)
async for tick in tick_stream:
yield tick
except Exception as e:
Expand Down
6 changes: 3 additions & 3 deletions src/viam/components/input/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def _stream_events(self, metadata: ResourceRPCClientBase.Metadata):
return

md = metadata.proto
request = StreamEventsRequest(controller=self.name, events=[], extra=self._callback_extra, metadata=md)
request = StreamEventsRequest(controller=self.name, events=[], extra=self._callback_extra)
with self._lock:
for control, callbacks in self.callbacks.items():
event = StreamEventsRequest.Events(
Expand All @@ -144,7 +144,7 @@ async def _stream_events(self, metadata: ResourceRPCClientBase.Metadata):
request.events.append(event)

try:
async with self.client.StreamEvents.open() as stream:
async with self.client.StreamEvents.open(metadata=md) as stream:
await stream.send_message(request, end=True)
self._send_connection_status(True)
reply: StreamEventsResponse
Expand Down Expand Up @@ -191,4 +191,4 @@ async def do_command(

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
md = kwargs.get('metadata', self.Metadata())
return await get_geometries(self.client, self.name, extra, timeout)
return await get_geometries(self.client, self.name, extra, timeout, md)
2 changes: 1 addition & 1 deletion src/viam/components/pose_tracker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ async def do_command(

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
md = kwargs.get('metadata', self.Metadata())
return await get_geometries(self.client, self.name, extra, timeout)
return await get_geometries(self.client, self.name, extra, timeout, md)
2 changes: 1 addition & 1 deletion src/viam/components/sensor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ async def do_command(

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
md = kwargs.get('metadata', self.Metadata())
return await get_geometries(self.client, self.name, extra, timeout)
return await get_geometries(self.client, self.name, extra, timeout, md)
2 changes: 1 addition & 1 deletion src/viam/components/servo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ async def do_command(

async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
md = kwargs.get('metadata', self.Metadata())
return await get_geometries(self.client, self.name, extra, timeout)
return await get_geometries(self.client, self.name, extra, timeout, md)
5 changes: 3 additions & 2 deletions src/viam/resource/rpc_client_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Mapping, Optional, Protocol, runtime_checkable
from typing import Any, Dict, Protocol, runtime_checkable
from string import ascii_lowercase
from random import choice

Expand All @@ -15,7 +15,7 @@ class ResourceRPCClientBase(Protocol):
"""

class Metadata:
metadata: Mapping[str, str] = {}
metadata: Dict[str, str] = {}

def enable_debug_logging(self, key: str = ''):
"""Enables server-side debug logging for resource methods.
Expand All @@ -39,6 +39,7 @@ def proto(self):
channel: Channel
client: Any


class ReconfigurableResourceRPCClientBase(ResourceRPCClientBase):
"""A base RPC client that can reset its channel.
Expand Down
2 changes: 1 addition & 1 deletion src/viam/resource/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,5 @@ def resource_name_from_string(string: str) -> ResourceName:
class SupportsGetGeometries(Protocol):
"""The SupportsGetGeometries protocol defines the requirements for a resource to call get_geometries."""

async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None) -> GetGeometriesResponse:
async def GetGeometries(self, request: GetGeometriesRequest, *, timeout: Optional[float] = None, **kwargs) -> GetGeometriesResponse:
...
8 changes: 7 additions & 1 deletion src/viam/services/sensors/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ def __init__(self, name: str, channel: Channel):
super().__init__(name, channel)
self.client = SensorsServiceStub(channel)

async def get_sensors(self, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[ResourceName]:
async def get_sensors(
self,
*,
extra: Optional[Mapping[str, Any]] = None,
timeout: Optional[float] = None,
**kwargs,
) -> List[ResourceName]:
"""Get the ``ResourceName`` of all the ``Sensor`` resources connected to this Robot
Returns:
Expand Down
3 changes: 2 additions & 1 deletion src/viam/services/vision/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ async def get_classifications_from_camera(
) -> List[Classification]:
md = kwargs.get('metadata', self.Metadata()).proto
request = GetClassificationsFromCameraRequest(name=self.name, camera_name=camera_name, n=count, extra=dict_to_struct(extra))
response: GetClassificationsFromCameraResponse = await self.client.GetClassificationsFromCamera(request, timeout=timeout, metadata=md)
response: GetClassificationsFromCameraResponse = await self.client.GetClassificationsFromCamera(
request, timeout=timeout, metadata=md)
return list(response.classifications)

async def get_classifications(
Expand Down

0 comments on commit 55be528

Please sign in to comment.