Exemplo n.º 1
0
async def main(loop):
    args = GPSService.parser.parse_args()
    gpss = await GPSService(ip=args.ipaddr, port=args.port)

    if args.loglevel:
        gpss.logger.setLevel(args.loglevel)

    if args.record:
        msgid = await gpss.record(args.record)
        print(f'Sent gps record request with value {args.record} with messageid {msgid}')
        print(AFBResponse(await gpss.response()))

    if args.location:
        msgid = await gpss.location()
        print(AFBResponse(await gpss.response()))

    if args.subscribe:
        for event in args.subscribe:
            msgid = await gpss.subscribe(event)
            print(f'Subscribed for event {event} with messageid {msgid}')
            print(AFBResponse(await gpss.response()))

    if args.listener:
        async for response in gpss.listener():
            print(response)
Exemplo n.º 2
0
async def test_location_events(event_loop, service: GPS):
    msgid = await service.subscribe('location')
    resp = AFBResponse(await service.response())
    assert resp.msgid == msgid
    assert resp.status == 'success'  # successful subscription
    try:
        resp = await asyncio.wait_for(service.afbresponse(), 10)
        resp = AFBResponse(resp)
        assert resp.type == AFBT.EVENT, f'Expected EVENT response, got {resp.type.name} instead'
        # TODO one more assert for the actual received event, haven't received a location event yet
    except TimeoutError:
        pytest.xfail("Did not receive location event")
Exemplo n.º 3
0
async def main(loop):
    args = GeoClueService.parser.parse_args()
    gcs = await GeoClueService(args.ipaddr)

    if args.location:
        msgid = await gcs.location()
        print(f'Sent location request with messageid {msgid}')
        print(AFBResponse(await gcs.response()))

    if args.subscribe:
        for event in args.subscribe:
            msgid = await gcs.subscribe(event)
            print(f"Subscribed for {event} with messageid {msgid}")
            print(AFBResponse(await gcs.response()))
    if args.listener:
        async for response in gcs.listener():
            print(response)
Exemplo n.º 4
0
async def main(loop):
    args = NFCService.parser.parse_args()
    nfcs = await NFCService(ip=args.ipaddr, port=args.port)

    if args.subscribe:
        for event in args.subscribe:
            msgid = await nfcs.subscribe(event)
            print(f"Subscribing for event {event} with messageid {msgid}")
            r = AFBResponse(await nfcs.response())
            print(r)

    if args.unsubscribe:
        for event in args.unsubscribe:
            msgid = await nfcs.unsubscribe(event)
            print(f"Unsubscribing for event {event} with messageid {msgid}")
            r = AFBResponse(await nfcs.response())
            print(r)

    if args.listener:
        async for response in nfcs.listener():
            print(response)
Exemplo n.º 5
0
async def main():
    args = WeatherService.parser.parse_args()
    aws = await WeatherService(ip=args.ipaddr, port=args.port)
    if args.current:
        msgid = await aws.current_weather()
        resp = AFBResponse(await aws.response())
        print(json.dumps(resp.data, indent=2))

    if args.apikey:
        msgid = await aws.apikey()
        resp = AFBResponse(await aws.response())
        print(resp.data['api_key'])

    if args.subscribe:
        for event in args.subscribe:
            msgid = await aws.subscribe(event)
            print(f'Subscribed for event {event} with messageid {msgid}')
            resp = AFBResponse(await aws.response())
            print(resp)

    if args.listener:
        async for response in aws.listener():
            print(response)
Exemplo n.º 6
0
async def main():
    args = AudioMixerService.parser.parse_args()
    ams = await AudioMixerService(ip=args.ipaddr, port=args.port)

    if args.list_controls:
        resp = await ams.list_controls()
        print(f'Requesting list_controls with id {resp}')
        r = AFBResponse(await ams.response())
        print(r)

    if args.setvolume is not None:
        resp = await ams.volume(args.setvolume)
        print(f'Setting volume to {args.setvolume} with id {resp}')
        r = AFBResponse(await ams.response())
        print(r)

    if args.getvolume:
        resp = await ams.volume()
        print(f'Requesting volume with id {resp}')
        r = AFBResponse(await ams.response())
        print(r)

    if args.setmute is not None:
        resp = await ams.mute(args.setmute)
        print(f'Setting mute to {args.setmute} with id {resp}')
        r = AFBResponse(await ams.response())
        print(r)

    if args.getmute:
        resp = await ams.mute()
        r = AFBResponse(await ams.response())
        print(r)

    if args.subscribe:
        for event in args.subscribe:
            msgid = await ams.subscribe(event)
            print(f'Subscribing to {event} with id {msgid}')
            r = AFBResponse(await ams.response())
            print(r)

    if args.unsubscribe:
        for event in args.unsubscribe:
            msgid = await ams.unsubscribe(event)
            print(f'Unsubscribing from {event} with id {msgid}')
            r = AFBResponse(await ams.response())
            print(r)

    if args.listener:
        async for response in ams.listener():
            print(response)
Exemplo n.º 7
0
async def main(loop):
    args = BluetoothService.parser.parse_args()
    bts = await BluetoothService(ip=args.ipaddr, port=args.port)

    if args.default_adapter:
        msgid = await bts.default_adapter()
        print(f'Requesting default adapter with id {msgid}')
        r = AFBResponse(await bts.response())
        print(r)

    if args.adapter_state:
        pass

    if args.listener:
        for response in bts.listener():
            print(response)

    bts.logger.debug(await bts.adapter_state('hci0', {'uuids': ['0000110e-0000-1000-8000-00805f9b34fb']}))
Exemplo n.º 8
0
async def test_unsubscribe(event_loop, service: GPS):
    msgid = await service.unsubscribe('location')
    resp = AFBResponse(await service.response())
    assert resp.msgid == msgid
    assert resp.status == 'success'
Exemplo n.º 9
0
async def test_subscribe_verb(event_loop, service: GPS):
    msgid = await service.subscribe("")
    resp = AFBResponse(await service.response())
    assert resp.msgid == msgid
    assert resp.status == 'success'
Exemplo n.º 10
0
async def test_location_result(event_loop, service: GPS):
    msgid = await service.location()
    resp = AFBResponse(await service.response())
    assert resp.status == 'success'
Exemplo n.º 11
0
async def test_location_verb(event_loop, service: GPS):
    msgid = await service.location()
    resp = AFBResponse(await service.response())
    assert resp.msgid == msgid
Exemplo n.º 12
0
async def main(loop):
    args = MediaPlayerService.parser.parse_args()
    MPS = await MediaPlayerService(ip=args.ipaddr)

    if args.playlist:
        msgid = await MPS.playlist()
        r = AFBResponse(await MPS.response())
        for l in r.data['list']:
            print(l)

    if args.control:
        msgid = await MPS.control(args.control)
        print(f'Sent {args.control} request with messageid {msgid}')
        r = AFBResponse(await MPS.response())
        print(r)

    if args.seek:
        msgid = await MPS.control('seek', args.seek)
        print(f'Sent seek request to {args.seek} msec with messageid {msgid}')
        r = AFBResponse(await MPS.response())
        print(r)

    if args.fastforward:
        msgid = await MPS.control('fast-forward', args.fastforward)
        print(
            f'Sent fast-forward request for {args.fastforward} msec with messageid {msgid}'
        )
        r = AFBResponse(await MPS.response())
        print(r)

    if args.rewind:
        msgid = await MPS.control('rewind', -args.rewind)
        print(
            f'Sent rewind request for {args.rewind} msec with messageid {msgid}'
        )
        r = AFBResponse(await MPS.response())
        print(r)

    if args.picktrack:
        msgid = await MPS.control('pick-track', args.picktrack)
        print(
            f'Sent pick-track request with index {args.rewind} with messageid {msgid}'
        )
        r = AFBResponse(await MPS.response())
        print(r)

    if args.volume:
        msgid = await MPS.control('volume', int(args.volume))
        print(f'Sent volume request: {args.rewind} with messageid {msgid}')
        r = AFBResponse(await MPS.response())
        print(r)

    if args.loop:
        msgid = await MPS.control('loop', args.loop)
        print(f'Sent loop-state request: {args.loop} with messageid {msgid}')
        r = AFBResponse(await MPS.response())
        print(r)

    # if args.avrcp:
    #     id = await MPS.control('avrcp_controls', args.avrcp)
    #     print(f'Sent AVRCP control request: {args.loop} with messageid {id}')
    #     r = AFBResponse(await MPS.response())
    #     print(r)

    if args.subscribe:
        for event in args.subscribe:
            msgid = await MPS.subscribe(event)
            print(f"Subscribed for event {event} with messageid {msgid}")
            r = await MPS.response()
            print(r)

    if args.listener:
        async for response in MPS.listener():
            print(response)
Exemplo n.º 13
0
async def test_adapter_state(event_loop, service: BTS):
    msgid = await service.adapter_state('hci0')
    resp = AFBResponse(await service.response())
    assert resp.status == 'success', 'adapter state verb failed'
Exemplo n.º 14
0
async def test_has_single_adapter(event_loop, service: BTS):
    msgid = await service.managed_objects()
    resp = AFBResponse(await service.response())
    assert len(resp.data['adapters']) == 1, \
        f'Detected {len(resp.data["adapters"])} adapters. Multiple adapters may also break testing'
Exemplo n.º 15
0
async def test_managed_objects(event_loop, service: BTS):
    msgid = await service.managed_objects()
    resp = AFBResponse(await service.response())
    assert resp.status == 'success', str(resp)
Exemplo n.º 16
0
async def test_default_adapter(event_loop, service: BTS):
    msgid = await service.default_adapter()
    resp = AFBResponse(await service.response())
    assert resp.status == 'success', resp
    assert 'adapter' in resp.data.keys()
    assert resp.data['adapter'] == 'hci0'