original_docstring: Set up the sisyphus component.
docstring: Set up the sisyphus component.
docstring_tokens: Set up the sisyphus component .
code: async def async_setup(hass, config):
      """Set up the sisyphus component."""
      from sisyphus_control import Table
      tables = hass.data.setdefault(DATA_SISYPHUS, {})
      table_configs = config.get(DOMAIN)
      session = async_get_clientsession(hass)
  
      async def add_table(host, name=None):
          """Add platforms for a single table with the given hostname."""
          table = await Table.connect(host, session)
          if name is None:
              name = table.name
          tables[name] = table
          _LOGGER.debug("Connected to %s at %s", name, host)
  
          hass.async_create_task(async_load_platform(
              hass, 'light', DOMAIN, {
                  CONF_NAME: name,
              }, config
          ))
          hass.async_create_task(async_load_platform(
              hass, 'media_player', DOMAIN, {
                  CONF_NAME: name,
                  CONF_HOST: host,
              }, config
          ))
  
      if isinstance(table_configs, dict):  # AUTODETECT_SCHEMA
          for ip_address in await Table.find_table_ips(session):
              await add_table(ip_address)
      else:  # TABLES_SCHEMA
          for conf in table_configs:
              await add_table(conf[CONF_HOST], conf[CONF_NAME])
  
      async def close_tables(*args):
          """Close all table objects."""
          tasks = [table.close() for table in tables.values()]
          if tasks:
              await asyncio.wait(tasks)
  
      hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_tables)
  
      return True
code_tokens: async def async_setup ( hass , config ) : from sisyphus_control import Table tables = hass . data . setdefault ( DATA_SISYPHUS , { } ) table_configs = config . get ( DOMAIN ) session = async_get_clientsession ( hass ) async def add_table ( host , name = None ) : """Add platforms for a single table with the given hostname.""" table = await Table . connect ( host , session ) if name is None : name = table . name tables [ name ] = table _LOGGER . debug ( "Connected to %s at %s" , name , host ) hass . async_create_task ( async_load_platform ( hass , 'light' , DOMAIN , { CONF_NAME : name , } , config ) ) hass . async_create_task ( async_load_platform ( hass , 'media_player' , DOMAIN , { CONF_NAME : name , CONF_HOST : host , } , config ) ) if isinstance ( table_configs , dict ) : for ip_address in await Table . find_table_ips ( session ) : await add_table ( ip_address ) else : for conf in table_configs : await add_table ( conf [ CONF_HOST ] , conf [ CONF_NAME ] ) async def close_tables ( * args ) : """Close all table objects.""" tasks = [ table . close ( ) for table in tables . values ( ) ] if tasks : await asyncio . wait ( tasks ) hass . bus . async_listen_once ( EVENT_HOMEASSISTANT_STOP , close_tables ) return True
short_docstring: Set up the sisyphus component.
short_docstring_tokens: Set up the sisyphus component .
comment: """Set up the sisyphus component."""$SEP$"""Add platforms for a single table with the given hostname."""$SEP$# AUTODETECT_SCHEMA$SEP$# TABLES_SCHEMA$SEP$"""Close all table objects."""