mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 21:33:00 +00:00
Update hourly forecast: Match modern layout with 5-hour display
This commit is contained in:
@@ -112,8 +112,8 @@ class WeatherManager:
|
|||||||
if not forecast_data:
|
if not forecast_data:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Process hourly forecast (next 6 hours)
|
# Process hourly forecast (next 5 hours)
|
||||||
hourly_list = forecast_data.get('list', [])[:6] # Get next 6 3-hour forecasts
|
hourly_list = forecast_data.get('list', [])[:5] # Changed from 6 to 5 to match image
|
||||||
self.hourly_forecast = []
|
self.hourly_forecast = []
|
||||||
|
|
||||||
for hour_data in hourly_list:
|
for hour_data in hourly_list:
|
||||||
@@ -121,7 +121,7 @@ class WeatherManager:
|
|||||||
temp = round(hour_data['main']['temp'])
|
temp = round(hour_data['main']['temp'])
|
||||||
condition = hour_data['weather'][0]['main']
|
condition = hour_data['weather'][0]['main']
|
||||||
self.hourly_forecast.append({
|
self.hourly_forecast.append({
|
||||||
'hour': dt.strftime('%I%p').lstrip('0'), # Remove leading 0
|
'hour': dt.strftime('%I:00 %p').lstrip('0'), # Format as "2:00 PM"
|
||||||
'temp': temp,
|
'temp': temp,
|
||||||
'condition': condition
|
'condition': condition
|
||||||
})
|
})
|
||||||
@@ -321,42 +321,46 @@ class WeatherManager:
|
|||||||
# Clear once at the start
|
# Clear once at the start
|
||||||
self.display_manager.clear()
|
self.display_manager.clear()
|
||||||
|
|
||||||
# Display next 3 hours
|
# Create a new image for drawing
|
||||||
hours_to_show = min(3, len(self.hourly_forecast))
|
image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height))
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
# Display next 5 hours
|
||||||
|
hours_to_show = min(5, len(self.hourly_forecast))
|
||||||
section_width = self.display_manager.matrix.width // hours_to_show
|
section_width = self.display_manager.matrix.width // hours_to_show
|
||||||
|
|
||||||
for i in range(hours_to_show):
|
for i in range(hours_to_show):
|
||||||
forecast = current_state[i]
|
forecast = self.hourly_forecast[i]
|
||||||
x = i * section_width
|
x = i * section_width
|
||||||
|
center_x = x + section_width // 2
|
||||||
|
|
||||||
# Draw hour
|
# Draw hour at top
|
||||||
self.display_manager.draw_text(
|
hour_text = forecast['hour']
|
||||||
forecast['hour'],
|
hour_width = draw.textlength(hour_text, font=self.display_manager.small_font)
|
||||||
x=x + 2,
|
draw.text((center_x - hour_width // 2, 2),
|
||||||
y=2,
|
hour_text,
|
||||||
color=self.COLORS['text'],
|
font=self.display_manager.small_font,
|
||||||
small_font=True
|
fill=self.COLORS['text'])
|
||||||
)
|
|
||||||
|
|
||||||
# Draw weather icon
|
# Draw weather icon in middle
|
||||||
|
icon_y = 12
|
||||||
self.display_manager.draw_weather_icon(
|
self.display_manager.draw_weather_icon(
|
||||||
forecast['condition'],
|
forecast['condition'],
|
||||||
x=x + (section_width - self.ICON_SIZE['medium']) // 2,
|
x=center_x - self.ICON_SIZE['medium'] // 2,
|
||||||
y=12,
|
y=icon_y,
|
||||||
size=self.ICON_SIZE['medium']
|
size=self.ICON_SIZE['medium']
|
||||||
)
|
)
|
||||||
|
|
||||||
# Draw temperature
|
# Draw temperature at bottom
|
||||||
temp = f"{forecast['temp']}°"
|
temp_text = f"{forecast['temp']}°"
|
||||||
self.display_manager.draw_text(
|
temp_width = draw.textlength(temp_text, font=self.display_manager.small_font)
|
||||||
temp,
|
draw.text((center_x - temp_width // 2, 24),
|
||||||
x=x + (section_width - len(temp) * 4) // 2,
|
temp_text,
|
||||||
y=24,
|
font=self.display_manager.small_font,
|
||||||
color=self.COLORS['highlight'],
|
fill=self.COLORS['highlight'])
|
||||||
small_font=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update display once after all elements are drawn
|
# Update the display
|
||||||
|
self.display_manager.image = image
|
||||||
self.display_manager.update_display()
|
self.display_manager.update_display()
|
||||||
self.last_hourly_state = current_state
|
self.last_hourly_state = current_state
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user