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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace wrong domain returned from xbox api 2.0 #47021

Merged
merged 5 commits into from Feb 25, 2021
Merged

Replace wrong domain returned from xbox api 2.0 #47021

merged 5 commits into from Feb 25, 2021

Conversation

Melantrix
Copy link
Contributor

@Melantrix Melantrix commented Feb 24, 2021

Somehow after setting up the dev environment, i couldn't commit/push to my original fork, thus i needed to create a seperate branch and push it into that. As far as i know i can't merge that branch with the original pull request #46723, if that's somehow possible, please let me know

Proposed change

As explained in this issue-807727457 the xbox api somehow returns a wrong domain sometimes. The wrong url is: "https://images-eds.xboxlive.com/" and it contains a wrong certificate (common name invalid). However, if you replace the domain with: "https://images-eds-ssl.xboxlive.com/" there is no certificate error and the correct image is loaded.

To fix this, the base_sensor can do a string replace. if the wrong url is returned, it is replaced with the correct one. If the xbox api returns the correct one already, nothing is replaced.

**I don't have the means or knowhow to test this, as its a simple change, i'm hoping someone can test this or help me test this **

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:
[N/A]

If the code communicates with devices, web services, or third-party tools:
[N/A]

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@project-bot project-bot bot added this to Needs review in Dev Feb 24, 2021
@probot-home-assistant
Copy link

Hey there @hunterjm, mind taking a look at this pull request as its been labeled with an integration (xbox) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Copy link
Member

@hunterjm hunterjm left a comment

Choose a reason for hiding this comment

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

Looks good @Melantrix. Can merge when tests pass.

Dev automation moved this from Needs review to Reviewer approved Feb 24, 2021
@Melantrix
Copy link
Contributor Author

I don't understand what's going wrong here. The error logs of the check that failed references a file i haven't touched, but somehow it fails? How can i fix this?

url = URL(self.data.display_pic)
if url.host == "images-eds.xboxlive.com":
url = url.with_host("images-eds-ssl.xboxlive.com")
return str(url.with_query(url=url.query["url"], format=url.query["format"]))
Copy link
Contributor

Choose a reason for hiding this comment

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

None of this is needed i think. You just need str(url). Everything else should have been retained.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also you seem to have lost the padding removal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand, you commented that I needed to check if the url needs replacing which I added.

This is the most elegant solution I could think of, because now it checks if the base url needs replacement and does that when necessary (row 56 and 57).

The on row 58, it returns the url with the query string which contains only the necessary queries url and format and thus removes the padding.

How would you do this differently? You commented something like this before, I think I misunderstood then.

Copy link
Contributor

Choose a reason for hiding this comment

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

The old code removed a padding url argument. The new doesn't.

Copy link
Contributor

@elupus elupus Feb 25, 2021

Choose a reason for hiding this comment

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

Okey you recreate with known url queries. But that is not equivalent.

It should have done something like.

q = url.query
q.pop("padding, None)
url = with_query(q)

To be equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, i'll try that

Copy link
Contributor

@elupus elupus left a comment

Choose a reason for hiding this comment

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

I'm okey with this now. But would be good if adjusted comment.

homeassistant/components/xbox/base_sensor.py Outdated Show resolved Hide resolved
@Melantrix
Copy link
Contributor Author

Looks good @Melantrix. Can merge when tests pass.

Checkes have passed, do i need to do anything else to be able to get it merged or is it considered done?

@hunterjm hunterjm merged commit 5bba532 into home-assistant:dev Feb 25, 2021
Dev automation moved this from Reviewer approved to Done Feb 25, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

Xbox integration sometimes uses wrong url for gamertag picture
4 participants