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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug with AppleTV multiple sound output : the current AppleTV de… #25

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions driver.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"driver_id": "appletv",
"version": "0.15.0",
"version": "0.15.1",
"min_core_api": "0.7.0",
"name": { "en": "Apple TV" },
"icon": "uc:integration",
Expand Down Expand Up @@ -41,5 +41,5 @@
}
]
},
"release_date": "2024-09-27"
"release_date": "2024-11-03"
}
18 changes: 14 additions & 4 deletions intg-appletv/tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(
self._state: DeviceState | None = None
self._app_list: dict[str, str] = {}
self._available_output_devices: dict[str, str] = {}
self._output_devices: OrderedDict[str, [str]] = OrderedDict()
self._output_devices: OrderedDict[str, [str]] = OrderedDict[str, [str]]()
self._playback_state = PlaybackState.NORMAL

@property
Expand Down Expand Up @@ -598,7 +598,7 @@ def _build_output_devices_list(self, atvs: list[BaseConfig], device_ids: [str]):
device_names.append(atv.name)
break
entry_name: str = ", ".join(sorted(device_names, key=str.casefold))
self._output_devices[entry_name] = combination
self._output_devices[entry_name] = list[str](combination)

async def _poll_worker(self) -> None:
await asyncio.sleep(2)
Expand Down Expand Up @@ -893,12 +893,22 @@ async def set_output_device(self, device_name: str) -> ucapi.StatusCodes:
device_ids = []
for device in output_devices:
device_ids.append(device.identifier)

_LOG.debug("Removing output devices %s", device_ids)
await self._atv.audio.remove_output_devices(*device_ids)
if len(device_entry) == 0:
return ucapi.StatusCodes.OK
_LOG.debug("Setting output devices %s", device_entry)
await self._atv.audio.set_output_devices(*device_entry)

# Add current AppleTV device to the list unless it is already there
new_output_devices = device_entry
found_current_device = [
device_id for device_id in new_output_devices if device_id == self._atv.device_info.output_device_id
]
if len(found_current_device) == 0:
new_output_devices.append(self._atv.device_info.output_device_id)

_LOG.debug("Setting output devices %s", new_output_devices)
await self._atv.audio.set_output_devices(*new_output_devices)

@async_handle_atvlib_errors
async def set_media_position(self, media_position: int) -> ucapi.StatusCodes:
Expand Down