def device_registration(self):
"""Presents a dialog with information on how to activate the device.
Attempts to authorize the device using the interval returned by the activation data."""
activation_data = self.vp.get_activation_data()
message = self.language(30039).format(activation_data['verificationUrl'], activation_data['userCode'])
dialog = xbmcgui.DialogProgress()
xbmc.sleep(200) # small delay to prevent DialogProgress from hanging
dialog.create(self.language(30040), message)
secs = 0
expires = activation_data['expires']
while secs < expires:
try:
self.vp.authorize_device(activation_data)
dialog.close()
return True
except self.vp.ViaplayError as error:
# raise all non-pending authorization errors
if not error.value == 'DeviceAuthorizationPendingError':
raise
secs += activation_data['interval']
percent = int(100 * float(secs) / float(expires))
dialog.update(percent, message)
xbmc.sleep(activation_data['interval'] * 1000)
if dialog.iscanceled():
dialog.close()
return False
dialog.close()
return False
评论列表
文章目录