From ddb836dbe40ee05c43ba790c9085a01ed7baa896 Mon Sep 17 00:00:00 2001 From: myTselection Date: Tue, 28 Nov 2023 22:15:50 +0100 Subject: [PATCH] include last day of period for period_end_date, #35 --- .../telenet_telemeter/manifest.json | 2 +- custom_components/telenet_telemeter/sensor.py | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/custom_components/telenet_telemeter/manifest.json b/custom_components/telenet_telemeter/manifest.json index b982d6d..4b41dc6 100644 --- a/custom_components/telenet_telemeter/manifest.json +++ b/custom_components/telenet_telemeter/manifest.json @@ -9,5 +9,5 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/myTselection/telenet_telemeter/issues", "requirements": ["beautifulsoup4", "html5lib"], - "version": "1.5.0" + "version": "1.5.2" } \ No newline at end of file diff --git a/custom_components/telenet_telemeter/sensor.py b/custom_components/telenet_telemeter/sensor.py index a057f4d..7c03cd9 100644 --- a/custom_components/telenet_telemeter/sensor.py +++ b/custom_components/telenet_telemeter/sensor.py @@ -290,6 +290,9 @@ async def async_update(self): self._product = self._data._telemeter.get('internetusage')[0].get('availableperiods')[0].get('usages')[0].get('producttype') self._period_start_date = datetime.strptime(self._data._telemeter.get('internetusage')[0].get('availableperiods')[0].get('usages')[0].get('periodstart'), _TELENET_DATETIME_FORMAT) self._period_end_date = datetime.strptime(self._data._telemeter.get('internetusage')[0].get('availableperiods')[0].get('usages')[0].get('periodend'), _TELENET_DATETIME_FORMAT) + # Add one day to the datetime object + self._period_end_date = self._period_end_date + timedelta(days=1) + tz_info = self._period_end_date.tzinfo self._extended_volume = self._data._telemeter.get('internetusage')[0].get('availableperiods')[0].get('usages')[0].get('extendedvolume').get('volume') else: @@ -297,6 +300,9 @@ async def async_update(self): self._product = self._data._product_details.get('product').get('labelkey','N/A') self._period_start_date = datetime.strptime(self._data._telemeter.get('startDate'), _TELENET_DATETIME_FORMAT_V2) self._period_end_date = datetime.strptime(self._data._telemeter.get('endDate'), _TELENET_DATETIME_FORMAT_V2) + + # Add one day to the datetime object + self._period_end_date = self._period_end_date + timedelta(days=1) tz_info = self._period_end_date.tzinfo self._extended_volume = 0 #TODO unclear if available wifiDetails = self._data._telemeter.get('wifidetails') @@ -767,6 +773,15 @@ async def async_update(self): self._last_update = productdetails.get('lastupdated') self._product = productdetails.get('label') self._period_end_date = productdetails.get('nextbillingdate') + format_string = "%d-%m-%Y %H:%M:%S" + # Parse the timestamp string into a datetime object + original_datetime = datetime.strptime(self._period_end_date, format_string) + + # Add one day to the datetime object + new_datetime = original_datetime + timedelta(days=1) + + # Format the new datetime object back to a string + self._period_end_date = new_datetime.strftime(format_string) # get shared sensor sharedusage = productdetails.get('sharedusage') @@ -899,6 +914,15 @@ async def async_update(self): self._last_update = productdetails.get('lastupdated') self._product = productdetails.get('label') self._period_end_date = productdetails.get('nextbillingdate') + format_string = "%d-%m-%Y %H:%M:%S" + # Parse the timestamp string into a datetime object + original_datetime = datetime.strptime(self._period_end_date, format_string) + + # Add one day to the datetime object + new_datetime = original_datetime + timedelta(days=1) + + # Format the new datetime object back to a string + self._period_end_date = new_datetime.strftime(format_string) # get shared sensor unassignesub = productdetails.get('unassigned').get('mobilesubscriptions')[self._subsid] @@ -1045,6 +1069,15 @@ async def async_update(self): self._last_update = productdetails.get('lastupdated') self._product = productdetails.get('label') self._period_end_date = productdetails.get('nextbillingdate') + format_string = "%d-%m-%Y %H:%M:%S" + # Parse the timestamp string into a datetime object + original_datetime = datetime.strptime(self._period_end_date, format_string) + + # Add one day to the datetime object + new_datetime = original_datetime + timedelta(days=1) + + # Format the new datetime object back to a string + self._period_end_date = new_datetime.strftime(format_string) # get shared sensor profile = productdetails.get('profiles')[self._profileid] @@ -1210,6 +1243,15 @@ async def async_update(self): self._last_update = mobileusage.get('lastUpdated') self._label = self._product = self._productSubscription.get('label') self._period_end_date = mobileusage.get('nextBillingDate') + format_string = "%d-%m-%Y %H:%M:%S" + # Parse the timestamp string into a datetime object + original_datetime = datetime.strptime(self._period_end_date, format_string) + + # Add one day to the datetime object + new_datetime = original_datetime + timedelta(days=1) + + # Format the new datetime object back to a string + self._period_end_date = new_datetime.strftime(format_string) self._outofbundle = f"{mobileusage.get('outOfBundle').get('usedUnits')} {mobileusage.get('outOfBundle').get('unitType')}" self._number = self._identifier self._active = self._productSubscription.get('status')