mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 12:12:20 +00:00
fix moment, add unit filter
This commit is contained in:
parent
07d35a8513
commit
91ddc00f7e
@ -42,14 +42,10 @@
|
|||||||
<div class="large light">
|
<div class="large light">
|
||||||
<span class="wi weathericon wi-{{current.weatherType}}"></span>
|
<span class="wi weathericon wi-{{current.weatherType}}"></span>
|
||||||
<span class="bright">
|
<span class="bright">
|
||||||
{{current.temperature | round(0 if config.roundTemp else 1)}}°{% if config.degreeLabel %}
|
{{current.temperature | round(0 if config.roundTemp else 1) | unit("temperature")}}
|
||||||
{% if config.units == "metric" %}C{% endif %}
|
|
||||||
{% if config.units == "imperial" %}F{% endif %}
|
|
||||||
{% if config.units == "default" %}K{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<!-- Unclomment the line below to see the contents of the `current` object. -->
|
<!-- Unclomment the line below to see the contents of the `current` object. -->
|
||||||
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{current | dump}}</div> -->
|
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{current | dump}}</div> -->
|
||||||
|
@ -16,8 +16,6 @@ Module.register("weather",{
|
|||||||
roundTemp: false,
|
roundTemp: false,
|
||||||
type: "current", //current, forecast
|
type: "current", //current, forecast
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
location: false,
|
location: false,
|
||||||
locationID: false,
|
locationID: false,
|
||||||
appid: "",
|
appid: "",
|
||||||
@ -61,12 +59,13 @@ Module.register("weather",{
|
|||||||
// Return the scripts that are nessecery for the weather module.
|
// Return the scripts that are nessecery for the weather module.
|
||||||
getScripts: function () {
|
getScripts: function () {
|
||||||
var scripts = [
|
var scripts = [
|
||||||
|
"moment.js",
|
||||||
"weatherprovider.js",
|
"weatherprovider.js",
|
||||||
"weatherobject.js"
|
"weatherobject.js"
|
||||||
];
|
];
|
||||||
|
|
||||||
// Add the provider file to the required scripts.
|
// Add the provider file to the required scripts.
|
||||||
scripts.push(this.file("providers/" + this.config.weatherProvider.toLowerCase() + ".js"))
|
scripts.push(this.file("providers/" + this.config.weatherProvider.toLowerCase() + ".js"));
|
||||||
|
|
||||||
return scripts
|
return scripts
|
||||||
},
|
},
|
||||||
@ -74,16 +73,16 @@ Module.register("weather",{
|
|||||||
// Start the weather module.
|
// Start the weather module.
|
||||||
start: function () {
|
start: function () {
|
||||||
// Initialize the weather provider.
|
// Initialize the weather provider.
|
||||||
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this)
|
this.weatherProvider = WeatherProvider.initialize(this.config.weatherProvider, this);
|
||||||
|
|
||||||
// Let the weather provider know we are starting.
|
// Let the weather provider know we are starting.
|
||||||
this.weatherProvider.start()
|
this.weatherProvider.start();
|
||||||
|
|
||||||
// Add custom filters
|
// Add custom filters
|
||||||
this.addFilters()
|
this.addFilters();
|
||||||
|
|
||||||
// Schedule the first update.
|
// Schedule the first update.
|
||||||
this.scheduleUpdate(0)
|
this.scheduleUpdate(0);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Select the template depending on the display type.
|
// Select the template depending on the display type.
|
||||||
@ -102,10 +101,9 @@ Module.register("weather",{
|
|||||||
|
|
||||||
// What to do when the weather provider has new information available?
|
// What to do when the weather provider has new information available?
|
||||||
updateAvailable: function() {
|
updateAvailable: function() {
|
||||||
Log.log("New weather information available.")
|
Log.log("New weather information available.");
|
||||||
console.info(this.weatherProvider.currentWeather())
|
this.updateDom(0);
|
||||||
this.updateDom(0)
|
this.scheduleUpdate(5000);
|
||||||
this.scheduleUpdate()
|
|
||||||
},
|
},
|
||||||
|
|
||||||
scheduleUpdate: function(delay = null) {
|
scheduleUpdate: function(delay = null) {
|
||||||
@ -117,34 +115,50 @@ Module.register("weather",{
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
switch (this.config.type) {
|
switch (this.config.type) {
|
||||||
case "forecast":
|
case "forecast":
|
||||||
this.weatherProvider.fetchWeatherForecast()
|
this.weatherProvider.fetchWeatherForecast();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
case "current":
|
case "current":
|
||||||
this.weatherProvider.fetchCurrentWeather()
|
this.weatherProvider.fetchCurrentWeather();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}, nextLoad);
|
}, nextLoad);
|
||||||
},
|
},
|
||||||
|
|
||||||
addFilters() {
|
addFilters() {
|
||||||
var self = this
|
|
||||||
this.nunjucksEnvironment().addFilter("formatTime", function(date) {
|
this.nunjucksEnvironment().addFilter("formatTime", function(date) {
|
||||||
date = moment(date)
|
date = moment(date);
|
||||||
|
|
||||||
if (self.config.timeFormat !== 24) {
|
if (this.config.timeFormat !== 24) {
|
||||||
if (self.config.showPeriod) {
|
if (this.config.showPeriod) {
|
||||||
if (self.config.showPeriodUpper) {
|
if (this.config.showPeriodUpper) {
|
||||||
return date.format("h:mm A")
|
return date.format("h:mm A");
|
||||||
} else {
|
} else {
|
||||||
return date.format("h:mm a")
|
return date.format("h:mm a");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return date.format("h:mm")
|
return date.format("h:mm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return date.format("HH:mm")
|
return date.format("HH:mm");
|
||||||
});
|
}.bind(this));
|
||||||
|
|
||||||
|
this.nunjucksEnvironment().addFilter("unit", function (value, type) {
|
||||||
|
if (type === "temperature") {
|
||||||
|
value += "°";
|
||||||
|
if (this.config.scale || this.config.degreeLabel) {
|
||||||
|
if (this.config.units === "metric") {
|
||||||
|
value += "C";
|
||||||
|
} else if (this.config.units === "imperial") {
|
||||||
|
value += "F";
|
||||||
|
} else {
|
||||||
|
value += "K";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}.bind(this));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user