Skip to content

Commit

Permalink
Fix service handling in atvremote
Browse files Browse the repository at this point in the history
  • Loading branch information
postlund committed Feb 23, 2018
1 parent 6235acf commit ad58094
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
12 changes: 2 additions & 10 deletions pyatv/__main__.py
Expand Up @@ -345,23 +345,15 @@ async def _autodiscover_device(args, loop):
return None

apple_tv = atvs[0]

# Extract the preferred service here instead of a usable service. The
# reason for this is that some services are never usable after a scan,
# like MRP, but might become usable after the user has filled in
# additional information (which will be done here).
service = apple_tv.preferred_service()
if not service:
print("fel fel fel")
return None
service = apple_tv.usable_service() # scan only returns usable service

# Common parameters for all protocols
args.address = apple_tv.address
args.name = apple_tv.name
args.protocol = service.protocol
args.port = service.port

# Protocol specific parameters
# Protocol specific parameters (overrides cli arguments)
if service.protocol == const.PROTOCOL_DMAP:
args.device_credentials = service.device_credentials

Expand Down
14 changes: 0 additions & 14 deletions pyatv/conf.py
Expand Up @@ -60,20 +60,6 @@ def usable_service(self):

return None

def preferred_service(self):
"""Return the best supported service of the device.
This methods works similarily to usable_service(), but it will return
the most appropriate service regardless of it being usable or not. So
an Apple TV supporting both DMAP and MRP (like gen 4) will return MRP
here.
"""
for protocol in self._supported_protocols:
if protocol in self._services:
return self._services[protocol]

return None

def is_usable(self):
"""Return True if there are any usable services."""
return any([x.is_usable() for x in self._services.values()])
Expand Down
9 changes: 0 additions & 9 deletions tests/test_conf.py
Expand Up @@ -69,15 +69,6 @@ def test_usable_service(self):
self.service_mock2.is_usable.return_value = True
self.assertEqual(self.atv.usable_service(), self.service_mock2)

def test_preferred_service(self):
self.assertIsNone(self.atv.preferred_service())

self.atv.add_service(self.service_mock)
self.assertEqual(self.atv.preferred_service(), self.service_mock)

self.atv.add_service(self.service_mock2)
self.assertEqual(self.atv.preferred_service(), self.service_mock)

def test_any_service_usable(self):
self.assertFalse(self.atv.is_usable())

Expand Down

0 comments on commit ad58094

Please sign in to comment.