def do_authentication(hass, config):
 from oauth2client.client import OAuth2WebServerFlow, OAuth2DeviceCodeError, FlowExchangeError
 from oauth2client.file import Storage
 oauth = OAuth2WebServerFlow(config[CONF_CLIENT_ID], config[CONF_CLIENT_SECRET], 'https://www.googleapis.com/auth/calendar.readonly', 'Home-Assistant.io')
 persistent_notification = loader.get_component('persistent_notification')
 try:
  dev_flow = oauth.step1_get_device_and_user_codes()
 except OAuth2DeviceCodeError as err:
  persistent_notification.create(hass, 'Error: {}<br />You will need to restart hass after fixing.'.format(err), title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID)
  return False
 persistent_notification.create(hass, 'In order to authorize Home-Assistant to view your calendarsYou must visit: <a href="{}" target="_blank">{}</a> and entercode: {}'.format(dev_flow.verification_url, dev_flow.verification_url, dev_flow.user_code), title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID)
 def step2_exchange(now):
  'Keep trying to validate the user_code until it expires.'
  if (now >= dt.as_local(dev_flow.user_code_expiry)):
   persistent_notification.create(hass, 'Authenication code expired, please restart Home-Assistant and try again', title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID)
   listener()
  try:
   credentials = oauth.step2_exchange(device_flow_info=dev_flow)
  except FlowExchangeError:
   return
  storage = Storage(hass.config.path(TOKEN_FILE))
  storage.put(credentials)
  do_setup(hass, config)
  listener()
  persistent_notification.create(hass, 'We are all setup now. Check {} for calendars that have been found'.format(YAML_DEVICES), title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID)
 listener = track_time_change(hass, step2_exchange, second=range(0, 60, dev_flow.interval))
 return True

def do_authentication ( hass , config ) : from oauth2client . client import OAuth2WebServerFlow , OAuth2DeviceCodeError , FlowExchangeError from oauth2client . file import Storage oauth = OAuth2WebServerFlow ( config [ CONF_CLIENT_ID ] , config [ CONF_CLIENT_SECRET ] , 'https://www.googleapis.com/auth/calendar.readonly' , 'Home-Assistant.io' ) persistent_notification = loader . get_component ( 'persistent_notification' ) try : dev_flow = oauth . step1_get_device_and_user_codes ( ) except OAuth2DeviceCodeError as err : persistent_notification . create ( hass , 'Error: {}<br />You will need to restart hass after fixing.' . format ( err ) , title = NOTIFICATION_TITLE , notification_id = NOTIFICATION_ID ) return False persistent_notification . create ( hass , 'In order to authorize Home-Assistant to view your calendarsYou must visit: <a href="{}" target="_blank">{}</a> and entercode: {}' . format ( dev_flow . verification_url , dev_flow . verification_url , dev_flow . user_code ) , title = NOTIFICATION_TITLE , notification_id = NOTIFICATION_ID ) def step2_exchange ( now ) : if ( now >= dt . as_local ( dev_flow . user_code_expiry ) ) : persistent_notification . create ( hass , 'Authenication code expired, please restart Home-Assistant and try again' , title = NOTIFICATION_TITLE , notification_id = NOTIFICATION_ID ) listener ( ) try : credentials = oauth . step2_exchange ( device_flow_info = dev_flow ) except FlowExchangeError : return storage = Storage ( hass . config . path ( TOKEN_FILE ) ) storage . put ( credentials ) do_setup ( hass , config ) listener ( ) persistent_notification . create ( hass , 'We are all setup now. Check {} for calendars that have been found' . format ( YAML_DEVICES ) , title = NOTIFICATION_TITLE , notification_id = NOTIFICATION_ID ) listener = track_time_change ( hass , step2_exchange , second = range ( 0 , 60 , dev_flow . interval ) ) return True
display the login form .