-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
There was a problem hiding this 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._ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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"]] |
There was a problem hiding this comment.
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
def __init__(self, hass: core.HomeAssistant, config_entry, url: str) -> None: | ||
self.hass = hass | ||
self.config_entry = config_entry |
There was a problem hiding this comment.
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.
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 |
"""Add or remove sensors based on coordinator data.""" | ||
"""Add or update sensors based on coordinator data.""" |
There was a problem hiding this comment.
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)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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" |
tags = game.get("tags", []) | ||
tags_string = ", ".join(tags) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: " + datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0"))).strftime("%b %d, %Y") + " 🆕" if datetime.datetime.utcnow() < datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0")) + 86400) else "Released: " + datetime.datetime.utcfromtimestamp(int(game.get("release_date", "0"))).strftime("%b %d, %Y")) if str(game.get("release_date", "0")).isdigit() else "Unknown" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Added a callback to update the manager with the option value and schedule a sensor refresh with the option flow is completed.
Added support for Upcoming Media Cards' new interactive features and updated README.me.