Skip to content

Commit c338149

Browse files
committed
fix(weather): handle invalid weather data in popup
- Added a flag to track the validity of weather data. - Updated the popup card method to display a placeholder when weather data is unavailable.
1 parent 91d0427 commit c338149

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/core/widgets/yasb/weather.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(
8383

8484
# Store weather data
8585
self._weather_data: dict[str, Any] | None = None
86+
self._has_valid_weather_data = False
8687
self._hourly_data_today: list[dict[str, Any]] = []
8788
self._hourly_data_2: list[dict[str, Any]] = []
8889
self._hourly_data_3: list[dict[str, Any]] = []
@@ -139,10 +140,6 @@ def _toggle_card(self):
139140
self._popup_card()
140141

141142
def _popup_card(self):
142-
if self._weather_data is None:
143-
logging.warning("Weather data is not yet available.")
144-
return
145-
146143
self.dialog = PopupWidget(
147144
self,
148145
self._weather_card["blur"],
@@ -152,6 +149,31 @@ def _popup_card(self):
152149
)
153150
self.dialog.setProperty("class", "weather-card")
154151

152+
if self._weather_data is None or not self._has_valid_weather_data:
153+
logging.warning("Weather data is not yet available.")
154+
layout = QVBoxLayout()
155+
layout.setContentsMargins(24, 24, 24, 24)
156+
layout.setSpacing(12)
157+
icon_label = QLabel(self._icons.get("default", ""))
158+
icon_label.setStyleSheet("font-size: 72px;")
159+
icon_label.setProperty("class", "placeholder-icon")
160+
icon_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
161+
info_label = QLabel("Weather data not available")
162+
info_label.setProperty("class", "label")
163+
info_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
164+
layout.addWidget(icon_label)
165+
layout.addWidget(info_label)
166+
self.dialog.setLayout(layout)
167+
self.dialog.adjustSize()
168+
self.dialog.setPosition(
169+
alignment=self._weather_card["alignment"],
170+
direction=self._weather_card["direction"],
171+
offset_left=self._weather_card["offset_left"],
172+
offset_top=self._weather_card["offset_top"],
173+
)
174+
self.dialog.show()
175+
return
176+
155177
main_layout = QVBoxLayout()
156178

157179
# Create graph buttons container
@@ -586,13 +608,15 @@ def process_weather_data(self, weather_data: dict[str, Any]):
586608
if alerts["alert"] and alerts["alert"][0]["expires"]
587609
else None,
588610
}
611+
self._has_valid_weather_data = True
589612
except Exception as e:
590613
if not self._retry_timer.isActive():
591614
err = f"Error processing weather data: {e}. Retrying fetch in 10 seconds."
592615
if isinstance(e, (IndexError, KeyError, TypeError)):
593616
err += f"\n{traceback.format_exc()}"
594617
logging.warning(err)
595618
self._retry_timer.start(10000)
619+
self._has_valid_weather_data = False
596620
if self._weather_data is None:
597621
self._weather_data = {
598622
"{temp}": "N/A",

0 commit comments

Comments
 (0)