Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pykefcontrol/kef_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ 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)
payload["value"] = json.dumps(payload["value"], separators=(",", ":"))
with requests.get(
"http://" + self.host + "/api/setData", params=payload
) as response:
response.raise_for_status()
return response.json()

def _track_control(self, command):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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_"]
Expand All @@ -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_"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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_"]
Expand Down Expand Up @@ -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_"]
Expand All @@ -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_"]
Expand Down Expand Up @@ -572,13 +585,15 @@ 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)
payload["value"] = json.dumps(payload["value"], separators=(",", ":"))
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):
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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_"]
Expand All @@ -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_"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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_"]
Expand All @@ -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"]
Expand All @@ -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_"]
Expand All @@ -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_"]
Expand Down