From 4ce65d8965bdebdf35e5f3a4272482c0f40ef2bd Mon Sep 17 00:00:00 2001 From: Humberto Alfonso Díaz Date: Wed, 11 Dec 2019 09:41:30 +0100 Subject: FUNCT Added homescreen --- src/js/time.js | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'src/js/time.js') diff --git a/src/js/time.js b/src/js/time.js index 1757257..d4c3aa3 100644 --- a/src/js/time.js +++ b/src/js/time.js @@ -1,16 +1,31 @@ import { load as load_template } from './templates'; import Mustache from 'mustache'; +import { weather } from 'agl-js-api'; var template; var root; +var counter = 0; +var updateTime = 10000; var page = { date: { day: '', hour: '' }, - weather: { - icon: 'fas fa-cloud-sun-rain', - temperature: '20ºC' + weather: undefined, + showTemperature: function() { + return counter%5 === 0; + }, + showWind: function() { + return counter%5 === 1; + }, + showPosition: function() { + return counter%5 === 2; + }, + showHumidity: function() { + return counter%5 === 3; + }, + showDescription: function() { + return counter%5 === 4; } } @@ -29,15 +44,28 @@ function formatAMPM(date) { minutes = minutes < 10 ? '0'+minutes : minutes; var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; - } +} -function initInterval() { - setInterval(function() { - var date = new Date(); - page.date.day = days[date.getDay()], - page.date.hour = formatAMPM(date); +function update() { + var date = new Date(); + page.date.day = days[date.getDay()], + page.date.hour = formatAMPM(date); + if( counter === 0 || !page.weather) { + weather.current_weather().then(function(result) { + page.weather = result; + show(); + }, function(error) { + console.error(error); + show(); + }); + } else { show(); - }, 1000); + } + counter = (counter+1) % Math.floor(300000/updateTime); +} + +function initInterval() { + setInterval(update, updateTime); } export function init(node) { @@ -45,6 +73,7 @@ export function init(node) { template = result; root = node; Mustache.parse(template); + update(); initInterval(); }, function(error) { console.error('ERRROR loading main template', error); -- cgit 1.2.3-korg