Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustments needed to make this module work (as of Sept, 2022) #3

Open
kevsfastz opened this issue Sep 6, 2022 · 3 comments
Open

Comments

@kevsfastz
Copy link

Hi all,

For anyone like myself looking at this module, I was able to get it working as I wanted by making the following adjustments:

In MMM-WindyV2.js, I updated the following line:
From:
56: 'https://unpkg.com/leaflet@0.7.7/dist/leaflet.js',

To:
56: 'https://unpkg.com/leaflet@1.4.0/dist/leaflet.js',

This got the module working alone, but I wanted to use windy with "radar" so I added the "overlay" line on 130:
/////////////////////////////////////////////////////////////////////////////////////
scheduleInit: function(delay) {
setTimeout(() => {
const options = {
graticule: false,
key: this.config.apiKey,
lat: this.config.latitude,
lon: this.config.longitude,
animate: false,
zoom: this.config.zoomLevel,
minZoom: 3,
maxZoom: 18,
overlay: 'radar', //ADDED THIS LINE TO FORCE RADAR

Finally, I wanted the radar to automatically 'play', as well as remove all the other unnecessary buttons/logos/ etc. Therefore, i made the below adjustments to the MAIN.JS of MM at the very end:

// Add polyfill for Object.assign.
if (typeof Object.assign !== "function") {
(function () {
Object.assign = function (target) {
"use strict";
if (target === undefined || target === null) {
throw new TypeError("Cannot convert undefined or null to object");
}
const output = Object(target);
for (let index = 1; index < arguments.length; index++) {
const source = arguments[index];
if (source !== undefined && source !== null) {
for (const nextKey in source) {
if (source.hasOwnProperty(nextKey)) {
output[nextKey] = source[nextKey];
}
}
}
}
return output;
};
})();
}
///////BELOW WILL AUTOMATICALLY CLICK THE PLAY BUTTON///////
setTimeout(function() {
document.evaluate(
'//[@[starts-with(name(), "data-ref")]="play"]',
document,
null,
XPathResult.ANY_TYPE,
null
).iterateNext().click()
}, 2000);
///////BELOW WILL HIDE LOADING BARS AND LOGOS///////
setTimeout(function() {
document.getElementById("radar-wrapper").style.display = "none";
document.getElementById("progress-bar").style.display = "none";
document.getElementById("mobile-ovr-select").style.display = "none";
document.getElementById("logo").style.display = "none";
}, 3000);

//////////////////////////////////////////////////////////////////
MM.init();

With these changes above, I now have a radar loop that will display as the background of my magic mirror. Currently, I have a cronjob to restart MM every 6 hours as the radar play will eventually expire. I'm sure there is a better way to achieve this but I haven't explored any other options yet. Lastly, here is an example of my config.js for reference.

{
disabled: false,
module: "MMM-WindyV2",
position: 'fullscreen_above', // this must be set to 'fullscreen_above'
config: {
apiKey: 'PLACE YOUR API KEY HERE!!!!', // insert your free or paid API key here
initLoadDelay: 50, // optional, default is 50 milliseconds
latitude: 69.123, // example: 69.123
longitude: 17.123, // example: 17.123
zoomLevel: 9, // set your preferred zoom level
showLayer: 'radar', // wind, rain, clouds, temp, pressure, currents, waves
rotateLayers: false, // set to true to rotate layers
layersToRotate: ['radar','radar'], // layers to rotate
delayRotate: 5000, // delay between rotated layers, in milliseconds
wMinZoom: 3, // set minimum zoom level for WindyV2
wMaxZoom: 17, // set maximum zoom level for WindyV2
windyMetric: 'm/s', // 'kt', 'bft', 'm/s', 'km/h' and 'mph'
updateTimer: 60 * 60 * 1000 * 6, // update per 6 hours
retainZoom: true // retain zoomlevel between changing overlays
}
},

I hope this helps someone looking to achieve the same goal as I was!

@thatguyinoz
Copy link

Hi @kevsfastz
this is just what I've been trying to do. :-)
however i get a few errors with the code you posted.

the autoplay throws
Uncaught DOMException: Failed to execute 'evaluate' on 'Document': The string '//[@[starts-with(name(), "data-ref")]="play"]' is not a valid XPath expression.
in the console
Sadly Im way out of my depth with this.

@kevsfastz
Copy link
Author

kevsfastz commented Apr 25, 2023

Hi @thatguyinoz
I know this reply is very late, but in case you are still looking for a solution or for anyone else, you are receiving this error because of the formatting when copy/paste from here to your main.js. You need to make sure your indentation is the same as in my screen shot below between lines 619 - 623

I should also mention I have only tested this in Chrome.

image

@thatguyinoz
Copy link

cheers for that, I'll give it a go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants