Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added full support for Upcoming Media Card and updated README.md #20

Merged
merged 13 commits into from
Apr 4, 2024

Conversation

mkanet
Copy link
Contributor

@mkanet mkanet commented Mar 25, 2024

Added support for Upcoming Media Cards' new interactive features and updated README.me.

Copy link
Owner

@boralyl boralyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting!

I did an initial review but I suspect there may be more required changes when the build actually runs. After you fix the translation file and push up that commit, you'll likely see more errors in the build show up due to formatting and test failures.

I'd recommend installing pre-commit pip install pre-commit and running the checks locally to see the problems or automatically fix formatting issues.

After installing, from the root directory run:

$ pre-commit run -a

README.md Outdated
| deep_link | Clickable hyperlink to game on Steam website  **\*** |


• _Attributes marked with **\*** are for **upcoming_media_card** only._
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note probably isn't necessary as anyone could use any of the values for any automation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@@ -20,7 +20,7 @@ async def async_setup_entry(
url = entry.data["url"]
# https://store.steampowered.com/wishlist/profiles/<steam-id>/wishlistdata/
steam_id = url.split("/")[-3]
hass.data[DOMAIN][entry.entry_id] = SensorManager(hass, url)
hass.data[DOMAIN][entry.entry_id] = SensorManager(hass, entry, url)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend passing just the boolean value rather than the entire config entry instance.

Suggested change
hass.data[DOMAIN][entry.entry_id] = SensorManager(hass, entry, url)
store_all_wishlist_items = entry.options.get("show_all_wishlist_items", False)
hass.data[DOMAIN][entry.entry_id] = SensorManager(hass, store_all_wishlist_items, url)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This required to make several more changes for this to work. I'm happy to say it's all working now during testing.

'line4_default': '$genres',
'icon': 'mdi:arrow-down-bold',
}
data_list = [placeholders] + [game for game in self.games if game["sale_price"]]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filtering in the list comprehension isn't actually doing anything. Regardless if you've checked or not checked the show_all_wishlist_items this will return the entire wish list. This is because you are converting None to a str, "None", which is not falsey.

>>> bool("None")
True

Comment on lines 116 to 118
def __init__(self, hass: core.HomeAssistant, config_entry, url: str) -> None:
self.hass = hass
self.config_entry = config_entry
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only pass the boolean instead of the config entry instance.

Suggested change
def __init__(self, hass: core.HomeAssistant, config_entry, url: str) -> None:
self.hass = hass
self.config_entry = config_entry
def __init__(self, hass: core.HomeAssistant, store_all_wishlist_items: bool, url: str) -> None:
self.hass = hass
self.store_all_wishlist_items = store_all_wishlist_items

Comment on lines 140 to 141
"""Add or remove sensors based on coordinator data."""
"""Add or update sensors based on coordinator data."""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also remove sensors if you've removed them from your wish list, so let's keep that in the comment.

"init": {
"title": "Opções",
"data": {
"show_all_wishlist_items": "Exiba também itens da lista de desejos não em promoção no Upcoming Media Card (reinicialização necessária)"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"show_all_wishlist_items": "Exiba também itens da lista de desejos não em promoção no Upcoming Media Card (reinicialização necessária)"
"show_all_wishlist_items": "Exiba também itens da lista de desejos não em promoção no Upcoming Media Card"

Comment on lines 38 to 39
tags = game.get("tags", [])
tags_string = ", ".join(tags)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't used at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I forgot to remove that. That was before I had added genres attribute as a string.

price_info = "Price information unavailable"


release_date = ("Release date:&nbsp;&nbsp;" + datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0"))).strftime("%b %d, %Y") + "&nbsp;&nbsp;🆕" if datetime.datetime.utcnow() < datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0")) + 86400) else "Released:&nbsp;&nbsp;" + datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0"))).strftime("%b %d, %Y")) if str(game.get("release_date", "0")).isdigit() else "Unknown"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really hard to read, I'd factor this out into a new function. Generally speaking I wouldn't do more than a single ternary in a statement.

Also note that datetime.utcfromtimestamp and datetime.utcnow are deprecated. Pass in the timezone instead. e.g.

from datetime import datetime, timezone

# replace datetime.utcfromtimestamp() with:
datetime.fromtimestamp(timestamp, timezone.utc)

# replace datetime.utcnow() with:
datetime.now(timezone.utc)

See: https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"sale_price": sale_price,
"steam_id": game_id,
"title": game["name"],
"sale_price": sale_price if not config_entry.options.get("show_all_wishlist_items", True) else str(sale_price),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure why this is needed. Why would you want to use "None" instead of None?

Copy link
Contributor Author

@mkanet mkanet Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, I was looking for the simplest way to display all wishlist items instead of only on_sale items. I realized when switching to "None" instead of None for sale_price, that effectively did what I wanted; hence why I changed that line the way I did. There is probably a better way to do it; but, I just did whatever was quick and effective. In any case, after successfully making all the changes necessary to directly use boolean (store_all_wishlist_items) instead of config_entry that line now looks like this: "sale_price": str(sale_price) if store_all_wishlist_items else sale_price,

Let me know what you think. I already have the changes done in respect to your requests and my comments.

@boralyl boralyl self-requested a review April 4, 2024 18:39
@boralyl boralyl merged commit 9ca16a7 into boralyl:main Apr 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants