pyatv icon indicating copy to clipboard operation
pyatv copied to clipboard

Add support for a connect strategy

Open postlund opened this issue 4 years ago • 0 comments

Short feature/function description Currently only DMAP and MRP tries to connect to the remote device when calling pyatv.connect. The other protocols do that on-demand, when needed. Only DMAP and MRP support persistent connections so far, which is the reason it works like this. One problem though is that a service can fail because of fatal error, like missing/missing credentials or improper configuration (e.g. wrong port). Ideally, this should be caught during initial connect so that problems can be signaled immediately.

My idea is to introduce a "strategy", so a developer can choose what will happen if connecting to a service fails. I initially intend to support two strategies:

  1. Fail if any protocols fails to connect
  2. Ignore protocols that fail to connect

An API needs to be added to expose which protocol that are actually connected as well as potential exception/error message in case a protocol failed to connect.

Current strategy matches 1 and I would like to keep it like that.

What needs to be done?

  • Add parameter to pyatv.connect accepting a strategy (needs a new constant in const.py)
  • Connect call in facade.py is currently sequential and should be made parallel (call connect on each protocol and collect with gather)
  • Add API to interface.AppleTV with service status, I.e. which protocols are connected (need to think about this a bit more)

Is this a breaking change? Yes and no. No change from an API perspective, but connect will fail in some cases where it would not before.

Anything else worth knowing? No

postlund avatar Jul 13 '21 20:07 postlund