From 65464fae5438d016eccfca4700fd8904c70f219e Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Wed, 8 Jan 2020 21:59:35 +0000 Subject: [PATCH] implement get device status latest A.P.I. call. --- app/api.py | 3 + app/readings.db | Bin 40960 -> 40960 bytes app/readings.db-journal | Bin 4616 -> 0 bytes app/services/get_services.py | 57 ++++++++++++- app/swagger.yml | 155 ++++++++++++++++++++++++----------- 5 files changed, 161 insertions(+), 54 deletions(-) delete mode 100644 app/readings.db-journal diff --git a/app/api.py b/app/api.py index ceb9ba1..34b1f08 100644 --- a/app/api.py +++ b/app/api.py @@ -23,3 +23,6 @@ def get_all_readings(light_meter): def get_all_readings_for_every_meter(): return get_services.get_all_readings_from_database() + +def get_latest_device_status(device): + return get_services.get_latest_status(device) diff --git a/app/readings.db b/app/readings.db index b555a9763b8c07e41230206af32bddca510c7402..4b7ad3219c65b18a97ce1b0aa3b7ca9dd01fdde1 100644 GIT binary patch delta 19 bcmZoTz|?SnX@WE(??f4AM&6AH3+4j=L5c>9 delta 19 bcmZoTz|?SnX@WE(&qNt#MxKoc3+4j=L3;*@ diff --git a/app/readings.db-journal b/app/readings.db-journal deleted file mode 100644 index 290d5f9ed7c2d6179d082918513d1188f9659c7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4616 zcmeI$F%E+;3VA&~o30c+(-- The reading was successfully added to the database. - /status/update/{device}: - post: - operationId: api.post_a_status_change - tags: - - Log Device Status Change - summary: >- - Logs a change in the status of the specified device. - description: >- - This is mostly to check if the devices included in this project - are turned on, off or an error has occured and they are - unreachable/crashed. - parameters: - - name: device - in: path - description: >- - The Id. of the device with the change in status. 1, 2 and 3 - refer to the light-meters in Ritherdon and 4, 5 and 6 - refer to the relays in the gallery. The pairing of each - meter and relay is as follows: 1->4, 2->5 and 3->6. - type: integer - required: True - - name: the_status_change - in: body - description: >- - The status change and the time the change occurred. - required: True - schema: - type: object - properties: - time: - type: string - format: date-time - example: 2019-10-19 17:04:57 - description: >- - The date and time the change in status occurred. Make - sure to use the U.T.C. time format. This is because - the A.P.I. has made a design decision to standardise - on it. - status: - type: string - example: "on" - description: >- - The current status of the device you would like to log. - The two status types are "on" and "off". - responses: - 201: - description: >- - The status update was successfully added to the database. - /readings/latest/{light_meter}: get: operationId: api.get_latest @@ -146,7 +99,7 @@ paths: 200: description: >- If the server can successfully retrieve the latest reading - for the specified light meter, you should receive a JASON + for the specified light meter, you should receive a JSON object like the one below. It should include the Id. of the light meter it was taken with, the time the reading was taken and the reading itself. @@ -249,3 +202,105 @@ paths: schema: type: object additionalProperties: True + +# Device A.P.I. Calls +# ==================================================================== + /status/update/{device}: + post: + operationId: api.post_a_status_change + tags: + - Log Device Status Change + summary: >- + Logs a change in the status of the specified device. + description: >- + This is mostly to check if the devices included in this project + are turned on, off or an error has occured and they are + unreachable/crashed. + parameters: + - name: device + in: path + description: >- + The Id. of the device with the change in status. 1, 2 and 3 + refer to the light-meters in Ritherdon and 4, 5 and 6 + refer to the relays in the gallery. The pairing of each + meter and relay is as follows: 1->4, 2->5 and 3->6. + type: integer + required: True + - name: the_status_change + in: body + description: >- + The status change and the time the change occurred. + required: True + schema: + type: object + properties: + time: + type: string + format: date-time + example: 2019-10-19 17:04:57 + description: >- + The date and time the change in status occurred. Make + sure to use the U.T.C. time format. This is because + the A.P.I. has made a design decision to standardise + on it. + status: + type: string + example: "on" + description: >- + The current status of the device you would like to log. + The two status types are "on" and "off". + responses: + 201: + description: >- + The status update was successfully added to the database. + + /status/latest/{device}: + get: + operationId: api.get_latest_device_status + tags: + - Request Device Status + summary: >- + Returns the current status of the specified device. + description: >- + Use this U.R.L. to retrieve the current status of the device + you specified (in the U.R.L.). At the time of writing, the + project has six devices in total which are split equally + between Ritherdon and the gallery. Devices 1 to 3 (light-meters) + refer to the devices in Ritherdon and 4 to 6 (relays) are in + the gallery. Each light-meter and relay should pair up in the + following ways: 1->4, 2->5 and 3->6. + parameters: + - name: device + in: path + description: >- + This is the Id. of the device which you are retrieving the + current status for. The Id. should consist of a number + between 1 and 6, at the time of writing. + type: integer + required: True + responses: + 200: + description: >- + If the server can successfully retrieve the current status + for the specified device, you should receive a JSON object + like the one below. It should include the Id. of the + device, the current status and the time it was logged. + schema: + type: object + properties: + id: + type: integer + example: 2 + description: >- + The is the Id. of the device. + time: + type: string + example: 2019-10-19 17:04:57 + description: >- + The time the status change was logged in the + database. The A.P.I. has standardised on the + U.T.C. format. + status: + type: string + example: balshsdkjk + description: The current status of the device.