Skip to content

Commit

Permalink
Added information about the smarthome used to the latest data
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianKreuzberger committed Jan 4, 2020
1 parent 6648879 commit 25c9a51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/tempBerry/smarthome/rest/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from tempBerry.smarthome.models import Room
from tempBerry.smarthome.models import Room, SmartHome


class RoomSerializer(serializers.ModelSerializer):
Expand All @@ -12,3 +12,12 @@ class Meta:
fields = ('id', 'name', 'comment', 'created_at', 'public',
'has_temperature', 'has_humidity', 'has_air_pressure')
read_only_fields = ('created_at', )


class MinimalisticSmartHomeSerializer(serializers.Serializer):
"""
Minimalistic Serializer for SmartHome
"""
id = serializers.IntegerField(read_only=True)
name = serializers.CharField(read_only=True)
description = serializers.CharField(read_only=True)
5 changes: 4 additions & 1 deletion app/tempBerry/temperatures/rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rest_framework import serializers

from tempBerry.smarthome.models import Room
from tempBerry.smarthome.rest.serializers import MinimalisticSmartHomeSerializer
from tempBerry.temperatures.models import TemperatureDataEntry


Expand Down Expand Up @@ -37,9 +38,11 @@ class RoomLiveDataSerializer(serializers.ModelSerializer):

average_last_hour = serializers.SerializerMethodField()

smarthome = MinimalisticSmartHomeSerializer(many=False)

class Meta:
model = Room
fields = ('id', 'name', 'comment', 'created_at', 'public', 'live_data',
fields = ('id', 'name', 'comment', 'created_at', 'public', 'live_data', 'smarthome',
'has_temperature', 'has_humidity', 'has_air_pressure', 'average_last_hour')
read_only_fields = ('created_at', 'live_data')

Expand Down
2 changes: 1 addition & 1 deletion app/tempBerry/temperatures/rest/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def latest(self, request):
cached_data = cache.get('last_temperature_data')

# get queryset with public rooms only
rooms = self.get_queryset().filter(public=True)
rooms = self.get_queryset().filter(public=True).prefetch_related('smarthome')

if not cached_data:
# no cached_data available yet, pre-fill it
Expand Down

0 comments on commit 25c9a51

Please sign in to comment.