Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return something sensible when searching readings for non-existent components #276

Merged

Conversation

timcowlishaw
Copy link
Contributor

Fixes #275

Currently, we 500 when searching for readings for a sensor which isn't present on a device. This PR instead returns a meaningful empty response:

{
  "device_id": "15333",
  "sensor_key": null,
  "sensor_id": 3,
  "component_id": null,
  "rollup": "20m",
  "function": "avg",
  "from": "2023-10-25",
  "to": "2023-10-26",
  "sample_size": 0,
  "readings": []
}

@oscgonfer
Copy link
Contributor

Tested in staging. Very good work!

https://staging-api.smartcitizen.me/v0/devices/16602/readings?sensor_id=550&rollup=1m&from=2010-01-01

{"device_id":"16602","sensor_key":null,"sensor_id":550,"component_id":null,"rollup":"1m","function":"avg","from":"2010-01-01","to":null,"sample_size":0,"readings":[]}

https://staging-api.smartcitizen.me/v0/devices/16602/readings?sensor_id=55&rollup=1m&from=2010-01-01

{"device_id":16602,"sensor_key":"t","sensor_id":55,"component_id":240,"rollup":"1m","function":"avg","from":"2010-01-01T00:00:00Z","to":"2023-10-27T09:38:52Z","sample_size":9,"readings":[["2023-10-27T09:38:20Z",23.92],["2023-10-27T09:37:20Z",24.07],["2023-10-27T09:36:20Z",24.05],["2023-10-27T09:35:20Z",23.98],["2023-10-27T09:34:20Z",24.05],["2023-10-27T09:33:20Z",24.02],["2023-10-27T09:32:20Z",24.08],["2023-10-27T09:31:20Z",24.02],["2023-10-27T09:30:20Z",24.25]]}

@oscgonfer oscgonfer merged commit 9d37ef2 into master Oct 27, 2023
2 checks passed
@timcowlishaw timcowlishaw deleted the bugfix/dont-500-on-non-existent-components-for-readings branch July 4, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not 500 when searching for readings for a sensor which does not exist on a device
2 participants