Skip to content

Commit

Permalink
Fixed bug with AppleTV multiple sound output : the current AppleTV de…
Browse files Browse the repository at this point in the history
…vice was disable when enabling other airplay devices
  • Loading branch information
albaintor committed Nov 3, 2024
1 parent 23a2388 commit ec51724
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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

0 comments on commit ec51724

Please sign in to comment.