Exemple #1
0
async def async_setup_entry(
        hass: HomeAssistantType, entry: config_entries.ConfigEntry
):
    """Set up an access point from a config entry."""
    client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])

    config = hass.data[DOMAIN_DATA_CONFIG].get(
        (entry.data[CONF_HOST], entry.data[CONF_PORT]),
        DEVICE_SCHEMA(
            {
                CONF_HOST: entry.data[CONF_HOST],
                CONF_PORT: entry.data[CONF_PORT],
            }
        ),
    )

    hass.data[DOMAIN_DATA_ENTRIES][entry.entry_id] = {
        "client": client,
        "config": config,
    }

    asyncio.ensure_future(
        _run_client(hass, client, config[CONF_SCAN_INTERVAL])
    )

    hass.async_create_task(
        hass.config_entries.async_forward_entry_setup(entry, "media_player")
    )

    return True
async def async_setup_entry(hass: HomeAssistantType, entry: config_entries.ConfigEntry):
    """Set up an access point from a config entry."""
    client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])

    config = hass.data[DOMAIN_DATA_CONFIG].get(
        (entry.data[CONF_HOST], entry.data[CONF_PORT]),
        DEVICE_SCHEMA(
            {CONF_HOST: entry.data[CONF_HOST], CONF_PORT: entry.data[CONF_PORT]}
        ),
    )
    tasks = hass.data.setdefault(DOMAIN_DATA_TASKS, {})

    hass.data[DOMAIN_DATA_ENTRIES][entry.entry_id] = {
        "client": client,
        "config": config,
    }

    task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL))
    tasks[entry.entry_id] = task

    hass.async_create_task(
        hass.config_entries.async_forward_entry_setup(entry, "media_player")
    )

    return True
Exemple #3
0
async def test_silent_server_disconnect(loop, speedy_client, silent_server):
    from arcam.fmj.client import _HEARTBEAT_TIMEOUT

    c = Client("localhost", 8888)
    connected = True
    with pytest.raises(ConnectionFailed):
        async with ClientContext(c):
            await asyncio.sleep(_HEARTBEAT_TIMEOUT.total_seconds() + 0.5)
            connected = c.connected
    assert not connected
    async def _async_check_and_create(self, host, port):
        client = Client(host, port)
        try:
            await client.start()
        except ConnectionFailed:
            return self.async_abort(reason="unable_to_connect")
        finally:
            await client.stop()

        return self.async_create_entry(
            title=f"{DEFAULT_NAME} ({host})",
            data={CONF_HOST: host, CONF_PORT: port},
        )
Exemple #5
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up config entry."""
    entries = hass.data[DOMAIN_DATA_ENTRIES]
    tasks = hass.data[DOMAIN_DATA_TASKS]

    client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])
    entries[entry.entry_id] = client

    task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL))
    tasks[entry.entry_id] = task

    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
Exemple #6
0
async def async_setup_entry(opp: OpenPeerPower,
                            entry: config_entries.ConfigEntry):
    """Set up config entry."""
    entries = opp.data[DOMAIN_DATA_ENTRIES]
    tasks = opp.data[DOMAIN_DATA_TASKS]

    client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])
    entries[entry.entry_id] = client

    task = asyncio.create_task(_run_client(opp, client, DEFAULT_SCAN_INTERVAL))
    tasks[entry.entry_id] = task

    opp.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
Exemple #7
0
async def async_setup_entry(hass: HomeAssistantType,
                            entry: config_entries.ConfigEntry):
    """Set up config entry."""
    entries = hass.data[DOMAIN_DATA_ENTRIES]
    tasks = hass.data[DOMAIN_DATA_TASKS]

    client = Client(entry.data[CONF_HOST], entry.data[CONF_PORT])
    entries[entry.entry_id] = client

    task = asyncio.create_task(_run_client(hass, client,
                                           DEFAULT_SCAN_INTERVAL))
    tasks[entry.entry_id] = task

    hass.async_create_task(
        hass.config_entries.async_forward_entry_setup(entry, "media_player"))

    return True
async def async_setup_platform(hass: HomeAssistantType,
                               config: ConfigType,
                               async_add_devices,
                               discovery_info=None):
    """Setup platform."""
    client = Client(config[CONF_HOST], config[CONF_PORT])

    asyncio.ensure_future(_run_client(hass, client,
                                      config[CONF_SCAN_INTERVAL]))

    async_add_devices([
        ArcamFmj(
            client,
            zone_config.get(CONF_NAME, '{} - {}'.format(DEFAULT_NAME, zone)),
            zone, zone_config.get(SERVICE_TURN_ON))
        for zone, zone_config in config[CONF_ZONE].items()
    ])
Exemple #9
0
async def test_cancellation(loop, silent_server):
    from arcam.fmj.client import _HEARTBEAT_TIMEOUT

    e = asyncio.Event()
    c = Client("localhost", 8888)

    async def runner():
        await c.start()
        try:
            e.set()
            await c.process()
        finally:
            await c.stop()

    task = asyncio.create_task(runner())
    await asyncio.wait_for(e.wait(), 5)
    task.cancel()

    with pytest.raises(asyncio.CancelledError):
        await task
Exemple #10
0
async def client(loop, request):
    c = Client("localhost", 8888)
    async with ClientContext(c):
        yield c
Exemple #11
0
async def client(loop, request):
    c = Client("localhost", 8888, loop=loop)
    context = ClientContext(c)
    await run_context(loop, request, context)
    return c