From 76fd853ab3c388e132b30bf11cfda5160c897dcd Mon Sep 17 00:00:00 2001 From: Jacob Berelman <630000+stickpin@users.noreply.github.com> Date: Thu, 23 May 2024 17:56:58 +0200 Subject: [PATCH] Fix time timezone detection --- .../meinvodafone/MeinVodafoneContract.py | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/custom_components/meinvodafone/MeinVodafoneContract.py b/custom_components/meinvodafone/MeinVodafoneContract.py index aafe0e6..da0a8d6 100644 --- a/custom_components/meinvodafone/MeinVodafoneContract.py +++ b/custom_components/meinvodafone/MeinVodafoneContract.py @@ -89,7 +89,9 @@ def minutes_remaining(self): @property def minutes_remaining_last_update(self): """Return remaining minutes for the plan last update timestamp.""" - return self.get_value(MINUTES, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_minutes_remaining_supported(self): @@ -107,7 +109,9 @@ def minutes_used(self): @property def minutes_used_last_update(self): """Return used minutes for the plan last update timestamp.""" - return self.get_value(MINUTES, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_minutes_used_supported(self): @@ -125,7 +129,9 @@ def minutes_total(self): @property def minutes_total_last_update(self): """Return total minutes for the plan last update timestamp.""" - return self.get_value(MINUTES, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(MINUTES, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_minutes_total_supported(self): @@ -153,7 +159,9 @@ def sms_remaining(self): @property def sms_remaining_last_update(self): """Return remaining sms for the plan last update timestamp.""" - return self.get_value(SMS, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_sms_remaining_supported(self): @@ -171,7 +179,9 @@ def sms_used(self): @property def sms_used_last_update(self): """Return used sms for the plan last update timestamp.""" - return self.get_value(SMS, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_sms_used_supported(self): @@ -189,7 +199,9 @@ def sms_total(self): @property def sms_total_last_update(self): """Return total sms for the plan last update timestamp.""" - return self.get_value(SMS, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(SMS, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_sms_total_supported(self): @@ -217,7 +229,9 @@ def data_remaining(self): @property def data_remaining_last_update(self): """Return remaining data for the plan last update timestamp.""" - return self.get_value(DATA, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_data_remaining_supported(self): @@ -235,7 +249,9 @@ def data_used(self): @property def data_used_last_update(self): """Return used data for the plan last update timestamp.""" - return self.get_value(DATA, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_data_used_supported(self): @@ -253,7 +269,9 @@ def data_total(self): @property def data_total_last_update(self): """Return total data for the plan last update timestamp.""" - return self.get_value(DATA, LAST_UPDATE) + return datetime.datetime.strptime( + self.get_value(DATA, LAST_UPDATE), "%Y-%m-%dT%H:%M:%S" + ).replace(tzinfo=datetime.UTC) @property def is_data_total_supported(self): @@ -306,14 +324,12 @@ def is_billing_last_summary_supported(self): @property def billing_cycle_days(self): """Return days until end of the billing cycle.""" - datetime_now = ( - datetime.datetime.now(datetime.UTC) - .replace(tzinfo=None) - .replace(hour=0, minute=0, second=0, microsecond=0) + datetime_now = datetime.datetime.now(datetime.UTC).replace( + hour=0, minute=0, second=0, microsecond=0 ) cycle_end = datetime.datetime.strptime( self.billing_cycle_end, "%Y-%m-%d" - ).replace(tzinfo=None) + ).replace(tzinfo=datetime.UTC) delta = cycle_end - datetime_now return delta.days