Skip to content

Commit

Permalink
Merge for release v1.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jan 11, 2017
1 parent 88b0ea8 commit 16444fa
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ Please make sure you have a fresh **database backup** before upgrading! Upgradin



v1.5.3 - 2017-01-11
^^^^^^^^^^^^^^^^^^^

**Tickets resolved in this release:**

- Improve MinderGas API client implementation (`#228 <https://github.com/dennissiemensma/dsmr-reader/issues/228>`_).



v1.5.2 - 2017-01-09
^^^^^^^^^^^^^^^^^^^

Expand Down
19 changes: 10 additions & 9 deletions dsmr_mindergas/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def export():
if not should_export():
return

# For backend logging in Supervisor.
print(' - Attempting to export gas meter position to MinderGas.')
print(' - MinderGas | Attempting to upload gas meter position.')

# Just post the latest reading of the day before.
today = timezone.localtime(timezone.now())
Expand All @@ -43,6 +42,9 @@ def export():
hour=0,
))

# Push back for a day and a bit.
next_export = midnight + timezone.timedelta(hours=24, minutes=random.randint(15, 59))

try:
last_gas_reading = GasConsumption.objects.filter(
# Slack of six hours to make sure we have any valid reading at all.
Expand All @@ -51,10 +53,10 @@ def export():
except IndexError:
# Just continue, even though we have no data... yet.
last_gas_reading = None
print(' - No gas readings found to export to MinderGas')
print(' - MinderGas | No gas readings found for uploading')
else:
settings = MinderGasSettings.get_solo()
print(' - Exporting gas meter position to MinderGas:', last_gas_reading.delivered)
print(' - MinderGas | Uploading gas meter position: {}'.format(last_gas_reading.delivered))

# Register telegram by simply sending it to the application with a POST request.
response = requests.post(
Expand All @@ -67,12 +69,11 @@ def export():
)

if response.status_code != 201:
raise AssertionError('MinderGas upload failed: %s (HTTP %s)'.format(response.text, response.status_code))

# Push back for a day and a bit.
next_export = midnight + timezone.timedelta(hours=24, minutes=random.randint(15, 59))
print(' - Delaying the next export to MinderGas until:', next_export)
# Try again in an hour.
next_export = midnight + timezone.timedelta(hours=1)
print(' [!] MinderGas upload failed (HTTP {}): {}'.format(response.status_code, response.text))

print(' - MinderGas | Delaying the next upload until: {}'.format(next_export))
settings = MinderGasSettings.get_solo()
settings.next_export = next_export
settings.save()
6 changes: 3 additions & 3 deletions dsmr_mindergas/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ def test_export_fail(self, now_mock, should_export_mock, requests_post_mock):
for current_error_code in (401, 422):
requests_post_mock.return_value = mock.MagicMock(status_code=current_error_code, text='Error message')

with self.assertRaises(AssertionError):
dsmr_mindergas.services.export()
dsmr_mindergas.services.export()

settings = MinderGasSettings.get_solo()
self.assertIsNone(settings.next_export)
# This should be set one hour forward now.
self.assertEqual(settings.next_export, timezone.make_aware(timezone.datetime(2015, 12, 12, hour=1, minute=0)))
self.assertTrue(requests_post_mock.called)

@mock.patch('requests.post')
Expand Down
2 changes: 1 addition & 1 deletion dsmrreader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
from django.utils.version import get_version


VERSION = (1, 5, 2, 'final', 0)
VERSION = (1, 5, 3, 'final', 0)

__version__ = get_version(VERSION)
Binary file modified dsmrreader/locales/nl/LC_MESSAGES/django.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion dsmrreader/locales/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: DSMR Reader v1.x\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-01-09 21:05+0100\n"
"POT-Creation-Date: 2017-01-11 20:49+0100\n"
"PO-Revision-Date: 2017-01-08 20:19+0100\n"
"Last-Translator: Dennis Siemensma <github@dennissiemensma.nl>\n"
"Language-Team: Dennis Siemensma <github@dennissiemensma.nl>\n"
Expand Down

0 comments on commit 16444fa

Please sign in to comment.