Add support for a connect strategy
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:
- Fail if any protocols fails to connect
- 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.connectaccepting a strategy (needs a new constant inconst.py) - Connect call in
facade.pyis currently sequential and should be made parallel (call connect on each protocol and collect with gather) - Add API to
interface.AppleTVwith 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