Skip to content

Commit aef4224

Browse files
Sunbrye LySunbrye Ly
authored andcommitted
fix: update get_device()
1 parent 35505e8 commit aef4224

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

api/devices.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,24 @@ def get_buckets():
2828
return buckets
2929

3030

31-
def get_device() -> {}:
31+
def get_device(device_id) -> {}:
3232
influxdb_client = InfluxDBClient(url=config.get('APP', 'INFLUX_URL'),
3333
token=config.get('APP', 'INFLUX_TOKEN'),
3434
org=config.get('APP', 'INFLUX_ORG'))
35-
3635
# Queries must be formatted with single and double quotes correctly
3736
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"'
4139
flux_query = f'from(bucket: "{config.get("APP", "INFLUX_BUCKET_AUTH")}") ' \
4240
f'|> range(start: 0) ' \
4341
f'|> filter(fn: (r) => r._measurement == "deviceauth" and {device_filter}) ' \
4442
f'|> last()'
45-
devices = {}
4643

4744
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)
5245
results = []
5346
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()))
5649
return results
5750

5851

0 commit comments

Comments
 (0)