Replace wrong domain returned from xbox api 2.0 (#47021)

* Change solution to use yarl lib

* Add check if base url needs changing

* Actively remove padding query instead of omitting

* Fixed popping the wrong query

* Change explaination about removing mode query
This commit is contained in:
Johan Josua Storm 2021-02-25 15:38:45 +01:00 committed by GitHub
parent 09bafafee2
commit 5bba532dd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,8 @@
"""Base Sensor for the Xbox Integration."""
from typing import Optional
from yarl import URL
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import PresenceData, XboxUpdateCoordinator
@ -44,7 +46,17 @@ class XboxBaseSensorEntity(CoordinatorEntity):
if not self.data:
return None
return self.data.display_pic.replace("&mode=Padding", "")
# Xbox sometimes returns a domain that uses a wrong certificate which creates issues
# with loading the image.
# The correct domain is images-eds-ssl which can just be replaced
# to point to the correct image, with the correct domain and certificate.
# We need to also remove the 'mode=Padding' query because with it, it results in an error 400.
url = URL(self.data.display_pic)
if url.host == "images-eds.xboxlive.com":
url = url.with_host("images-eds-ssl.xboxlive.com")
query = dict(url.query)
query.pop("mode", None)
return str(url.with_query(query))
@property
def entity_registry_enabled_default(self) -> bool: