コード例 #1
0
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up the Russound RIO platform."""
    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)

    from russound_rio import Russound

    russ = Russound(hass.loop, host, port)

    yield from russ.connect()

    # Discover sources
    sources = yield from russ.enumerate_sources()

    # Discover zones
    valid_zones = yield from russ.enumerate_zones()

    devices = []
    for zone_id, name in valid_zones:
        yield from russ.watch_zone(zone_id)
        dev = RussoundZoneDevice(russ, zone_id, name, sources)
        devices.append(dev)

    @callback
    def on_stop(event):
        """Shutdown cleanly when hass stops."""
        hass.loop.create_task(russ.close())

    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_stop)

    async_add_devices(devices)
コード例 #2
0
async def async_setup_platform(hass,
                               config,
                               async_add_entities,
                               discovery_info=None):
    """Set up the Russound RIO platform."""

    host = config.get(CONF_HOST)
    port = config.get(CONF_PORT)

    russ = Russound(hass.loop, host, port)

    await russ.connect()

    # Discover sources and zones
    sources = await russ.enumerate_sources()
    valid_zones = await russ.enumerate_zones()

    devices = []
    for zone_id, name in valid_zones:
        await russ.watch_zone(zone_id)
        dev = RussoundZoneDevice(russ, zone_id, name, sources)
        devices.append(dev)

    @callback
    def on_stop(event):
        """Shutdown cleanly when hass stops."""
        hass.loop.create_task(russ.close())

    hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_stop)

    async_add_entities(devices)
コード例 #3
0
ファイル: basic.py プロジェクト: wickerwaka/russound_rio
def demo(loop, host):
    rus = Russound(loop, host)
    yield from rus.connect()

    print("Determining valid zones")
    # Determine Zones
    valid_zones = yield from rus.enumerate_zones()

    for zone_id, name in valid_zones:
        print("%s: %s" % (zone_id, name))

    sources = yield from rus.enumerate_sources()
    for source_id, name in sources:
        print("%s: %s" % (source_id, name))

    yield from rus.watch_zone(ZoneID(1))
    yield from asyncio.sleep(1)
    yield from rus.send_zone_event(ZoneID(1), "KeyPress", "Volume", 40)
    yield from asyncio.sleep(1)
    r = yield from rus.get_zone_variable(ZoneID(1), "volume")
    print("Volume:", r)
    source = rus.get_cached_zone_variable(ZoneID(1), "currentsource")
    name = yield from rus.get_source_variable(source, 'name')
    print("Zone 1 source name: %s" % name)
    yield from rus.close()
    print("Done")