Skip to content

Commit

Permalink
Fix incorrect type from diablo.trade (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisoro authored Jul 9, 2024
1 parent 73d41d0 commit 29e3e33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/config/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""New config loading and verification using pydantic. For now, both will exist in parallel hence _new."""

import enum
import logging
import sys

import numpy as np
Expand All @@ -11,6 +12,7 @@
from src.config.helper import check_greater_than_zero, validate_hotkey
from src.item.data.item_type import ItemType

MODULE_LOGGER = logging.getLogger(__name__)
HIDE_FROM_GUI_KEY = "hide_from_gui"
IS_HOTKEY_KEY = "is_hotkey"

Expand Down Expand Up @@ -305,6 +307,15 @@ def font_size_in_range(cls, v: int) -> int:
raise ValueError("Font size must be between 10 and 20, inclusive")
return v

@model_validator(mode="before")
def check_deprecation(cls, data) -> dict:
# removed non_favorites from MoveItemsType
for key in ["move_to_inv_item_type", "move_to_stash_item_type"]:
if key in data and data[key] == "non_favorites":
data[key] = MoveItemsType.unmarked
MODULE_LOGGER.warning(f"{key}=non_favorites is deprecated. Use unmarked instead")
return data


class HSVRangeModel(_IniBaseModel):
h_s_v_min: np_array_pydantic_annotated_typing(dimensions=1)
Expand Down
10 changes: 9 additions & 1 deletion src/gui/importer/diablo_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,15 @@ def _construct_api_url(listing_url: str, cursor: int = 1) -> str:


def _create_affixes_from_api_dict(affixes: list[dict[str, Any]]) -> list[Affix]:
res = [Affix(name=closest_match(clean_str(affix["name"]), Dataloader().affix_dict), value=affix["value"]) for affix in affixes]
res = []
for affix in affixes:
new_affix = Affix(name=closest_match(clean_str(affix["name"]), Dataloader().affix_dict), value=affix["value"])
if isinstance(new_affix.value, list):
if new_affix.value:
new_affix.value = new_affix.value[0]
else:
new_affix.value = 0
res.append(new_affix)
if len(affixes) != len(res) or any(x.name is None for x in res):
LOGGER.error(f"If you see this create a bug ticket! {affixes=}")
return res
Expand Down

0 comments on commit 29e3e33

Please sign in to comment.