def status(self):
status = {
# summary = 'notfound', 'sleeping', 'on', or 'recording'
'summary': 'notfound',
'raw': {}
}
camActive = True
# loop through different status URLs
for cmd in self.statusMatrix:
# stop sending requests if a previous request failed
if camActive:
url = self._statusURL(cmd)
# attempt to contact the camera
try:
response = urlopen(
url, timeout=self.timeout).read().encode('hex')
status['raw'][cmd] = response # save raw response
# loop through different parts we know how to translate
for item in self.statusMatrix[cmd]:
args = self.statusMatrix[cmd][item]
if 'a' in args and 'b' in args:
part = response[args['a']:args['b']]
else:
part = response
# translate the response value if we know how
if 'translate' in args:
status[item] = self._translate(
args['translate'], part)
else:
status[item] = part
except (HTTPError, URLError, socket.timeout) as e:
logging.warning('{}{} - error opening {}: {}{}'.format(
Fore.YELLOW, 'GoProHero.status()', url, e, Fore.RESET))
camActive = False
# build summary
if 'record' in status and status['record'] == 'on':
status['summary'] = 'recording'
elif 'power' in status and status['power'] == 'on':
status['summary'] = 'on'
elif 'power' in status and status['power'] == 'sleeping':
status['summary'] = 'sleeping'
logging.info('GoProHero.status() - result {}'.format(status))
return status
评论列表
文章目录