Skip to content

Commit

Permalink
mobile data date formatting fix #40
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Jan 2, 2024
1 parent e8b2a11 commit 98f9314
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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.3"
"version": "1.5.4"
}
17 changes: 9 additions & 8 deletions custom_components/telenet_telemeter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_LOGGER = logging.getLogger(__name__)
_TELENET_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.0%z"
_TELENET_DATETIME_FORMAT_V2 = "%Y-%m-%d"
_TELENET_DATETIME_FORMAT_MOBILE = "%Y-%m-%dT%H:%M:%S%z"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
Expand Down Expand Up @@ -774,13 +775,13 @@ async def async_update(self):
self._product = productdetails.get('label')
self._period_end_date = productdetails.get('nextbillingdate')
# Parse the timestamp string into a datetime object
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT)
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT_MOBILE)

# 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(_TELENET_DATETIME_FORMAT)
self._period_end_date = new_datetime.strftime(_TELENET_DATETIME_FORMAT_MOBILE)
# get shared sensor
sharedusage = productdetails.get('sharedusage')

Expand Down Expand Up @@ -914,13 +915,13 @@ async def async_update(self):
self._product = productdetails.get('label')
self._period_end_date = productdetails.get('nextbillingdate')
# Parse the timestamp string into a datetime object
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT)
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT_MOBILE)

# 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(_TELENET_DATETIME_FORMAT)
self._period_end_date = new_datetime.strftime(_TELENET_DATETIME_FORMAT_MOBILE)
# get shared sensor
unassignesub = productdetails.get('unassigned').get('mobilesubscriptions')[self._subsid]

Expand Down Expand Up @@ -1068,13 +1069,13 @@ async def async_update(self):
self._product = productdetails.get('label')
self._period_end_date = productdetails.get('nextbillingdate')
# Parse the timestamp string into a datetime object
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT)
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT_MOBILE)

# 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(_TELENET_DATETIME_FORMAT)
self._period_end_date = new_datetime.strftime(_TELENET_DATETIME_FORMAT_MOBILE)
# get shared sensor
profile = productdetails.get('profiles')[self._profileid]

Expand Down Expand Up @@ -1241,13 +1242,13 @@ async def async_update(self):
self._label = self._product = self._productSubscription.get('label')
self._period_end_date = mobileusage.get('nextBillingDate')
# Parse the timestamp string into a datetime object
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT)
original_datetime = datetime.strptime(self._period_end_date, _TELENET_DATETIME_FORMAT_MOBILE)

# 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(_TELENET_DATETIME_FORMAT)
self._period_end_date = new_datetime.strftime(_TELENET_DATETIME_FORMAT_MOBILE)
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 98f9314

Please sign in to comment.