From 16444fa9f9602d01e2a6064580bca2cf13b40aaf Mon Sep 17 00:00:00 2001 From: Dennis Siemensma Date: Wed, 11 Jan 2017 20:52:35 +0100 Subject: [PATCH] Merge for release v1.5.3 --- docs/changelog.rst | 9 +++++++++ dsmr_mindergas/services.py | 19 ++++++++++--------- dsmr_mindergas/tests/test_services.py | 6 +++--- dsmrreader/__init__.py | 2 +- dsmrreader/locales/nl/LC_MESSAGES/django.mo | Bin 37819 -> 37819 bytes dsmrreader/locales/nl/LC_MESSAGES/django.po | 2 +- 6 files changed, 24 insertions(+), 14 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index adced6187..70bd89983 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 `_). + + + v1.5.2 - 2017-01-09 ^^^^^^^^^^^^^^^^^^^ diff --git a/dsmr_mindergas/services.py b/dsmr_mindergas/services.py index 507a9e50b..7200b9c25 100644 --- a/dsmr_mindergas/services.py +++ b/dsmr_mindergas/services.py @@ -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()) @@ -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. @@ -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( @@ -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() diff --git a/dsmr_mindergas/tests/test_services.py b/dsmr_mindergas/tests/test_services.py index 76b42fe0e..806e8a88a 100644 --- a/dsmr_mindergas/tests/test_services.py +++ b/dsmr_mindergas/tests/test_services.py @@ -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') diff --git a/dsmrreader/__init__.py b/dsmrreader/__init__.py index 43d7dc489..178466f92 100644 --- a/dsmrreader/__init__.py +++ b/dsmrreader/__init__.py @@ -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) diff --git a/dsmrreader/locales/nl/LC_MESSAGES/django.mo b/dsmrreader/locales/nl/LC_MESSAGES/django.mo index ca58ec85333aefe660a15e06593a98d06edcccd7..bb8c66a8cfeab193e307b99c03b9121ac2133c15 100644 GIT binary patch delta 23 ecmdnJoN4!RrVTk^9EOGpMg~?UmYYk$+-(78@(0fV delta 23 ecmdnJoN4!RrVTk^90ryOMut`frkhK`+-(798VAn+ diff --git a/dsmrreader/locales/nl/LC_MESSAGES/django.po b/dsmrreader/locales/nl/LC_MESSAGES/django.po index f9141eb0d..8deb510d5 100644 --- a/dsmrreader/locales/nl/LC_MESSAGES/django.po +++ b/dsmrreader/locales/nl/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: Dennis Siemensma \n"