Added weather

pull/2133/head
David Peer 2022-09-17 18:21:54 +02:00
parent b60f0c4687
commit b06f3a9cc2
1 changed files with 50 additions and 1 deletions

View File

@ -204,14 +204,62 @@ agenda.forEach((entry, i) => {
// ----agenda_clock_info ------------------------------------------------------
// ----weather_clock_info ------------------------------------------------------
var weather = {
temp: "?",
hum: "?",
wind: "?",
};
var weatherJson = storage.readJSON('weather.json');
if(weatherJson !== undefined && weatherJson.weather !== undefined){
weather = weatherJson.weather;
weather.temp = locale.temp(weather.temp-273.15);
weather.hum = weather.hum + "%";
weather.wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/);
weather.wind = Math.round(weather.wind[1]) + "kph";
}
var weatherItems = {
name: "Weather",
img: atob("GBiBAf+///u5//n7//8f/9wHP8gDf/gB//AB/7AH/5AcP/AQH/DwD/uAD84AD/4AA/wAAfAAAfAAAfAAAfgAA/////+bP/+zf/+zfw=="),
items: [
{
name: "temperature",
get: () => ({ text: weather.temp, img: atob("GBiBAf/D//+B//8Y//88//88//88//88//88//8k//8k//8k//8k//8k//8k//4kf/5mf/zDP/yBP/yBP/zDP/5mf/48f/8A///D/w==")}),
show: function() { weatherItems.items[0].emit("redraw"); },
hide: function () {}
},
{
name: "humidity",
get: () => ({ text: weather.hum, img: atob("GBiBAf/7///z///x///g///g///Af//Af/3Af/nA//jg//B/v/B/H+A/H8A+D8AeB8AcB4AYA8AYA8AYA+A4A/B4A//4A//8B///Dw==")}),
show: function() { weatherItems.items[1].emit("redraw"); },
hide: function () {}
},
{
name: "wind",
get: () => ({ text: weather.wind, img: atob("GBiBAf4f//wP//nn//Pn//Pzg//nAf/meIAOfAAefP///P//+fAAAfAAB////////wAAP4AAH///z///z//nz//nz//zj//wH//8Pw==")}),
show: function() { weatherItems.items[2].emit("redraw"); },
hide: function () {}
},
]
};
// ----weather_clock_info ------------------------------------------------------
// Still missing
var timerItems = {};
var weatherItems = {};
var homeAssistantItems = {};
// Load menu
var menu = load();
menu = menu.concat(agendaItems);
menu = menu.concat(weatherItems);
menu = menu.concat(clockItems);
// Set draw functions for each item
@ -348,6 +396,7 @@ function drawMenuItem(text, image){
g.setFontAlign(0,0);
// For multiline text we show an even smaller font...
text = String(text);
if(text.split('\n').length > 1){
g.setMiniFont();
} else {