Skip to content

Commit

Permalink
More windy details added.
Browse files Browse the repository at this point in the history
  • Loading branch information
fmandal committed Feb 21, 2020
1 parent df5229c commit af674d6
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 46 deletions.
16 changes: 13 additions & 3 deletions MMM-YrThen.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@
text-align: center;
}
.yrthen-icon-cell {
padding-right: 10px;
padding-left: 10px;
text-align: center;
}

.yrthen-temp {
padding-left: 20px;
padding-left: 10px;
padding-right: 0;
}

.yrthen-prec {
padding-left: 20px;
padding-left: 10px;
padding-right: 0;
}

.yrthen-wind {
padding-left: 10px;
padding-right: 0;
line-height: 0.9rem;
}

.yrthen-wind-det {
line-height: 1rem;
}

.yrthen-timecell {
text-align: center;
}
Expand Down
77 changes: 70 additions & 7 deletions MMM-YrThen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Module.register('MMM-YrThen', {
windGust: false,
windUnit: '',
windSize: 'yrthen-xxsmall',
windText: true,
windTextNumber: true,
windTextNewLine: true,
title: 'Værmelding for Skrubblivegen',
header: false,
size: "small"
Expand All @@ -30,6 +33,7 @@ Module.register('MMM-YrThen', {
en: "translations/en.json",
sv: "translations/sv.json",
fi: "translations/fi.json",
es: "translations/es.json",
}
},

Expand Down Expand Up @@ -210,9 +214,20 @@ Module.register('MMM-YrThen', {
forecastCell.innerHTML += precValue;
}
if(this.config.windShow){
var windValue = '<br><span class="dimmed ' + this.config.windSize + '">';
windValue += newData.wind.speed + ' ';
if(this.config.windUnit != false) windValue += this.config.windUnit + ' ';
var windValue = '<br><span class="dimmed yrthen-wind-det ' + this.config.windSize + '">';
if(this.config.windText){
windValue += this.calculateWindSpeed(newData.wind.speed);
if(this.config.windTextNumber){
windValue += ' ';
if(this.config.windTextNewLine) windValue += '<br>';
windValue += newData.wind.speed;
}
windValue += ' ';
}
else{
windValue += newData.wind.speed + ' ';
if(this.config.windUnit != false) windValue += this.config.windUnit + ' ';
}
windValue += this.translate(this.calculateWindDirection(newData.wind.direction));
if(this.config.windGust && newData.wind.gust) windValue += ' (' + newData.wind.gust + ' ' + this.translate("gust") + ') ';
windValue += '</span>';
Expand Down Expand Up @@ -254,20 +269,49 @@ Module.register('MMM-YrThen', {
iconCell.appendChild(icon);

var maxTempCell = document.createElement("td");
if(this.config.roundTemp) maxTempCell.innerHTML = this.round(newData.temperature.value, 0);
else maxTempCell.innerHTML = this.round(newData.temperature.value, 1);
if(this.config.roundTemp){
tempValue = this.round(newData.temperature.value, 0);
maxValue = this.round(newData.temperature.max, 0);
minValue = this.round(newData.temperature.min, 0);
}
else{
tempValue = this.round(newData.temperature.value, 1);
maxValue = this.round(newData.temperature.max, 1);
minValue = this.round(newData.temperature.min, 1);
}

if(this.config.showMaxMin){
if(newData.temperature.min && newData.temperature.max) maxTempCell.innerHTML = minValue + '˚' + this.config.maxMinSeparator + maxValue + '˚';
else maxTempCell.innerHTML = tempValue;
}
else{
maxTempCell.innerHTML = tempValue;
}
maxTempCell.className = "align-right bright yrthen-temp " + this.config.size;
row.appendChild(maxTempCell);

var minTempCell = document.createElement("td");
minTempCell.innerHTML = this.round(newData.precipitation.value, 1);
minTempCell.className = "align-right yrthen-prec dimmed";
row.appendChild(minTempCell);

if(this.config.windShow){
windValue = '';
var windCell = document.createElement("td");
windCell.className = "align-left yrthen-prec dimmed " + this.config.windSize;
windValue += newData.wind.speed + ' ';
windCell.className = "align-left yrthen-wind dimmed " + this.config.windSize;
if(this.config.windText){
windValue += this.calculateWindSpeed(newData.wind.speed) + ' ';
if(this.config.windTextNumber){
if(this.config.windTextNewLine) windValue += '<br>';
windValue += newData.wind.speed;
if(this.config.windUnit) windValue += ' ' + this.config.windUnit;
windValue += ' ';
}
}
else{
windValue += newData.wind.speed + ' ';
if(this.config.windUnit != false) windValue += this.config.windUnit + ' ';
}
if(this.config.windUnit != false) windValue += this.config.windUnit + ' ';
windValue += this.translate(this.calculateWindDirection(newData.wind.direction));
if(this.config.windGust && newData.wind.gust) windValue += ' (' + newData.wind.gust + ' ' + this.translate("gust") + ') ';
Expand Down Expand Up @@ -341,6 +385,25 @@ Module.register('MMM-YrThen', {
if(d > 326.25 && d < 348.75) return 'NNW';
},

calculateWindSpeed: function(s){
if(!s) return '';
var w = '';
if(s <= 0.2) return 'windCalm';
if(s > 0.2 && s <= 1.5) w = 'windLightAir';
if(s > 1.5 && s <= 3.3) w = 'windLightBreeze';
if(s > 3.3 && s <= 5.4) w = 'windGentleBreeze';
if(s > 5.4 && s <= 7.9) w = 'windModerateBreeze';
if(s > 7.9 && s <= 10.7) w = 'windFreshBreeze';
if(s > 10.7 && s <= 13.8) w = 'windStrongBreeze';
if(s > 13.8 && s <= 17.1) w = 'windModerateGale';
if(s > 17.1 && s <= 20.7) w = 'windGale';
if(s > 20.7 && s <= 24.4) w = 'windStrongGale';
if(s > 24.4 && s <= 28.4) w = 'windStorm';
if(s > 28.4 && s <= 32.6) w = 'windViolentStorm';
if(s > 32.6) w = 'windHurricaneForce';
return this.translate(w);
},

socketNotificationReceived: function(notification, payload) {
if(notification === 'YRTHEN_FORECAST_DATA') {
Log.info('Got forecast');
Expand Down
78 changes: 47 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,101 +38,117 @@ Find your location using the search form at <a href="https://www.yr.no/nb/liste/
</tr>
<tr>
<td>location</td>
<td>The unique Id found in the Url of any location on <a href="https://www.yr.no/nb/liste/dag/1-2820936/Norge/Nord-Trøndelag/Steinkjer/Skrubblivegen">Yr.no</a>. Default location is Skrubblivegen in Steinkjer, Norway.</td>
<td>1-2296935</td>
<td>The unique Id found in the Url of any location on <a href="https://www.yr.no/nb/liste/dag/1-2820936/Norge/Nord-Trøndelag/Steinkjer/Skrubblivegen">Yr.no</a>. Default location is Skrubblivegen in Steinkjer, Norway. (String)</td>
<td>"1-2296935"</td>
</tr>
<tr>
<td>updateInterval</td>
<td>How often to get new data. Defaults to 1 hour, as the weather forecast doesn't really change too often.</td>
<td>How often to get new data. Defaults to 1 hour, as the weather forecast doesn't really change too often. (Integer)</td>
<td>3600000</td>
</tr>
<tr>
<td>initialLoadDelay</td>
<td>Dunno why, but thought it was a good idea to give it some rest before we start. Defaults to 1 sec.</td>
<td>Dunno why, but thought it was a good idea to give it some rest before we start. Defaults to 1 sec. (Integer)</td>
<td>1000</td>
</tr>
<tr>
<td>numDays</td>
<td>Number of days to show.</td>
<td>Number of days to show. (Integer)</td>
<td>7</td>
</tr>
<tr>
<td>showAll</td>
<td>Show all four periods of each day or not.</td>
<td>Show all four periods of each day or not. (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>details</td>
<td>If showAll is false, show detailed weather forecast? If false, it only shows the forecast around midday (12.00). If true, it shows detailed forecast numDetails times. (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>showPrecipitation</td>
<td>If showAll is true, show precipitation as well?</td>
<td>If showAll is true, show precipitation as well? (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>detailedPrec</td>
<td>Show detailed precipitation? (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>showMaxMin</td>
<td>If showAll is true, show maximum and minimum temperature?</td>
<td>If showAll is true, show maximum and minimum temperature? (Boolean)</td>
<td>false</td>
</tr>
<tr>
<td>maxMinSeparator</td>
<td>If showMaxMin is true, which separator should be used?</td>
<td>-</td>
<tr>
<td>details</td>
<td>If showAll is false, show detailed weather forecast? If false, it only shows the forecast around midday (12.00). If true, it shows detailed forecast numDetails times.</td>
<td>true</td>
<td>If showMaxMin is true, which separator should be used? (String)</td>
<td>"-"</td>
</tr>
<tr>
<td>numDetails</td>
<td>How many detailed forecasts to show. Default is next two periods. Only applies if showAll is false and details is true.</td>
<td>How many detailed forecasts to show. Default is next two periods. Only applies if showAll is false and details is true. (Integer)</td>
<td>2</td>
</tr>
<tr>
<td>detailedPrec</td>
<td>Show detailed precipitation?</td>
<td>true</td>
</tr>
<tr>
<td>roundTemp</td>
<td>Round temperature to zero decimals.</td>
<td>Round temperature to zero decimals. (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>roundPrec</td>
<td>Round precipitation to zero decimals.</td>
<td>Round precipitation to zero decimals. (Boolean)</td>
<td>false</td>
</tr>
<tr>
<td>title</td>
<td>Title for the module, if shown.</td>
<td>Værmelding for Skrubblivegen</td>
<td>Content of the header of the module – the title. If shown, that is. (String)</td>
<td>"Værmelding for Skrubblivegen"</td>
</tr>
<tr>
<td>header</td>
<td>Show header or not. Contents of header is title.</td>
<td>Show header or not. Contents of header is title. (Boolean)</td>
<td>false</td>
</tr>
<tr>
<td>size</td>
<td>The size of the text. One of the CSS classes defined in main.css of MagicMirror2: "xsmall", "small", "medium", "large", "xlarge"</td>
<td>The size of the text. One of the CSS classes defined in main.css of MagicMirror2: "xsmall", "small", "medium", "large", "xlarge". (String)</td>
<td>"small"</td>
</tr>
<tr>
<td>windShow</td>
<td>Show wind forecast or not, true or false.</td>
<td>Show wind forecast or not? (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>windGust</td>
<td>Show wind gust information or not, true or false.</td>
<td>Show wind gust information or not. (Boolean)</td>
<td>false</td>
</tr>
<tr>
<td>windUnit</td>
<td>If set, it shows as the unit of the wind. Default could be m/s, but defalt is nothing at all. (string)</td>
<td>If set, it shows as the unit of the wind. Default could be "m/s", but I like it at nothing at all. (string)</td>
<td>""</td>
</tr>
<tr>
<td>windSize</td>
<td>Size of wind forecast. One of the CSS classes defined in main.css of MagicMirror2: "xsmall", "small", "medium", "large", "xlarge" – or the custom "yrthen-xxsmall" for extra, extra small.</td>
<td>Size of wind forecast. One of the CSS classes defined in main.css of MagicMirror2: "xsmall", "small", "medium", "large", "xlarge" – or the custom "yrthen-xxsmall" for extra, extra small. (String)</td>
<td>"yrthen-xxsmall"</td>
</tr>
</table>
<tr>
<td>windText</td>
<td>Show wind speed in text. (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>windTextNumber</td>
<td>Show wind speed in number after showing it in text. (Boolean)</td>
<td>true</td>
</tr>
<tr>
<td>windTextNewLine</td>
<td>If windText and windTextNumber both are true, show windTextNumber on a new line? (Boolean)</td>
<td>true</td>
</tr>
</table>
Binary file modified images/newShot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"morning": "Morning",
"afternoon": "Afternoon",
"evening": "Evening",
"gust": "gusts"
"gust": "gusts",
"windCalm": "Calm",
"windLightAir": "Light air",
"windLightBreeze": "Light breeze",
"windGentleBreeze": "Gentle breeze",
"windModerateBreeze": "Moderate breeze",
"windFreshBreeze": "Fresh breeze",
"windStrongBreeze": "Strong breeze",
"windModerateGale": "Moderate gale",
"windGale": "Gale",
"windStrongGale": "Strong gale",
"windStorm": "Storm",
"windViolentStorm": "Violent storm",
"windHurricaneForce": "Hurricane force"
}
15 changes: 14 additions & 1 deletion translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"morning": "Mañana",
"afternoon": "Tarde",
"evening": "Velada",
"gust": "ráfaga"
"gust": "ráfaga",
"windCalm": "Calma",
"windLightAir": "Ventolina",
"windLightBreeze": "Brisa muy débil",
"windGentleBreeze": "Brisa ligera",
"windModerateBreeze": "Brisa moderada",
"windFreshBreeze": "Brisa fresca",
"windStrongBreeze": "Brisa fuerte",
"windModerateGale": "Viento fuerte",
"windGale": "Viento duro",
"windStrongGale": "Muy duro",
"windStorm": "Temporal",
"windViolentStorm": "Borrasca",
"windHurricaneForce": "Huracán"
}
15 changes: 14 additions & 1 deletion translations/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"morning": "Aamulla",
"afternoon": "Iltapäivällä",
"evening": "Illalla",
"gust": "Puuska"
"gust": "Puuska",
"windCalm": "Tyyni",
"windLightAir": "Hiljainen tuuli",
"windLightBreeze": "Heikko tuuli",
"windGentleBreeze": "Heikonlainen tuuli",
"windModerateBreeze": "Kohtalainen tuuli",
"windFreshBreeze": "Navakka tuuli",
"windStrongBreeze": "Kova tuuli",
"windModerateGale": "Luja tuuli",
"windGale": "Myrskyinen tuuli",
"windStrongGale": "Myrsky",
"windStorm": "Kova myrsky",
"windViolentStorm": "Ankara myrsky",
"windHurricaneForce": "Hirmumyrsky"
}
15 changes: 14 additions & 1 deletion translations/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"morning": "Form.",
"afternoon": "Etterm.",
"evening": "Kveld",
"gust": "kast"
"gust": "kast",
"windCalm": "Stille",
"windLightAir": "Flau vind",
"windLightBreeze": "Svak vind",
"windGentleBreeze": "Lett bris",
"windModerateBreeze": "Laber bris",
"windFreshBreeze": "Frisk bris",
"windStrongBreeze": "Liten kuling",
"windModerateGale": "Stiv kuling",
"windGale": "Sterk kuling",
"windStrongGale": "Liten storm",
"windStorm": "Full storm",
"windViolentStorm": "Sterk storm",
"windHurricaneForce": "Orkan"
}
Loading

0 comments on commit af674d6

Please sign in to comment.