﻿<?xml version="1.0" encoding="utf-8"?>
<EXOconfigData format="Rwav" version="2019.4.100.249">
  <Object type="View">
    <Attribute name="Name">WeatherForecasts</Attribute>
    <Attribute name="Width">213</Attribute>
    <Attribute name="Height">128</Attribute>
    <Attribute name="Zoom">100%</Attribute>
    <Attribute name="ScaleValue">1</Attribute>
    <Attribute name="OnOpen">this.view.call('.getForecast', {}).then((result) =&gt; {
    
    if (result === undefined) {
      console.error('Failed to get forecast');
      return;
    }
       
    this.view.InOneHour.value(`${result.inOneHour}°C`);
    this.view.InTwoHours.value(`${result.inTwoHours}°C`);
    this.view.InThreeHours.value(`${result.inThreeHours}°C`);
});</Attribute>
    <Attribute name="ServerSideFunctionRPC">accounts.%account%.services.ssf.execute</Attribute>
    <Attribute name="ServerSideJS">return {
    getForecast: async (args, callInfo) =&gt; {        

        // The centre of Stockholm (Sweden) is at latitude 59.3293° N and longitude 18.0686° E
        const url =
          "https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/18.0686/lat/59.3293/data.json";
        const response = await callInfo.context.fetch(url);
        
        // Convert the response to an object
        const forecast = await response.json();
        
        const inOneHour = forecast.timeSeries[0].parameters[10].values[0];
        const inTwoHours = forecast.timeSeries[1].parameters[10].values[0];
        const inThreeHours = forecast.timeSeries[2].parameters[10].values[0];
        
        return { inOneHour, inTwoHours, inThreeHours };
    }
}</Attribute>
    <Object type="ArgumentsFolder">
      <Attribute name="Name">Arguments</Attribute>
      <Attribute name="Comment">This folder contains all arguments for the view. The arguments can be sent to the view when it is used in run-time.</Attribute>
    </Object>
    <Object type="ElementsFolder">
      <Attribute name="Name">Elements</Attribute>
      <Attribute name="Comment">This folder contains all visual elements for the view.</Attribute>
      <Object type="Text">
        <Attribute name="Name">InOneHour</Attribute>
        <Attribute name="Left">115</Attribute>
        <Attribute name="Top">20</Attribute>
      </Object>
      <Object type="Text">
        <Attribute name="Name">InTwoHours</Attribute>
        <Attribute name="Left">115</Attribute>
        <Attribute name="Top">55</Attribute>
      </Object>
      <Object type="Text">
        <Attribute name="Name">InThreeHours</Attribute>
        <Attribute name="Left">115</Attribute>
        <Attribute name="Top">90</Attribute>
      </Object>
    </Object>
  </Object>
</EXOconfigData>