v.0.5.2 weather_checker

This commit is contained in:
tiijay
2025-11-12 12:04:38 +01:00
parent eae0eaa9c8
commit 9d51f0827d
5 changed files with 67 additions and 56 deletions

View File

@@ -51,7 +51,7 @@ class CurrentCondition:
class Weather:
def __init__(self, location, current):
def __init__(self, location: Location, current: CurrentCondition):
self.location = location
self.current = current

View File

@@ -1,5 +1,5 @@
from .emojis import emojis_check
from .weather import weather_check
from .font_checker import Font_Checker
from .weather_checker import Weather_Checker
__all__ = ['emojis_check', 'Font_Checker', 'weather_check']
__all__ = ['emojis_check', 'Font_Checker', 'Weather_Checker']

View File

@@ -1,50 +0,0 @@
from app.display.neopixel_64x64 import NeoPixel_64x64
from app.web.wlan import Wlan
import app.utils.colors as colors
import app.display.fonts as fonts
def weather_check(display: NeoPixel_64x64, test_mode: bool = False):
wlan = Wlan('WOKWI-Guest', '12345678')
try:
display.clear()
display.write_text('search wlan', 0, 0, color=colors.WHITE)
display.clear_row(0, effect=False)
display.clear()
display.set_font(fonts.font_3x5)
ypos = 0
display.write_text('wlan connected', 0, ypos, color=colors.RAINBOW[0])
ypos += display.font_height + 1
display.write_text('querying', 0, ypos, color=colors.RAINBOW[1])
ypos += display.font_height + 1
display.write_text('weather data', 0, ypos, color=colors.RAINBOW[2])
w_resp = wlan.actual_weather(lang='en', test_mode=test_mode)
display.clear()
ypos = 0
display.write_text(f'{str(w_resp.location.name)}', 0, ypos, color=colors.RAINBOW[0])
ypos += display.font_height + 1
# display.set_font(fonts.font_8x8)
display.set_font(fonts.font_5x7)
display.write_text(f'{str(w_resp.current.temp_c)}°C', 0, ypos, color=colors.RAINBOW[1])
ypos += display.font_height + 1
display.write_text(f'{str(w_resp.current.condition.text)}°C', 0, ypos, color=colors.RAINBOW[2])
ypos += display.font_height + 1
display.write_text(f'upd:{str(w_resp.current.last_updated)[-5:]}', 0, ypos, color=colors.RAINBOW[3])
ypos += display.font_height + 1
display.write_text(f'cur:{str(w_resp.location.localtime)[-5:]}', 0, ypos, color=colors.RAINBOW[4])
# unten rechts in die Ecke
ypos = display.MATRIX_HEIGHT - display.font_height - 1
display.write_text('done.', 38, ypos, color=colors.NEON_GREEN)
except OSError as e:
print(f'Error: connection closed - {e}')
finally:
print('finally done.')

View File

@@ -0,0 +1,56 @@
from app.display.neopixel_64x64 import NeoPixel_64x64
from app.web.wlan import Wlan
import app.utils.colors as colors
import app.display.fonts as fonts
class Weather_Checker():
wlan: Wlan
def __init__(self, display: NeoPixel_64x64):
self.display = display
def setup_wlan(self):
self.wlan = Wlan('WOKWI-Guest', '12345678')
def check(self, test_mode: bool = False):
try:
self.display.clear()
self.display.write_text('search wlan', 0, 0, color=colors.WHITE)
self.setup_wlan()
self.display.clear()
self.display.set_font(fonts.font_3x5)
ypos = 0
self.display.write_text('wlan connected', 0, ypos, color=colors.RAINBOW[0])
ypos += self.display.font_height + 1
self.display.write_text('querying', 0, ypos, color=colors.RAINBOW[1])
ypos += self.display.font_height + 1
self.display.write_text('weather data', 0, ypos, color=colors.RAINBOW[2])
w_resp = self.wlan.actual_weather(lang='de', test_mode=test_mode)
self.display.clear()
ypos = 0
self.display.write_text(f'{str(w_resp.location.name)}', 0, ypos, color=colors.RAINBOW[0])
ypos += self.display.font_height + 1
# self.display.set_font(fonts.font_8x8)
self.display.set_font(fonts.font_5x7)
self.display.write_text(f'{str(w_resp.current.temp_c)}°C', 0, ypos, color=colors.RAINBOW[1])
ypos += self.display.font_height + 1
self.display.write_text(f'{str(w_resp.current.condition.text)}', 0, ypos, color=colors.RAINBOW[2])
ypos += self.display.font_height + 1
self.display.write_text(f'upd:{str(w_resp.current.last_updated)[-5:]}', 0, ypos, color=colors.RAINBOW[3])
ypos += self.display.font_height + 1
self.display.write_text(f'cur:{str(w_resp.location.localtime)[-5:]}', 0, ypos, color=colors.RAINBOW[4])
# unten rechts in die Ecke
ypos = self.display.MATRIX_HEIGHT - self.display.font_height - 1
self.display.write_text('done.', 38, ypos, color=colors.NEON_GREEN)
except OSError as e:
print(f'Error: connection closed - {e}')
finally:
print('finally done.')

11
main.py
View File

@@ -1,13 +1,18 @@
from app.display.neopixel_64x64 import NeoPixel_64x64
import app.tryout as tryout
from app.tryout.font_checker import Font_Checker
from app.tryout import Font_Checker, Weather_Checker
# Programm Startpunkt
if __name__ == '__main__':
display = NeoPixel_64x64()
font_checker : Font_Checker = Font_Checker( display)
font_checker.fonts_check(pretty=False)
# font_checker : Font_Checker = Font_Checker( display)
# font_checker.fonts_check(pretty=False)
# tryout.emojis_check(display)
# tryout.weather_check(display, test_mode=False)
weather_checker: Weather_Checker = Weather_Checker( display)
weather_checker.check(test_mode=False)
# utils.show_system_load()