http endpoint to retrieve sensor value added

This commit is contained in:
avollkopf 2021-08-28 17:32:31 +02:00
parent 7fc8bf84bc
commit 2d55410d4a

View file

@ -1,6 +1,7 @@
from cbpi.api.dataclasses import Props, Sensor from cbpi.api.dataclasses import Props, Sensor
from aiohttp import web from aiohttp import web
from cbpi.api import * from cbpi.api import *
import logging
auth = False auth = False
class SensorHttpEndpoints(): class SensorHttpEndpoints():
@ -206,4 +207,25 @@ class SensorHttpEndpoints():
data = await request.json() data = await request.json()
await self.controller.call_action(actor_id, data.get("name"), data.get("parameter")) await self.controller.call_action(actor_id, data.get("name"), data.get("parameter"))
return web.Response(status=204) return web.Response(status=204)
@request_mapping(path="/{id}", method="GET", auth_required=False)
async def get_value(self, request):
"""
---
description: Get Sensor Value
tags:
- Sensor
parameters:
- name: "id"
in: "path"
description: "Sensor ID"
type: "string"
required: true
"""
id = request.match_info['id']
sensor_value = self.controller.get_sensor_value(id)
logging.info(sensor_value)
return web.json_response(data=sensor_value)