Skip to content
Snippets Groups Projects
Commit 908d01ec authored by Robert Goldmann's avatar Robert Goldmann
Browse files

set example settings for tiles + externalized color logic to helpers

parent 86496e2d
No related branches found
No related tags found
No related merge requests found
......@@ -4,3 +4,23 @@ def join_url_parts(*args: str) -> str:
def round_to_decimals(value, decimals) -> str:
return '{:.{}f}'.format(value, decimals)
def determine_color_for_temperature(temperature: float):
if temperature < 0:
return 'rgba(70, 138, 221, 1)' # blue
elif temperature < 20:
return 'rgba(117, 190, 84, 1)' # green
elif temperature < 25:
return 'rgba(254, 151, 0, 1)' # orange
else:
return 'rgba(230, 76, 60, 1)' # red
def determine_color_for_wind(windSpeed: float):
if windSpeed < 20:
return 'rgba(255, 255, 255, 1)' # white
elif windSpeed < 60:
return 'rgba(254, 151, 0, 1)' # orange
else:
return 'rgba(230, 76, 60, 1)' # red
......@@ -9,6 +9,12 @@ from logic.tile.Tile import Tile
class CurrentWeatherTile(Tile):
EXAMPLE_SETTINGS = {
"lat": "51.012825",
"lon": "13.666365",
"apiKey": "myApiKey"
}
def __init__(self, uniqueName: str, settings: Dict, intervalInSeconds: int):
super().__init__(uniqueName, settings, intervalInSeconds)
......@@ -22,39 +28,19 @@ class CurrentWeatherTile(Tile):
currentWeather = weatherData['current']
currentTemperature = currentWeather['temp']
feelsLike = currentWeather['feels_like']
windSpeed = currentWeather["wind_speed"] * 3.6
windSpeed = currentWeather['wind_speed'] * 3.6
return {
'temperature': Helpers.round_to_decimals(currentTemperature, 1),
'temperatureColor': self.__determine_color_for_temperature(currentTemperature),
'temperatureColor': Helpers.determine_color_for_temperature(currentTemperature),
'feelsLike': Helpers.round_to_decimals(feelsLike, 1),
'feelsLikeColor': self.__determine_color_for_temperature(feelsLike),
'feelsLikeColor': Helpers.determine_color_for_temperature(feelsLike),
'icon': currentWeather['weather'][0]['id'],
'windDegrees': currentWeather['wind_deg'],
'windSpeed': f'{Helpers.round_to_decimals(windSpeed, 1)} km/h',
'windSpeedColor': self.__determine_color_for_wind(windSpeed)
'windSpeedColor': Helpers.determine_color_for_wind(windSpeed)
}
@staticmethod
def __determine_color_for_temperature(temperature: float):
if temperature < 0:
return 'rgba(70, 138, 221, 1)' # blue
elif temperature < 20:
return 'rgba(117, 190, 84, 1)' # green
elif temperature < 25:
return 'rgba(254, 151, 0, 1)', # orange
else:
return 'rgba(230, 76, 60, 1)' # red
@staticmethod
def __determine_color_for_wind(windSpeed: float):
if windSpeed < 20:
return 'rgba(255, 255, 255, 1)'
elif windSpeed < 60:
return 'rgba(254, 151, 0, 1)'
else:
return 'rgba(230, 76, 60, 1)'
def render(self, data: Dict) -> str:
return Tile.render_template(os.path.dirname(__file__), __class__.__name__, data=data)
......
......@@ -11,6 +11,12 @@ from logic.tile.Tile import Tile
class SevenDaysForecastTile(Tile):
EXAMPLE_SETTINGS = {
"lat": "51.012825",
"lon": "13.666365",
"apiKey": "myApiKey"
}
DATE_FORMAT = '%Y-%m-%d'
def __init__(self, uniqueName: str, settings: Dict, intervalInSeconds: int):
......
......@@ -8,6 +8,12 @@ from logic.tile.Tile import Tile
class SimpleSensorValueTile(Tile):
EXAMPLE_SETTINGS = {
"url": "http://192.168.178.39:10003",
"sensorID": 1,
"fetchType": "latest"
}
UNITS_BY_SENSOR_TYPE = {
'temperature': '&degC',
'humidity': '%'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment