summaryrefslogtreecommitdiffstats
path: root/gps.py
diff options
context:
space:
mode:
authorEdi Feschiyan <edi.feschiyan@konsulko.com>2020-05-22 15:09:59 +0300
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-09 09:30:10 +0300
commite190fff1a49499fc9e07931c641d8d110c3a595b (patch)
tree22a03e72af0ce2bd6ad75102b1b324f20525586e /gps.py
parentf050bced69122149fb4f39e0021a35c989a40f90 (diff)
Working base class, hopefully final reworks for the services
Diffstat (limited to 'gps.py')
-rw-r--r--gps.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/gps.py b/gps.py
index 61e3153..c11b2a8 100644
--- a/gps.py
+++ b/gps.py
@@ -1,14 +1,13 @@
-from aglbaseservice import AGLBaseService
+from aglbaseservice import AGLBaseService, AFBResponse
import asyncio
import os
-from concurrent import futures
-xc = futures.ThreadPoolExecutor(1)
class GPSService(AGLBaseService):
service = 'agl-service-gps'
parser = AGLBaseService.getparser()
- parser.add_argument('--location', help='Query location verb', action='store_true')
+ parser.add_argument('--record', help='Begin recording verb ')
+ parser.add_argument('--location', help='Get current location', action='store_true')
def __init__(self, ip, port=None):
super().__init__(api='gps', ip=ip, port=port, service='agl-service-gps')
@@ -16,6 +15,9 @@ class GPSService(AGLBaseService):
async def location(self):
return await self.request('location')
+ async def record(self, state='on'):
+ return await self.request('record', {'state': state})
+
async def subscribe(self, event='location'):
return await super().subscribe(event=event)
@@ -27,19 +29,27 @@ async def main(loop):
args = GPSService.parser.parse_args()
gpss = await GPSService(args.ipaddr)
- l = await loop.run_in_executor(xc, gpss.listener)
- # print(await r.__anext__())
-
if args.loglevel:
gpss.logger.setLevel(args.loglevel)
+
+ if args.record:
+ id = await gpss.record(args.record)
+ print(f'Sent gps record request with value {args.record} with messageid {id}')
+ print(AFBResponse(await gpss.response()))
+
if args.location:
msgid = await gpss.location()
- print(await gpss.receive())
+ print(AFBResponse(await gpss.response()))
if args.subscribe:
- await gpss.subscribe(args.subscribe)
-
- print(await l.__anext__())
+ for event in args.subscribe:
+ id = await gpss.subscribe(event)
+ print(f'Subscribed for event {event} with messageid {id}')
+ print(AFBResponse(await gpss.response()))
+
+ if args.listener:
+ async for response in gpss.listener():
+ print(response)
if __name__ == '__main__':
loop = asyncio.get_event_loop()