From 5bba532dd46be758bc2879fb666b9f2f4e9d15c7 Mon Sep 17 00:00:00 2001 From: Johan Josua Storm Date: Thu, 25 Feb 2021 15:38:45 +0100 Subject: [PATCH] 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 --- homeassistant/components/xbox/base_sensor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/xbox/base_sensor.py b/homeassistant/components/xbox/base_sensor.py index 028f1d4c9ec..d19fbfb918d 100644 --- a/homeassistant/components/xbox/base_sensor.py +++ b/homeassistant/components/xbox/base_sensor.py @@ -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: