def setup_services(hass, track_new_found_calendars, calendar_service):
 def _found_calendar(call):
  'Check if we know about a calendar and generate PLATFORM_DISCOVER.'
  calendar = get_calendar_info(hass, call.data)
  if (hass.data[DATA_INDEX].get(calendar[CONF_CAL_ID], None) is not None):
   return
  hass.data[DATA_INDEX].update({calendar[CONF_CAL_ID]: calendar})
  update_config(hass.config.path(YAML_DEVICES), hass.data[DATA_INDEX][calendar[CONF_CAL_ID]])
  discovery.load_platform(hass, 'calendar', DOMAIN, hass.data[DATA_INDEX][calendar[CONF_CAL_ID]])
 hass.services.register(DOMAIN, SERVICE_FOUND_CALENDARS, _found_calendar, None, schema=None)
 def _scan_for_calendars(service):
  'Scan for new calendars.'
  service = calendar_service.get()
  cal_list = service.calendarList()
  calendars = cal_list.list().execute()['items']
  for calendar in calendars:
   calendar['track'] = track_new_found_calendars
   hass.services.call(DOMAIN, SERVICE_FOUND_CALENDARS, calendar)
 hass.services.register(DOMAIN, SERVICE_SCAN_CALENDARS, _scan_for_calendars, None, schema=None)
 return True

def setup_services ( hass , track_new_found_calendars , calendar_service ) : def _found_calendar ( call ) : calendar = get_calendar_info ( hass , call . data ) if ( hass . data [ DATA_INDEX ] . get ( calendar [ CONF_CAL_ID ] , None ) is not None ) : return hass . data [ DATA_INDEX ] . update ( { calendar [ CONF_CAL_ID ] : calendar } ) update_config ( hass . config . path ( YAML_DEVICES ) , hass . data [ DATA_INDEX ] [ calendar [ CONF_CAL_ID ] ] ) discovery . load_platform ( hass , 'calendar' , DOMAIN , hass . data [ DATA_INDEX ] [ calendar [ CONF_CAL_ID ] ] ) hass . services . register ( DOMAIN , SERVICE_FOUND_CALENDARS , _found_calendar , None , schema = None ) def _scan_for_calendars ( service ) : service = calendar_service . get ( ) cal_list = service . calendarList ( ) calendars = cal_list . list ( ) . execute ( ) [ 'items' ] for calendar in calendars : calendar [ 'track' ] = track_new_found_calendars hass . services . call ( DOMAIN , SERVICE_FOUND_CALENDARS , calendar ) hass . services . register ( DOMAIN , SERVICE_SCAN_CALENDARS , _scan_for_calendars , None , schema = None ) return True
setup service listeners .