Add API routes for POSTing temperature data
This commit is contained in:
parent
50497b83b0
commit
cd27c1ee4b
|
@ -337,14 +337,34 @@ class IpnView(views.APIView):
|
|||
return Response(200)
|
||||
|
||||
|
||||
class StatsView(views.APIView):
|
||||
def get(self, request):
|
||||
class StatsViewSet(viewsets.ViewSet, List):
|
||||
def list(self, request):
|
||||
stats_keys = utils_stats.DEFAULTS.keys()
|
||||
cached_stats = cache.get_many(stats_keys)
|
||||
stats = utils_stats.DEFAULTS.copy()
|
||||
stats.update(cached_stats)
|
||||
return Response(stats)
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def bay_108_temp(self, request):
|
||||
try:
|
||||
cache.set('bay_108_temp', round(float(request.data['data']), 1))
|
||||
return Response(200)
|
||||
except ValueError:
|
||||
raise exceptions.ValidationError(dict(data='Invalid float.'))
|
||||
except KeyError:
|
||||
raise exceptions.ValidationError(dict(data='This field is required.'))
|
||||
|
||||
@action(detail=False, methods=['post'])
|
||||
def bay_110_temp(self, request):
|
||||
try:
|
||||
cache.set('bay_110_temp', round(float(request.data['data']), 1))
|
||||
return Response(200)
|
||||
except ValueError:
|
||||
raise exceptions.ValidationError(dict(data='Invalid float.'))
|
||||
except KeyError:
|
||||
raise exceptions.ValidationError(dict(data='This field is required.'))
|
||||
|
||||
|
||||
class BackupView(views.APIView):
|
||||
def get(self, request):
|
||||
|
|
|
@ -11,6 +11,7 @@ IPN_ROUTE = r'^ipn/{}/'.format(secrets.IPN_RANDOM)
|
|||
router = routers.DefaultRouter()
|
||||
router.register(r'door', views.DoorViewSet, basename='door')
|
||||
router.register(r'cards', views.CardViewSet, basename='card')
|
||||
router.register(r'stats', views.StatsViewSet, basename='stats')
|
||||
router.register(r'search', views.SearchViewSet, basename='search')
|
||||
router.register(r'members', views.MemberViewSet, basename='members')
|
||||
router.register(r'courses', views.CourseViewSet, basename='course')
|
||||
|
@ -29,7 +30,6 @@ urlpatterns = [
|
|||
url(r'^password/change/', views.PasswordChangeView.as_view(), name='rest_password_change'),
|
||||
url(r'^user/', views.UserView.as_view(), name='user'),
|
||||
url(r'^ping/', views.PingView.as_view(), name='ping'),
|
||||
url(r'^stats/', views.StatsView.as_view(), name='stats'),
|
||||
url(r'^paste/', views.PasteView.as_view(), name='paste'),
|
||||
url(r'^backup/', views.BackupView.as_view(), name='backup'),
|
||||
url(IPN_ROUTE, views.IpnView.as_view(), name='ipn'),
|
||||
|
|
Loading…
Reference in New Issue
Block a user