]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Fix openweather service
authorBastien Wirtz <bastien.wirtz@gmail.com>
Sun, 30 Oct 2022 13:48:45 +0000 (14:48 +0100)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Sun, 30 Oct 2022 13:48:45 +0000 (14:48 +0100)
dummy-data/openweather/weather [new file with mode: 0644]
public/assets/config-demo.yml.dist
src/components/services/OpenWeather.vue
src/components/services/Ping.vue

diff --git a/dummy-data/openweather/weather b/dummy-data/openweather/weather
new file mode 100644 (file)
index 0000000..80245ef
--- /dev/null
@@ -0,0 +1,46 @@
+{
+    "coord": {
+      "lon": 4.5833,
+      "lat": 45.75
+    },
+    "weather": [
+      {
+        "id": 804,
+        "main": "Clouds",
+        "description": "overcast clouds",
+        "icon": "04d"
+      }
+    ],
+    "base": "stations",
+    "main": {
+      "temp": 23,
+      "feels_like": 22.3,
+      "temp_min": 21.75,
+      "temp_max": 25.03,
+      "pressure": 1019,
+      "humidity": 36,
+      "sea_level": 1019,
+      "grnd_level": 957
+    },
+    "visibility": 10000,
+    "wind": {
+      "speed": 2.29,
+      "deg": 174,
+      "gust": 6.22
+    },
+    "clouds": {
+      "all": 97
+    },
+    "dt": 1667136939,
+    "sys": {
+      "type": 2,
+      "id": 2005747,
+      "country": "FR",
+      "sunrise": 1667110705,
+      "sunset": 1667147524
+    },
+    "timezone": 3600,
+    "id": 2996943,
+    "name": "Arrondissement de Lyon",
+    "cod": 200
+  }
\ No newline at end of file
index 43188fb8c9a8b0786ff0653a0042bfc660186790..4d088ccc9b831756593932cf0023415daf685c95 100644 (file)
@@ -100,6 +100,12 @@ services:
         keywords: "demo"
         url: "#"
         target: "_blank" 
+      - name: "Weather"
+        location: "Lyon"
+        apikey: "xxxxxxxxxxxx" # insert your own API key here. Request one from https://openweathermap.org/api.
+        units: "metric"
+        endpoint: "https://homer-demo-content.netlify.app/openweather/weather"
+        type: "OpenWeather"
   - name: "interesting links"
     icon: "fas fa-solid fa-arrow-up-right-from-square"
     items:
index 31698663dd87c0ae7715f120af1177ba4ff3ffe9..649e8e5a5df67390c1377729bb3d36c2ba2878a9 100644 (file)
@@ -23,7 +23,7 @@
                 <p class="title is-4">{{ name }}</p>
                 <p class="subtitle is-6">
                   <span>
-                    {{ temp | tempSuffix(this.item.units) }}
+                    {{ temperature }}
                   </span>
                   <span class="location-time">
                     {{ locationTime }}
@@ -68,15 +68,13 @@ export default {
       }
       return `${this.temp} ${unit}`;
     },
-  },
-  created() {
-    this.fetchWeather();
-  },
-  computed: {
     locationTime: function () {
       return this.calcTime(this.timezoneOffset);
     },
   },
+  created() {
+    this.fetchWeather();
+  },
   methods: {
     fetchWeather: async function () {
       let locationQuery;
@@ -89,7 +87,11 @@ export default {
       }
 
       const apiKey = this.item.apikey || this.item.apiKey;
-      const url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${apiKey}&units=${this.item.units}`;
+
+      let url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${apiKey}&units=${this.item.units}`;
+      if (this.item.endpoint) {
+        url = this.item.endpoint;
+      }
       fetch(url)
         .then((response) => {
           if (!response.ok) {
index 07bc0537fc8bfda907c02363f372d53601a94f63..e2db050e83f5d1440a95275eb934e36bbeee92c6 100644 (file)
@@ -29,9 +29,12 @@ export default {
   },
   methods: {
     fetchStatus: async function () {
-      const method = typeof this.item.method === 'string' ? this.item.method.toUpperCase() : 'HEAD';
+      const method =
+        typeof this.item.method === "string"
+          ? this.item.method.toUpperCase()
+          : "HEAD";
 
-      if (!['GET', 'HEAD', 'OPTION'].includes(method)) {
+      if (!["GET", "HEAD", "OPTION"].includes(method)) {
         console.error(`Ping: ${method} is not a supported HTTP method`);
         return;
       }