Repository: Ingenjorsarbete-For-Klimatet/ifk-smhi

Issue:
Mesan api updated
# Description

SMHI has updated their Mesan API, see [here](https://www.smhi.se/data/om-smhis-data/uppdateringar-oppna-data/uppdateringar-i-smhis-oppna-data/2024-01-18-ny-version-av-api-for-meteorologiska-analyser-mesan). That is, our code isn't working, but I don't really understand what has changed.

Discussion:

Solution patch:
diff --git a/pyproject.toml b/pyproject.toml
index e815552..4e8129a 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "ifk-smhi"
-version = "0.2.0"
+version = "0.3.0"
 description = "Inspect and get SMHI data."
 license = { text = "MIT" }
 readme = "README.md"
diff --git a/src/smhi/constants.py b/src/smhi/constants.py
index 6a438ec..da0d41c 100644
--- a/src/smhi/constants.py
+++ b/src/smhi/constants.py
@@ -6,6 +6,7 @@
 from posixpath import join as urljoin
 
 import arrow
+
 from smhi.models.strang_model import StrangParameter
 
 logging.basicConfig(level=logging.INFO, format="%(message)s")
diff --git a/src/smhi/mesan.py b/src/smhi/mesan.py
index 9eef3fc..ce7267e 100644
--- a/src/smhi/mesan.py
+++ b/src/smhi/mesan.py
@@ -8,6 +8,7 @@
 import arrow
 import pandas as pd
 from requests.structures import CaseInsensitiveDict
+
 from smhi.constants import (
     MESAN_LEVELS_UNIT,
     MESAN_PARAMETER_DESCRIPTIONS,
diff --git a/src/smhi/metfcts.py b/src/smhi/metfcts.py
index 80f041d..80a9b8e 100644
--- a/src/smhi/metfcts.py
+++ b/src/smhi/metfcts.py
@@ -3,6 +3,7 @@
 from typing import Dict
 
 import arrow
+
 from smhi.constants import METFCTS_PARAMETER_DESCRIPTIONS, METFCTS_URL
 from smhi.mesan import Mesan
 from smhi.models.metfcts_model import (
diff --git a/src/smhi/metobs.py b/src/smhi/metobs.py
index 97df33f..beab4ee 100644
--- a/src/smhi/metobs.py
+++ b/src/smhi/metobs.py
@@ -7,6 +7,7 @@
 
 import pandas as pd
 from requests.structures import CaseInsensitiveDict
+
 from smhi.constants import METOBS_AVAILABLE_PERIODS
 from smhi.models.metobs_model import (
     MetobsCategoryModel,
diff --git a/src/smhi/models/mesan_model.py b/src/smhi/models/mesan_model.py
index 7f710e2..96fd217 100644
--- a/src/smhi/models/mesan_model.py
+++ b/src/smhi/models/mesan_model.py
@@ -40,7 +40,8 @@ class MesanGeoMultiPoint(BaseModel):
 
 class MesanParameterItem(BaseModel):
     name: str
-    key: str
+    short_name: str = Field(..., alias="shortName")
+    description: str
     level_type: str = Field(..., alias="levelType")
     level: int
     unit: str
diff --git a/src/smhi/models/metobs_model.py b/src/smhi/models/metobs_model.py
index 4743e59..531edd1 100644
--- a/src/smhi/models/metobs_model.py
+++ b/src/smhi/models/metobs_model.py
@@ -4,6 +4,7 @@
 
 import pandas as pd
 from pydantic import BaseModel, ConfigDict, Field, field_validator
+
 from smhi.constants import METOBS_AVAILABLE_PERIODS
 
 
diff --git a/src/smhi/smhi.py b/src/smhi/smhi.py
index 6b812d1..2db9531 100644
--- a/src/smhi/smhi.py
+++ b/src/smhi/smhi.py
@@ -8,6 +8,7 @@
 from geopy import distance
 from geopy.extra.rate_limiter import RateLimiter
 from geopy.geocoders import Nominatim
+
 from smhi.metobs import Data, Parameters, Periods, Stations
 from smhi.models.metobs_model import MetobsLinks
 
diff --git a/src/smhi/strang.py b/src/smhi/strang.py
index e7cd213..ac1377a 100644
--- a/src/smhi/strang.py
+++ b/src/smhi/strang.py
@@ -13,6 +13,7 @@
 import arrow
 import pandas as pd
 from requests.structures import CaseInsensitiveDict
+
 from smhi.constants import (
     STRANG_MULTIPOINT_URL,
     STRANG_PARAMETERS,
diff --git a/src/smhi/utils.py b/src/smhi/utils.py
index a030242..b93893c 100644
--- a/src/smhi/utils.py
+++ b/src/smhi/utils.py
@@ -6,6 +6,7 @@
 
 import arrow
 import requests
+
 from smhi.constants import OUT_OF_BOUNDS, STATUS_OK
 
 logger = logging.getLogger(__name__)


Test patch:
diff --git a/tests/integration/test_integration_mesan.py b/tests/integration/test_integration_mesan.py
index 6bdd3b2..d1a0ab5 100644
--- a/tests/integration/test_integration_mesan.py
+++ b/tests/integration/test_integration_mesan.py
@@ -4,6 +4,7 @@
 
 import arrow
 import pytest
+
 from smhi.constants import MESAN_PARAMETER_DESCRIPTIONS
 from smhi.mesan import Mesan
 
diff --git a/tests/integration/test_integration_metobs.py b/tests/integration/test_integration_metobs.py
index 2b4ef3c..bf7aa2a 100644
--- a/tests/integration/test_integration_metobs.py
+++ b/tests/integration/test_integration_metobs.py
@@ -5,6 +5,7 @@
 
 import pandas as pd
 import pytest
+
 from smhi.metobs import Data, Parameters, Periods, Stations
 from smhi.models.metobs_model import MetobsVersionItem
 
diff --git a/tests/integration/test_integration_smhi.py b/tests/integration/test_integration_smhi.py
index 9b92a91..6288dbe 100644
--- a/tests/integration/test_integration_smhi.py
+++ b/tests/integration/test_integration_smhi.py
@@ -3,6 +3,7 @@
 import time
 
 import pytest
+
 from smhi.smhi import SMHI
 
 
diff --git a/tests/integration/test_integration_strang.py b/tests/integration/test_integration_strang.py
index e37662d..f2d13a0 100644
--- a/tests/integration/test_integration_strang.py
+++ b/tests/integration/test_integration_strang.py
@@ -4,6 +4,7 @@
 
 import pandas as pd
 import pytest
+
 from smhi.strang import Strang
 
 
diff --git a/tests/unit/test_unit_mesan.py b/tests/unit/test_unit_mesan.py
index 2c7b442..6fcae7c 100644
--- a/tests/unit/test_unit_mesan.py
+++ b/tests/unit/test_unit_mesan.py
@@ -6,11 +6,12 @@
 import arrow
 import pandas as pd
 import pytest
+from utils import get_response
+
 from smhi.constants import MESAN_LEVELS_UNIT, MESAN_PARAMETER_DESCRIPTIONS
 from smhi.mesan import Mesan
 from smhi.models.mesan_model import MesanGeometry, MesanParameter, MesanParameterItem
 from smhi.utils import format_datetime
-from utils import get_response
 
 BASE_URL = (
     "https://opendata-download-metanalys.smhi.se/" + "api/category/mesan2g/version/1/"
@@ -23,7 +24,8 @@
     parameter=[
         MesanParameterItem(
             name="t",
-            key="t_hl_2",
+            shortName="t",
+            description="Temperature",
             levelType="hl",
             level=2,
             unit="Cel",
@@ -31,7 +33,8 @@
         ),
         MesanParameterItem(
             name="gust",
-            key="gust_hl_10",
+            shortName="gust",
+            description="Wind gusts",
             levelType="hl",
             level=10,
             unit="m/s",
diff --git a/tests/unit/test_unit_metfcts.py b/tests/unit/test_unit_metfcts.py
index fa5fc0d..f1232ed 100644
--- a/tests/unit/test_unit_metfcts.py
+++ b/tests/unit/test_unit_metfcts.py
@@ -4,6 +4,7 @@
 
 import arrow
 import pytest
+
 from smhi.metfcts import Metfcts
 
 BASE_URL = (
diff --git a/tests/unit/test_unit_metobs.py b/tests/unit/test_unit_metobs.py
index 2e633ff..b482266 100644
--- a/tests/unit/test_unit_metobs.py
+++ b/tests/unit/test_unit_metobs.py
@@ -6,6 +6,8 @@
 import pandas as pd
 import pytest
 from pydantic import BaseModel
+from utils import MockResponse, get_data, get_response
+
 from smhi.constants import METOBS_AVAILABLE_PERIODS
 from smhi.metobs import (
     BaseMetobs,
@@ -23,7 +25,6 @@
     MetobsVersionItem,
     MetobsVersionModel,
 )
-from utils import MockResponse, get_data, get_response
 
 
 class MockModelInner(BaseModel):
diff --git a/tests/unit/test_unit_smhi.py b/tests/unit/test_unit_smhi.py
index 23951b1..32e1c41 100644
--- a/tests/unit/test_unit_smhi.py
+++ b/tests/unit/test_unit_smhi.py
@@ -4,6 +4,7 @@
 
 import pandas as pd
 import pytest
+
 from smhi.smhi import SMHI
 
 
diff --git a/tests/unit/test_unit_strang.py b/tests/unit/test_unit_strang.py
index f8de349..045cf89 100644
--- a/tests/unit/test_unit_strang.py
+++ b/tests/unit/test_unit_strang.py
@@ -6,6 +6,8 @@
 import arrow
 import pandas as pd
 import pytest
+from utils import get_response
+
 from smhi.constants import (
     STRANG_MULTIPOINT_URL,
     STRANG_PARAMETERS,
@@ -13,7 +15,6 @@
 )
 from smhi.models.strang_model import StrangParameter
 from smhi.strang import Strang
-from utils import get_response
 
 
 @pytest.fixture
diff --git a/tests/unit/text_unit_utils.py b/tests/unit/text_unit_utils.py
index 5048862..09464f1 100644
--- a/tests/unit/text_unit_utils.py
+++ b/tests/unit/text_unit_utils.py
@@ -1,6 +1,7 @@
 """Test utils functions."""
 
 import pytest
+
 from smhi.utils import format_datetime