@@ -28,31 +28,24 @@ def get_buckets():
28
28
return buckets
29
29
30
30
31
- def get_device () -> {}:
31
+ def get_device (device_id ) -> {}:
32
32
influxdb_client = InfluxDBClient (url = config .get ('APP' , 'INFLUX_URL' ),
33
33
token = config .get ('APP' , 'INFLUX_TOKEN' ),
34
34
org = config .get ('APP' , 'INFLUX_ORG' ))
35
-
36
35
# Queries must be formatted with single and double quotes correctly
37
36
query_api = QueryApi (influxdb_client )
38
- # query_api = influxdb_client.query_api()
39
- # device_id = str(device_id)
40
- device_filter = f'r._field != "token"'
37
+ device_id = str (device_id )
38
+ device_filter = f'r.deviceId == "{ device_id } " and r._field != "token"'
41
39
flux_query = f'from(bucket: "{ config .get ("APP" , "INFLUX_BUCKET_AUTH" )} ") ' \
42
40
f'|> range(start: 0) ' \
43
41
f'|> filter(fn: (r) => r._measurement == "deviceauth" and { device_filter } ) ' \
44
42
f'|> last()'
45
- devices = {}
46
43
47
44
response = query_api .query (flux_query )
48
-
49
- # iterate through the result(s)
50
- # TODO maybe change this to only show, device_id, auth_id, auth_token?
51
- # iterate through the result(s)
52
45
results = []
53
46
for table in response :
54
- results . append ( table .records [ 0 ]. values )
55
-
47
+ for record in table .records :
48
+ results . append (( record . get_field (), record . get_value ()))
56
49
return results
57
50
58
51
0 commit comments