fix: datetime import shadow breaks gateway price data#3696
Merged
springfall2008 merged 1 commit intomainfrom Mar 29, 2026
Merged
fix: datetime import shadow breaks gateway price data#3696springfall2008 merged 1 commit intomainfrom
springfall2008 merged 1 commit intomainfrom
Conversation
`from datetime import datetime` on line 18 shadows `import datetime` on line 10, causing all `datetime.datetime.*`, `datetime.timezone.*` and `datetime.timedelta()` calls to fail with: "type object 'datetime.datetime' has no attribute 'datetime'" This breaks `_publish_predbat_data()` which prevents price/timeline data from reaching gateway devices. Fix: remove the shadowing import and use `datetime.datetime.*` consistently throughout. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the GatewayMQTT component caused by datetime module/class shadowing, which prevented gateway devices from receiving published price/timeline data.
Changes:
- Removed
from datetime import datetimethat shadowed thedatetimemodule. - Updated affected call sites to use
datetime.datetime.*/datetime.timezone.*explicitly. - Removed an inner
datetime/timezoneimport and replaced it with module-qualified usage.
Comment on lines
411
to
415
| if status.timestamp > 0 and len(status.inverters) > 0: | ||
| primary_inv = next((inv for inv in status.inverters if inv.primary), status.inverters[0]) | ||
| ts_suffix = primary_inv.serial[-6:].lower() if len(primary_inv.serial) > 6 else primary_inv.serial.lower() | ||
| dt = datetime.fromtimestamp(status.timestamp) | ||
| dt = datetime.datetime.fromtimestamp(status.timestamp) | ||
| self.set_state_wrapper( |
There was a problem hiding this comment.
The datetime-shadowing bug was in a runtime path (_publish_predbat_data/inject*), but the current gateway unit tests don’t exercise _inject_entities / _inject_inverter_entities (timestamp formatting) or _check_token_refresh (ISO timestamp parsing). Consider adding a small regression test that constructs a minimal GatewayMQTT instance and calls these methods with a sample GatewayStatus / expires_at string to ensure they don’t raise and produce expected values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gateway.pyhas bothimport datetime(line 10) andfrom datetime import datetime(line 18)datetimebecomes the class not the moduledatetime.datetime.*,datetime.timezone.*, anddatetime.timedelta()calls fail with:type object 'datetime.datetime' has no attribute 'datetime'_publish_predbat_data()every 30 seconds, preventing price/timeline data from reaching gateway devicesFix
from datetime import datetimeimportdatetime.datetime.*consistently (4 call sites fixed)Test plan
🤖 Generated with Claude Code