summaryrefslogtreecommitdiffstats
path: root/geoclue.py
blob: cbccf3bd01af0921daf760f381c07dc6a64d6d8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from aglbaseservice import AGLBaseService
import asyncio
import os


class GeoClueService(AGLBaseService):
    def __init__(self, ip, port=None, api='geoclue'):
        super().__init__(ip=ip, port=port, api=api, service='agl-service-geoclue')

    async def location(self, waitresponse=False):
        return await self.request('location', waitresponse=waitresponse)

    async def subscribe(self, event='location', waitresponse=False):
        await super().subscribe(event=event, waitresponse=waitresponse)

    async def unsubscribe(self, event='location', waitresponse=False):
        await super().unsubscribe(event=event, waitresponse=waitresponse)


async def main(loop):
    addr = os.environ.get('AGL_TGT_IP', 'localhost')
    GCS = await GeoClueService(ip=addr)
    tasks = []
    tasks.append(loop.create_task(GCS.location()))
    tasks.append(loop.create_task(GCS.listener()))
    loop.run_until_complete(tasks)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))