From e23c335c3de735bedd8746bdb5669becb8bc5fdb Mon Sep 17 00:00:00 2001 From: leccelecce <24962424+leccelecce@users.noreply.github.com> Date: Fri, 17 Apr 2026 09:34:30 +0100 Subject: [PATCH] Correctly raise exceptions for HTTP errors --- pykefcontrol/kef_connector.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pykefcontrol/kef_connector.py b/pykefcontrol/kef_connector.py index 1f03dab..a9c6903 100644 --- a/pykefcontrol/kef_connector.py +++ b/pykefcontrol/kef_connector.py @@ -60,6 +60,7 @@ def _set_data(self, payload): with requests.post( "http://" + self.host + "/api/setData", json=payload ) as response: + response.raise_for_status() return response.json() else: payload = dict(payload) @@ -67,6 +68,7 @@ def _set_data(self, payload): with requests.get( "http://" + self.host + "/api/setData", params=payload ) as response: + response.raise_for_status() return response.json() def _track_control(self, command): @@ -99,6 +101,7 @@ def _get_player_data(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0] @@ -182,6 +185,7 @@ def get_request(self, path, roles="value"): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output @@ -250,6 +254,7 @@ def _get_polling_queue(self, song_status=False, poll_song_status=False): with requests.post( "http://" + self.host + "/api/event/modifyQueue", json=payload ) as response: + response.raise_for_status() json_output = response.json() # Update polling_queue property with queue uuid @@ -322,6 +327,7 @@ def poll_speaker(self, timeout=10, song_status=False, poll_song_status=False): params=payload, timeout=timeout + 0.5, # add 0.5 seconds to timeout to allow for processing ) as response: + response.raise_for_status() json_output = response.json() # Process all events @@ -348,6 +354,7 @@ def mac_address(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["string_"] @@ -360,6 +367,7 @@ def speaker_name(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["string_"] @@ -372,6 +380,7 @@ def status(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["kefSpeakerStatus"] @@ -400,6 +409,7 @@ def source(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["kefPhysicalSource"] @@ -431,6 +441,7 @@ def volume(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["i32_"] @@ -475,6 +486,7 @@ def song_status(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["i64_"] @@ -492,6 +504,7 @@ def _get_speaker_firmware_version(self): with requests.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = response.json() return json_output[0]["string_"] @@ -572,6 +585,7 @@ async def _set_data(self, payload): async with self._session.post( "http://" + self.host + "/api/setData", json=payload ) as response: + response.raise_for_status() return await response.json() else: payload = dict(payload) @@ -579,6 +593,7 @@ async def _set_data(self, payload): async with self._session.get( "http://" + self.host + "/api/setData", params=payload ) as response: + response.raise_for_status() return await response.json() async def _track_control(self, command): @@ -600,6 +615,7 @@ async def _get_player_data(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0] @@ -622,6 +638,7 @@ async def get_request(self, path, roles="value"): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output @@ -776,6 +793,7 @@ async def get_polling_queue(self, song_status=False, poll_song_status=False): async with self._session.post( "http://" + self.host + "/api/event/modifyQueue", json=payload ) as response: + response.raise_for_status() json_output = await response.json() # Update polling_queue property with queue uuid @@ -845,6 +863,7 @@ async def poll_speaker(self, timeout=10, song_status=False, poll_song_status=Fal params=payload, timeout=10 + 0.5, # add 0.5 seconds to timeout to allow for processing ) as response: + response.raise_for_status() json_output = await response.json() # Process all events @@ -870,6 +889,7 @@ async def mac_address(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["string_"] @@ -882,6 +902,7 @@ async def speaker_name(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["string_"] @@ -894,6 +915,7 @@ async def status(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["kefSpeakerStatus"] @@ -924,6 +946,7 @@ async def song_status(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["i64_"] @@ -940,6 +963,7 @@ async def source(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["kefPhysicalSource"] @@ -955,6 +979,7 @@ async def volume(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["i32_"] @@ -972,6 +997,7 @@ async def _get_speaker_firmware_version(self): async with self._session.get( "http://" + self.host + "/api/getData", params=payload ) as response: + response.raise_for_status() json_output = await response.json() return json_output[0]["string_"]