Skip to content

Commit 3993e5c

Browse files
[API] Gas cost missing at start of day #432
1 parent 65a6e48 commit 3993e5c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ v1.14.0 - 2018-xx-xx
2626
- [`#441 <https://github.com/dennissiemensma/dsmr-reader/issues/441>`_] PVOutput exports schedulen naar ingestelde upload interval - by pyrocumulus
2727
- [`#436 <https://github.com/dennissiemensma/dsmr-reader/issues/436>`_] Update docs: authentication method for public webinterface
2828
- [`#445 <https://github.com/dennissiemensma/dsmr-reader/issues/445>`_] Upload/export to PVoutput doesn't work
29+
- [`#432 <https://github.com/dennissiemensma/dsmr-reader/issues/432>`_] [API] Gas cost missing at start of day
2930

3031

3132

dsmr_api/tests/v2/test_consumption.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ def test_get(self, now_mock):
2323

2424
FIELDS = (
2525
'day', 'electricity1', 'electricity2', 'electricity1_returned', 'electricity2_returned',
26-
'electricity1_cost', 'electricity2_cost', 'total_cost'
26+
'electricity1_cost', 'electricity2_cost', 'gas', 'gas_cost', 'total_cost'
2727
)
2828

2929
for x in FIELDS:
3030
self.assertIn(x, result.keys())
3131

3232

33+
class TestTodayWithGas(TestToday):
34+
fixtures = [
35+
'dsmr_api/test_electricity_consumption.json',
36+
'dsmr_api/test_electricity_consumption.json',
37+
'dsmr_api/test_gas_consumption.json'
38+
]
39+
40+
3341
class TestElectricity(APIv2TestCase):
3442
fixtures = ['dsmr_api/test_electricity_consumption.json']
3543

dsmr_api/views/v2.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from decimal import Decimal
2+
13
from rest_framework import mixins, viewsets
24
from rest_framework.response import Response
35
from rest_framework.views import APIView
@@ -31,6 +33,7 @@ class TodayConsumptionView(APIView):
3133
'electricity2_returned_end', 'electricity_cost_merged', 'electricity_merged', 'electricity_returned_merged',
3234
'average_temperature', 'lowest_temperature', 'highest_temperature', 'latest_consumption'
3335
)
36+
DEFAULT_ZERO_FIELDS = ('gas', 'gas_cost') # These might miss during the first hour of each day.
3437

3538
def get(self, request):
3639
try:
@@ -45,6 +48,11 @@ def get(self, request):
4548
if x in day_totals.keys():
4649
del day_totals[x]
4750

51+
# Default these, if omitted.
52+
for x in self.DEFAULT_ZERO_FIELDS:
53+
if x not in day_totals.keys():
54+
day_totals[x] = Decimal(0)
55+
4856
return Response(day_totals)
4957

5058

0 commit comments

Comments
 (0)