1 """Support for controlling Sisyphus Kinetic Art Tables."""
6 from sisyphus_control
import Table
7 import voluptuous
as vol
16 _LOGGER = logging.getLogger(__name__)
18 DATA_SISYPHUS =
"sisyphus"
21 AUTODETECT_SCHEMA = vol.Schema({})
23 TABLE_SCHEMA = vol.Schema(
24 {vol.Required(CONF_NAME): cv.string, vol.Required(CONF_HOST): cv.string}
27 TABLES_SCHEMA = vol.Schema([TABLE_SCHEMA])
29 CONFIG_SCHEMA = vol.Schema(
30 {DOMAIN: vol.Any(AUTODETECT_SCHEMA, TABLES_SCHEMA)}, extra=vol.ALLOW_EXTRA
35 logging.getLogger(
"socketio.client").setLevel(logging.CRITICAL + 1)
36 logging.getLogger(
"engineio.client").setLevel(logging.CRITICAL + 1)
39 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
40 """Set up the sisyphus component."""
42 tables = hass.data.setdefault(DATA_SISYPHUS, {})
43 table_configs = config[DOMAIN]
46 async
def add_table(host, name=None):
47 """Add platforms for a single table with the given hostname."""
48 tables[host] =
TableHolder(hass, session, host, name)
50 hass.async_create_task(
53 hass.async_create_task(
55 hass, Platform.MEDIA_PLAYER, DOMAIN, {CONF_HOST: host}, config
59 if isinstance(table_configs, dict):
60 for ip_address
in await Table.find_table_ips(session):
61 await add_table(ip_address)
63 for conf
in table_configs:
64 await add_table(conf[CONF_HOST], conf[CONF_NAME])
66 async
def close_tables(*args):
67 """Close all table objects."""
68 tasks = [table.close()
for table
in tables.values()]
70 await asyncio.wait(tasks)
72 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_tables)
78 """Holds table objects and makes them available to platforms."""
81 """Initialize the table holder."""
91 """Return true if the table is responding to heartbeats."""
93 return self.
_table_task_table_task.result().is_connected
98 """Return the name of the table."""
99 return self.
_name_name
102 """Return the Table held by this holder, connecting to it if needed."""
114 if self.
_name_name
is None:
116 _LOGGER.debug(
"Connected to %s at %s", self.
_name_name, self.
_host_host)
122 """Close the table held by this holder, if any."""
def __init__(self, hass, session, host, name)
bool async_setup(HomeAssistant hass, ConfigType config)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)
None async_load_platform(core.HomeAssistant hass, Platform|str component, str platform, DiscoveryInfoType|None discovered, ConfigType hass_config)