Skip to content

Commit

Permalink
refactor: app list
Browse files Browse the repository at this point in the history
  • Loading branch information
martonborzak committed Jul 22, 2023
1 parent 2362372 commit 593db3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion driver.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"driver_id": "uc_appletv_driver",
"version": "0.10.1",
"version": "0.10.2",
"min_core_api": "0.7.0",
"name": { "en": "Apple TV" },
"icon": "custom:appletv.png",
Expand Down
17 changes: 8 additions & 9 deletions driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def event_handler(websocket, id, data):

if not dropdownItems:
LOG.warning('No Apple TVs found')
await api.driverSetupError(websocket, 'No Apple TVs found')
await api.driverSetupError(websocket)
return

await api.requestDriverSetupUserInput(websocket, 'Please choose your Apple TV', [
Expand Down Expand Up @@ -137,7 +137,7 @@ async def event_handler(websocket, id, data):

res = await pairingAppleTv.finishPairing()
if res is None:
await api.driverSetupError(websocket, 'Unable to pair with Apple TV')
await api.driverSetupError(websocket)
else:
c = {
'protocol': res.protocol.name.lower(),
Expand Down Expand Up @@ -165,7 +165,7 @@ async def event_handler(websocket, id, data):

res = await pairingAppleTv.finishPairing()
if res is None:
await api.driverSetupError(websocket, 'Unable to pair with Apple TV')
await api.driverSetupError(websocket)
else:
# Store credentials
c = {
Expand Down Expand Up @@ -204,7 +204,7 @@ async def event_handler(websocket, id, data):

if pairingAppleTv.pairingAtv is None:
LOG.error('Cannot find the chosen AppleTV')
await api.driverSetupError(websocket, 'There was an error during the setup process')
await api.driverSetupError(websocket)
return

await pairingAppleTv.init(choice, name = pairingAppleTv.pairingAtv.name)
Expand Down Expand Up @@ -232,7 +232,7 @@ async def event_handler(websocket, id, data):

else:
LOG.error('No choice was received')
await api.driverSetupError(websocket, 'No Apple TV was selected')
await api.driverSetupError(websocket)

@api.events.on(uc.uc.EVENTS.CONNECT)
async def event_handler():
Expand Down Expand Up @@ -270,10 +270,9 @@ async def event_handler(entityIds):
if entityId in configuredAppleTvs:
LOG.debug('We have a match, start listening to events')

if api.state != uc.uc.DEVICE_STATES.CONNECTED:
api.configuredEntities.updateEntityAttributes(entityId, {
entities.media_player.ATTRIBUTES.STATE: entities.media_player.STATES.UNAVAILABLE
})
api.configuredEntities.updateEntityAttributes(entityId, {
entities.media_player.ATTRIBUTES.STATE: entities.media_player.STATES.UNAVAILABLE
})

appleTv = configuredAppleTvs[entityId]

Expand Down
8 changes: 5 additions & 3 deletions tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,16 @@ async def _pollWorker(self):
except:
LOG.debug('Error while getting playing metadata')

if self._isFeatureAvailable(pyatv.const.FeatureName.AppList):
if self._atv.features.in_state(pyatv.const.FeatureState.Available, pyatv.const.FeatureName.AppList):
try:
appList = await self._atv.apps.app_list()
for app in appList:
self._appList[app.name] = app.identifier
update['sourceList'].append(app.name)
except:
LOG.warning('Could not get app list')
except pyatv.exceptions.NotSupportedError:
LOG.warning('App list is not supported')
except pyatv.exceptions.ProtocolError:
LOG.warning('App list: protocol error')

if self._isFeatureAvailable(pyatv.const.FeatureName.App):
update['source'] = self._atv.metadata.app.name
Expand Down

0 comments on commit 593db3d

Please sign in to comment.