def open(url): """Open specific URL on teleserver """ logger.info('Opening URL...') logger.debug(f'args: url: {url}') response = make_request('webbrowser/open', {'url': url}) logger.info(f"Server response: {response['message']}")
def set_volume(level): """Set volume to specific level """ logger.info('Setting volume...') logger.debug('args: level: {level}') response = make_request('system/set_volume', {'lvl': level}) logger.info(f"Server response: {response['message']}")
def call_word(word): """Call specific word or key string """ logger.info('Calling word') logger.debug(f'args: word: {word}') response = make_request('keyboard/call_word', {'word': word}) logger.info(f"Server response: {response['message']}")
def call_key(key): """Call specific key in xdotool format """ logger.info('Calling key...') logger.debug(f'args: key: {key}') response = make_request('keyboard/call_key', {'key': key}) logger.info(f"Server response: {response['message']}")
def grab_screen(output): """Take a screenshot and save it to local files """ logger.info(f'Grabbing screen and saving to {output}') logger.debug(f'args: output: {output}') response = make_request('system/grab_screen') logger.info(f"Server response: {response['message']}") imgdata = base64.b64decode(response['screen']) with open(output, 'wb') as f: f.write(imgdata) logger.info(f'Saved image to {output}')
def test_make_request(self, mock_post): test_credentials = { 'token_name': 'testtoken', 'token': 'secret', 'server': '127.0.0.1' } os.makedirs('~/.teleserver') with open('~/.teleserver/credentials.json', 'w') as f: json.dump(test_credentials, f) url_args = {'var1': 'val1', 'var2': 'val2'} route = 'test/route' post_args = { 'postvar1': 'postval1', 'postvar2': 'postval2', 'postvar3': 'postval3' } response = make_request(route=route, url_args=url_args, post_args=post_args) self.assertEqual(response['rc'], 0)
def mute(): """Mute the volume """ logger.info('Muting...') response = make_request('system/mute') logger.info(f"Server response: {response['message']}")
def screenshot(): """Take a screenshot of teleserver """ logger.info('Making screenshot...') response = make_request('system/screenshot') logger.info(f"Server response: {response['message']}")
def reboot(): """Reboot teleserver machine """ logger.info('Rebooting...') response = make_request('system/reboot') logger.info(f"Server response: {response['message']}")
def poweroff(): """Power off teleserver machine """ logger.info('Powering off...') response = make_request('system/poweroff') logger.info(f"Server response: {response['message']}")
def close(): """Close web browser on teleserver """ logger.info('Closing webbrowser...') response = make_request('webbrowser/close') logger.info(f"Server response: {response['message']}")
def openmeet(): """Open well-known Google Meet link """ logger.info('Opening meet...') response = make_request('webbrowser/openmeet') logger.info(f"Server response: {response['message']}")