Skip to content

Commit

Permalink
Fix pricing calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed May 18, 2023
1 parent 78287d7 commit e5813e2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions custom_components/steam_wishlist/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ def get_steam_game(game_id: int, game: Dict[str, Any]) -> SteamGame:
pricing: Optional[Dict[str, Any]] = None
try:
pricing: Dict[str, Any] = game["subs"][0]
discount_pct = pricing["discount_pct"]
discount_pct = pricing["discount_pct"] or 0
except IndexError:
# This typically means this game is not yet released so pricing is not known.
pricing = None
discount_pct = 0

normal_price: Optional[float] = None
if pricing:
price = int(pricing["price"])
if discount_pct == 100:
normal_price = pricing["price"]
normal_price = price
else:
normal_price = round(pricing["price"] / (100 - discount_pct), 2)
normal_price = round(price / (100 - discount_pct), 2)

sale_price: Optional[float] = None
if pricing and discount_pct:
# Price is an integer so $6.00 is 600.
sale_price = round(pricing["price"] * 0.01, 2)
sale_price = round(int(pricing["price"]) * 0.01, 2)

game: SteamGame = {
"box_art_url": game["capsule"],
Expand Down

0 comments on commit e5813e2

Please sign in to comment.