Exemple #1
0
async def request_in_loop(method,
                          url,
                          json=None,
                          *,
                          _headers: Optional[Dict[str, str]] = None):
    """make requests work in asyncio"""
    req_kwargs = json_obj.from_not_none(json=json, headers=_headers)
    return await run_in_executor(
        partial(requests.request, method, url, **req_kwargs))
Exemple #2
0
 async def trigger_skill_event(self,
                               skill_uid: str,
                               event_name: str,
                               json: Optional[Dict] = None):
     """send an event to a currently running skill"""
     payload = json_obj.from_not_none(UniqueId=skill_uid,
                                      EventName=event_name,
                                      Payload=json)
     await self._post('skills/event', payload)
Exemple #3
0
 async def post_in_mem_file(self,
                            channel,
                            content: str,
                            title='from python',
                            filetype='txt',
                            filename=None):
     """post file whose contents are in memory"""
     req = json_obj.from_not_none(content=content,
                                  channels=self.channel_id(channel),
                                  filetype=filetype,
                                  title=title,
                                  filename=filename)
     await self.client.files_upload(**req)
Exemple #4
0
    async def drive(self, linear_vel_pct: int = 0, angular_vel_pct: int = 0, time_ms: Optional[int] = None):
        """
        angular_vel_pct: -100 is full speed counter-clockwise, 100 is full speed clockwise
        """
        angular_vel_pct *= -1
        _validate_vel_pct(linear_vel_pct=linear_vel_pct, angular_vel_pct=angular_vel_pct)
        payload = json_obj.from_not_none(LinearVelocity=linear_vel_pct, AngularVelocity=angular_vel_pct)
        endpoint = 'drive'

        if time_ms:
            payload['TimeMS'] = time_ms
            endpoint += '/time'

        return await self._post(endpoint, payload)
Exemple #5
0
    async def take_picture(self,
                           file_name: Optional[str] = None,
                           width: Optional[int] = None,
                           height: Optional[int] = None,
                           *,
                           show_on_screen: Optional[bool] = False,
                           overwrite_existing=True) -> BytesIO:
        """
        if height is supplied, so must be width, and vice versa
        if you want to display on the screen, you must provide a filename

        # TODO: better way return data? maybe decode the base64 vals and return them?
        """
        self._validate_take_picture(file_name, width, height, show_on_screen)

        payload = json_obj.from_not_none(Base64=True,
                                         FileName=file_name,
                                         Width=width,
                                         Height=height,
                                         DisplayOnScreen=show_on_screen,
                                         OverwriteExisting=overwrite_existing)
        res = await self._get_j('cameras/rgb', **payload)
        return decode_data(res.base64)
Exemple #6
0
 async def help(self, endpoint: Optional[str] = None):
     """specs for the system at large"""
     return await self._get_j('help', **json_obj.from_not_none(command=endpoint))
Exemple #7
0
 def json(self):
     return json_obj.from_not_none(closedEyeMinMs=self.closed_eye_min_ms,
                                   closedEyeMaxMs=self.closed_eye_max_ms,
                                   openEyeMinMs=self.open_eye_min_ms,
                                   openEyeMaxMs=self.open_eye_max_ms,
                                   blinkImages=self.blink_image_map)
Exemple #8
0
 async def run(self, skill_name_or_uid, method: Optional[str] = None):
     return (await self._post(
         'skills/start',
         json_obj.from_not_none(Skill=skill_name_or_uid,
                                Method=method))).json()['result']
Exemple #9
0
 async def stop(self, skill_name: Optional[str] = None):
     await self._post('skills/cancel',
                      json_obj.from_not_none(Skill=skill_name))