Move definition ID to cloud name map to json file

This commit is contained in:
Frederic Meeuwissen 2024-03-14 11:46:59 +01:00 committed by Remco Burema
parent d3b1294e8b
commit 1bc8b90b56
2 changed files with 16 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import urllib.parse
from json import JSONDecodeError from json import JSONDecodeError
from time import time from time import time
from typing import Callable, List, Type, TypeVar, Union, Optional, Tuple, Dict, Any, cast from typing import Callable, List, Type, TypeVar, Union, Optional, Tuple, Dict, Any, cast
from pathlib import Path
from PyQt6.QtCore import QUrl from PyQt6.QtCore import QUrl
from PyQt6.QtNetwork import QNetworkRequest, QNetworkReply from PyQt6.QtNetwork import QNetworkRequest, QNetworkReply
@ -30,6 +31,14 @@ CloudApiClientModel = TypeVar("CloudApiClientModel", bound=BaseModel)
"""The generic type variable used to document the methods below.""" """The generic type variable used to document the methods below."""
try:
with open(Path(__file__).parent / "machine_id_to_name.json", "rt") as f:
MACHINE_ID_TO_NAME: Dict[str, str] = json.load(f)
except Exception as e:
Logger.logException("e", f"Could not load machine_id_to_name.json: '{e}'")
MACHINE_ID_TO_NAME = {}
class CloudApiClient: class CloudApiClient:
"""The cloud API client is responsible for handling the requests and responses from the cloud. """The cloud API client is responsible for handling the requests and responses from the cloud.
@ -84,13 +93,8 @@ class CloudApiClient:
# conversion! # conversion!
# API points to "MakerBot Method" for a makerbot printertypes which we already changed to allign with other printer_type # API points to "MakerBot Method" for a makerbot printertypes which we already changed to allign with other printer_type
method_x = { if machine_type in MACHINE_ID_TO_NAME:
"ultimaker_method":"MakerBot Method", machine_type = MACHINE_ID_TO_NAME[machine_type]
"ultimaker_methodx":"MakerBot Method X",
"ultimaker_methodxl":"MakerBot Method XL"
}
if machine_type in method_x:
machine_type = method_x[machine_type]
else: else:
machine_type = machine_type.replace("_plus", "+") machine_type = machine_type.replace("_plus", "+")
machine_type = machine_type.replace("_", " ") machine_type = machine_type.replace("_", " ")

View file

@ -0,0 +1,5 @@
{
"ultimaker_method": "MakerBot Method",
"ultimaker_methodx": "MakerBot Method X",
"ultimaker_methodxl": "MakerBot Method XL"
}