Skip to content

Commit

Permalink
include last day of period for period_end_date, #35
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Nov 28, 2023
1 parent b9c1910 commit ddb836d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/telenet_telemeter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
42 changes: 42 additions & 0 deletions custom_components/telenet_telemeter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,19 @@ 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:
self._last_update = self._data._telemeter.get('internet').get('totalUsage').get('lastUsageDate')
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')
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit ddb836d

Please sign in to comment.