fix: Replace pytz with zoneinfo (Python 3.9+ standard)#317
Conversation
- Replace deprecated pytz library with built-in zoneinfo - Add localize_datetime() helper for timezone-aware datetimes - Update all .localize() calls to use the new helper - This change removes the pytz dependency
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
User description
Summary
Replace deprecated
pytzlibrary with Python 3.9+'s built-inzoneinfomodule.Changes
import pytzwithfrom zoneinfo import ZoneInfoincommons.pylocalize_datetime()helper function for timezone-aware datetime conversion.localize()calls incoordinator.pyandsensor.pyto use the new helperpytzdependencyWhy
pytzis deprecated in favor of the built-inzoneinfomodule (PEP 615)Compatibility
.ruff.toml)zoneinfohas been available since Python 3.9PR Type
Bug fix, Enhancement
Description
Replace deprecated
pytzlibrary with Python 3.9+ built-inzoneinfomoduleAdd
localize_datetime()helper function for consistent timezone handlingUpdate all timezone localization calls across coordinator and sensor modules
Remove external
pytzdependency, reducing project dependenciesDiagram Walkthrough
File Walkthrough
commons.py
Replace pytz with zoneinfo and add helpercustom_components/iec/commons.py
import pytzwithfrom zoneinfo import ZoneInfoTIMEZONEconstant to useZoneInfo("Asia/Jerusalem")instead ofpytz.timezone()localize_datetime()helper function that safely localizesnaive datetimes to the IEC timezone
datetimeclass for type hints in the new helper functioncoordinator.py
Update coordinator to use localize_datetime helpercustom_components/iec/coordinator.py
localize_datetimehelper function from commons moduleTIMEZONE.localize()calls withlocalize_datetime()function_update_data(),_insert_statistics(), and_estimate_bill()methodsimplementation
sensor.py
Update sensor to use localize_datetime helpercustom_components/iec/sensor.py
localize_datetimehelper function from commons moduleTIMEZONE.localize()calls withlocalize_datetime()functionconsumption