Repository: postlund/pyatv
Pull request #2282 (2023-11-08 17:13:31)

Output all identifiers and mac address when scanning with atvscript
Hi @postlund ,

for the use-case I am currently working on, I use Airplay MAC-Adresses as an identifier https://github.com/maxileith/homebridge-appletv-enhanced/issues/20. Therefore, I always need to get the MAC-Address as an identifier from `atvscript`. However, currently the returned identifier from `atvscript scan` is not always the MAC-Address. Therefore, I would suggest to add an attribute `all_identifieres` to the output json. By not touching `identifier` of the output json, backward compatability is given.

I'd love to hear your thoughts on that.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/postlund/pyatv/pull/2282?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`427c362`)](https://app.codecov.io/gh/postlund/pyatv/commit/427c36240237c459cae4876e2c7b5f7af23f5137?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl) 88.95% compared to head [(`61b2ac8`)](https://app.codecov.io/gh/postlund/pyatv/pull/2282?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl) 88.62%.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #2282      +/-   ##
==========================================
- Coverage   88.95%   88.62%   -0.33%     
==========================================
  Files         168      168              
  Lines       11370    11245     -125     
==========================================
- Hits        10114     9966     -148     
- Misses       1256     1279      +23     
```


[see 16 files with indirect coverage changes](https://app.codecov.io/gh/postlund/pyatv/pull/2282/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl)


</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/postlund/pyatv/pull/2282?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pierre+St%C3%A5hl).

maxileith: I have updated the pull request to include the MAC-Address in the device infos since I noticed that this is available on the atv object anyways
maxileith: Hi everybody,

fyi, I am still waiting for the PR to get reviewed. I haven't forgotten the bug. Seems like the owner of pyatv is on vacation since there are no commits on this repository since a month or so ...
maxileith: Hi @postlund ,

Can you do a ruff estimation on when you will have the time to look at the PR? I don't want to stress, I am just curious and would like to evaluate wether I will wait for the PR or do a workaround 😬
postlund: @maxileith Sorry about the delay, I will try to get around doing that this week!
postlund: Sorry for not getting back sooner on this, but it looks good to me! 👍 I'll see if there's anything else to include, otherwise I can make a minor release soon with this change.

Patch:
diff --git a/docs/documentation/atvscript.md b/docs/documentation/atvscript.md
index d5791061..e7f4129f 100644
--- a/docs/documentation/atvscript.md
+++ b/docs/documentation/atvscript.md
@@ -73,7 +73,13 @@ $ atvscript scan
       "name": "Vardagsrum",
       "address": "10.0.10.81",
       "identifier": "xxx",
-      {
+      "all_identifiers": [
+        "xxx",
+        "xxx",
+        "xxx"
+      ],
+      "device_info": {
+        "mac": "AA:BB:CC:DD:EE:FF",
         "model": "Gen4K",
         "model_str": "Apple TV 4K",
         "operating_system": "TvOS",
@@ -94,7 +100,13 @@ $ atvscript scan
       "name": "Apple TV",
       "address": "10.0.10.123",
       "identifier": "xxx",
+      "all_identifiers": [
+        "xxx",
+        "xxx",
+        "xxx"
+      ],
       "device_info": {
+        "mac": "AA:BB:CC:DD:EE:FF",
         "model": "Gen3",
         "model_str": "Apple TV 3",
         "operating_system": "Legacy",
@@ -115,7 +127,13 @@ $ atvscript scan
       "name": "Proxy",
       "address": "10.0.10.254",
       "identifier": "xxx",
+      "all_identifiers": [
+        "xxx",
+        "xxx",
+        "xxx"
+      ],
       "device_info": {
+        "mac": null,
         "model": "Unknown",
         "model_str": "Unknown",
         "operating_system": "Unknown",
@@ -145,7 +163,13 @@ $ atvscript -s 10.0.10.81 scan
       "name": "Vardagsrum",
       "address": "10.0.10.81",
       "identifier": "xxx",
+      "all_identifiers": [
+        "xxx",
+        "xxx",
+        "xxx"
+      ],
       "device_info": {
+        "mac": "AA:BB:CC:DD:EE:FF",
         "model": "Gen4K",
         "model_str": "Apple TV 4K",
         "operating_system": "TvOS",
diff --git a/pyatv/scripts/atvscript.py b/pyatv/scripts/atvscript.py
index 9c86c07a..61db9bdd 100644
--- a/pyatv/scripts/atvscript.py
+++ b/pyatv/scripts/atvscript.py
@@ -221,7 +221,9 @@ async def _scan_devices(loop, storage: Storage, hosts):
                 "name": atv.name,
                 "address": str(atv.address),
                 "identifier": atv.identifier,
+                "all_identifiers": atv.all_identifiers,
                 "device_info": {
+                    "mac": atv.device_info.mac,
                     "model": atv.device_info.model.name,
                     "model_str": atv.device_info.model_str,
                     "operating_system": atv.device_info.operating_system.name,


Test patch:
diff --git a/tests/scripts/test_atvscript.py b/tests/scripts/test_atvscript.py
index 2da8a518..d083783c 100644
--- a/tests/scripts/test_atvscript.py
+++ b/tests/scripts/test_atvscript.py
@@ -8,7 +8,7 @@ import pytest
 
 from pyatv.const import Protocol
 
-from tests.scripts.conftest import DMAP_ID, IP_1, IP_2, MRP_ID
+from tests.scripts.conftest import AIRPLAY_ID, DMAP_ID, IP_1, IP_2, MRP_ID
 
 _LOGGER = logging.getLogger(__name__)
 HASH = "ca496c14642c78af6dd4250191fe175f6dafd72b4c33bcbab43c454aae051da1"
@@ -41,7 +41,9 @@ async def test_scan_devices(scriptenv, fake_atv):
                     "name": "Apple TV 1",
                     "address": IP_1,
                     "identifier": DMAP_ID,
+                    "all_identifiers": [DMAP_ID],
                     "device_info": {
+                        "mac": None,
                         "model": "Unknown",
                         "model_str": "Unknown",
                         "operating_system": "Legacy",
@@ -53,7 +55,9 @@ async def test_scan_devices(scriptenv, fake_atv):
                     "name": "Apple TV 2",
                     "address": IP_2,
                     "identifier": MRP_ID,
+                    "all_identifiers": [AIRPLAY_ID, MRP_ID],
                     "device_info": {
+                        "mac": AIRPLAY_ID,
                         "model": "Unknown",
                         "model_str": "pyatv",
                         "operating_system": "TvOS",