Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
StorageLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
StorageLeaf
Commits
e7c015a8
Commit
e7c015a8
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
added api route to get all sensors for a device
parent
1ad5d76b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/api.yml
+22
-2
22 additions, 2 deletions
docs/api.yml
src/blueprints/Routes.py
+9
-0
9 additions, 0 deletions
src/blueprints/Routes.py
src/logic/Database.py
+5
-0
5 additions, 0 deletions
src/logic/Database.py
with
36 additions
and
2 deletions
docs/api.yml
+
22
−
2
View file @
e7c015a8
...
...
@@ -50,10 +50,30 @@ paths:
application/json
:
schema
:
$ref
:
'
#/components/schemas/Device'
/device/{deviceName}/sensors
:
get
:
summary
:
Gets all sensors for a specific device
operationId
:
deviceSensors
parameters
:
-
in
:
path
name
:
deviceName
description
:
The device name
required
:
true
schema
:
type
:
string
responses
:
'
200'
:
description
:
All available sensors
content
:
application/json
:
schema
:
type
:
array
items
:
$ref
:
'
#/components/schemas/Sensor'
/device/{deviceName}/sensors/{sensorName}
:
get
:
summary
:
Gets a specific device
operationId
:
device
summary
:
Gets a specific
sensor for a
device
operationId
:
device
Sensor
parameters
:
-
in
:
path
name
:
deviceName
...
...
This diff is collapsed.
Click to expand it.
src/blueprints/Routes.py
+
9
−
0
View file @
e7c015a8
...
...
@@ -60,6 +60,15 @@ def construct_blueprint(settings, version):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
return
jsonify
(
database
.
get_all_sensors
())
@routes.route
(
'
/device/<deviceName>/sensors/
'
,
methods
=
[
'
GET
'
])
def
get_all_sensors_for_device
(
deviceName
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
device
=
database
.
get_device
(
deviceName
)
if
not
device
:
return
jsonify
({
'
success
'
:
False
,
'
msg
'
:
f
'
No device with name
"
{
deviceName
}
"
existing
'
})
return
jsonify
(
database
.
get_all_sensors_for_device
(
device
))
@routes.route
(
'
/device/<deviceName>/sensors/<sensorName>
'
,
methods
=
[
'
GET
'
])
def
get_sensor
(
deviceName
,
sensorName
):
database
=
Database
(
settings
[
'
database
'
][
'
databasePath
'
])
...
...
This diff is collapsed.
Click to expand it.
src/logic/Database.py
+
5
−
0
View file @
e7c015a8
...
...
@@ -82,6 +82,11 @@ class Database:
def
get_all_sensors
(
self
):
return
self
.
__query
(
f
'
SELECT * FROM
{
self
.
TABLE_SENSOR
}
ORDER BY device_id, name
'
,
fetch_type
=
FetchType
.
ALL
)
def
get_all_sensors_for_device
(
self
,
device
:
Dict
[
str
,
str
]):
return
self
.
__query
(
f
'
SELECT * FROM
{
self
.
TABLE_SENSOR
}
WHERE device_id = ? ORDER BY name
'
,
device
[
'
id
'
],
fetch_type
=
FetchType
.
ALL
)
def
get_sensor
(
self
,
deviceID
:
int
,
name
:
str
):
return
self
.
__query
(
f
'
SELECT * FROM
{
self
.
TABLE_SENSOR
}
WHERE device_id = ? AND name = ?
'
,
deviceID
,
name
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment