postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
893 stars 99 forks source link

Compatibility with CasaTunes music server? #1679

Open scyto opened 2 years ago

scyto commented 2 years ago

Describe the bug

I need some help figuring out if this is pyatv bug / new feature request or a casatunes bug.

Background

Error log

gathering details 

dns-sd output (the ATV are real ATV devices, rest are all the casatunes music server and share the same IP)

STUDY\C:\Users\alex> dns-sd -B _raop._tcp
Browsing for _raop._tcp
Timestamp     A/R Flags if Domain                    Service Type              Instance Name
12:19:11.574  Add     2 20 local.                    _raop._tcp.               6C4A8501B1D0@Living Room ATV
12:19:11.596  Add     2 20 local.                    _raop._tcp.               4CAB4F8F42F3@Study ATV
12:19:11.613  Add     2 20 local.                    _raop._tcp.               D0D2B099CEF8@Guest Room ATV
12:19:11.804  Add     2 20 local.                    _raop._tcp.               D0D2B08DB24D@Master Bed ATV
12:19:11.916  Add     2 20 local.                    _raop._tcp.               D050999B417E@ Master Bedroom - CT
12:19:11.918  Add     2 20 local.                    _raop._tcp.               D050999B417F@ SarahΓÇÖs Room - CT
12:19:11.920  Add     2 20 local.                    _raop._tcp.               D050999B4180@ Guest Bedroom - CT
12:19:11.921  Add     2 20 local.                    _raop._tcp.               D050999B4181@ Small Room & Balcony - CT
12:19:11.923  Add     2 20 local.                    _raop._tcp.               D050999B4182@ Kitchen - CT
12:19:11.925  Add     2 20 local.                    _raop._tcp.               D050999B4183@ Dining Room - CT
12:19:11.927  Add     2 20 local.                    _raop._tcp.               D050999B4184@ Study - CT
12:19:11.928  Add     2 20 local.                    _raop._tcp.               D050999B4185@ Basement - CT
12:19:11.930  Add     2 20 local.                    _raop._tcp.               D050999B4186@ Denon - CT
12:19:11.937  Add     2 20 local.                    _raop._tcp.               D050999B4187@ All House
12:19:11.938  Add     2 20 local.                    _raop._tcp.               D050999B4188@ All UpStairs
12:19:11.940  Add     2 20 local.                    _raop._tcp.               D050999B4189@ All Ground Floor

How to reproduce the bug?

Add add-in home assitant, point to IP of casatunes server and it finds one airplay endpoint.

What is expected behavior?

It should find multiple airplay endpoints.

Operating System

home assistant (linux) 2022.3.1

Python

3.9

pyatv

0.10.0

Device

CasaTunes Music Server

Additional context

I am unclear what the expected behaviour of pyATV should be in this situation. I am happy to go back to casatunes folks with suggestions on how they can improve their airplay support if needed.

it should be noted my iphone, ipad etc work perfectly with casatunes

scyto commented 2 years ago

pyatv / integration seems to also incorrectly think that is the denon device - which is weird

image

postlund commented 2 years ago

Unicast scanning probably doesn't work as that requires MDNS support on the target for that (usually only Apple devices do that). Home Assistant has a filter to only show devices from Apple (to make sure AirPlay devices not supported by pyatv aren't shown). It should however be shown with atvremote scan, assuming network is working properly. Regarding model name, that is raw from the mdns service. That just means that they announce it as a denon device.

scyto commented 2 years ago

thanks, the atvremote scan seems to be only finding _airplay._tcp devices from apple (i note it is not finding the denon you got working last year) and not _raop._tcp - i will dig in and see if i have a network issue / try a different docker host

good to know you don't see issues with their naming

postlund commented 2 years ago

That sounds a bit network-y to me. There's no intentional filtering in pyatv against non-Apple devices at least. You could try adding --debug and see if you get any hits. Are all devices on the same network or are you using an mdns responder?

scyto commented 2 years ago

I am running everything on one VLAN, there is an mDNS responder on my unifi gateway, i can try turning it off incase it is contaminating things

i just tried running natively on windows and got this, is this normal (sorry to be high maintenance) I want it to bind to the 192.168.x.x address...

STUDY\C:\Users\alex> C:\Users\alex\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Scripts\atvremote scan --debug
2022-03-07 13:21:50 DEBUG [pyatv.scripts]: Running with pyatv 0.10.0
2022-03-07 13:21:50 DEBUG [pyatv.support.net]: Binding on *:5353
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 192.168.1.137 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 169.254.90.124 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 169.254.126.82 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 169.254.177.34 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 169.254.209.75 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 127.0.0.1 (ignoring)
2022-03-07 13:21:50 DEBUG [pyatv.core.mdns]: Failed to add listener for 172.18.0.1 (ignoring)
scyto commented 2 years ago

qq, would the space between the @ and the name cause any issues with pyatv?

Timestamp     A/R Flags if Domain                    Service Type              Instance Name
13:41:19.474  Add     2 20 local.                    _raop._tcp.               D0D2B099CEF8@Guest Room ATV
13:41:19.530  Add     2 20 local.                    _raop._tcp.               6C4A8501B1D0@Living Room ATV
13:41:19.597  Add     2 20 local.                    _raop._tcp.               D0D2B08DB24D@Master Bed ATV
13:41:19.622  Add     2 20 local.                    _raop._tcp.               D050999B417E@ Master Bedroom - CT
13:41:19.624  Add     2 20 local.                    _raop._tcp.               D050999B417F@ SarahΓÇÖs Room - CT
13:41:19.626  Add     2 20 local.                    _raop._tcp.               D050999B4180@ Guest Bedroom - CT
13:41:19.627  Add     2 20 local.                    _raop._tcp.               D050999B4181@ Small Room & Balcony - CT
13:41:19.629  Add     2 20 local.                    _raop._tcp.               D050999B4182@ Kitchen - CT
13:41:19.631  Add     2 20 local.                    _raop._tcp.               D050999B4183@ Dining Room - CT
13:41:19.632  Add     2 20 local.                    _raop._tcp.               D050999B4184@ Study - CT
13:41:19.635  Add     2 20 local.                    _raop._tcp.               D050999B4185@ Basement - CT
13:41:19.641  Add     2 20 local.                    _raop._tcp.               D050999B4186@ Denon - CT
13:41:19.643  Add     2 20 local.                    _raop._tcp.               D050999B4187@ All House
13:41:19.644  Add     2 20 local.                    _raop._tcp.               D050999B4188@ All UpStairs
13:41:19.646  Add     2 20 local.                    _raop._tcp.               D050999B4189@ All Ground Floor
13:41:20.998  Add     2 20 local.                    _raop._tcp.               4CAB4F8F42F3@Study ATV

pyatv is seeing all the devices with no space after the @ symbol....

scyto commented 2 years ago

You could try adding --debug and see if you get any hits.

debug didn't show any other hits (using docker on linux VM)

Are all devices on the same network or are you using an mdns responder?

I disabled my mDNS reflector, no change in behaviour. (yes all on same default vlan)

scyto commented 2 years ago

Home Assistant has a filter to only show devices from Apple (to make sure AirPlay devices not supported by pyatv aren't shown)

Is that the integration or home assistant itsefl?

scyto commented 2 years ago

I did some more testing. I tested the scan command directly on my home assistant instance by shelling into the hass container.

automatic scanning still doesn't find casatunes. and manual scanning doesn't find anything

bash-5.1# atvremote --scan-hosts 192.168.1.179 scan --debug
2022-03-12 11:12:06 DEBUG [pyatv.scripts]: Running with pyatv 0.10.0
2022-03-12 11:12:06 DEBUG [pyatv.support.knock]: Knocking at port 3689 on 192.168.1.179
2022-03-12 11:12:06 DEBUG [pyatv.support.knock]: Knocking at port 7000 on 192.168.1.179
2022-03-12 11:12:06 DEBUG [pyatv.support.knock]: Knocking at port 49152 on 192.168.1.179
2022-03-12 11:12:06 DEBUG [pyatv.support.knock]: Knocking at port 32498 on 192.168.1.179
Scan Results
========================================
bash-5.1# 

I figured out why my sony receiver was no longer detected (it had fallen off the network) an automatic scan found it.

       Name: Sony
   Model/SW: MSA4G-N108, Unknown OS
    Address: 192.168.1.170
        MAC: 04:5D:4B:B2:72:8A
 Deep Sleep: False
Identifiers:
 - 04:5D:4B:B2:72:8A
 - 045D4BB2728A
Services:
 - Protocol: AirPlay, Port: 5000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded
 - Protocol: RAOP, Port: 5000, Credentials: None, Requires Password: False, Password: None, Pairing: NotNeeded

Whats interesting is this command also failed when directed at the sony receiver, so i am not sure its a useful test for casatunes?

bash-5.1# atvremote --scan-hosts 192.168.1.170 scan --debug
2022-03-12 11:21:56 DEBUG [pyatv.scripts]: Running with pyatv 0.10.0
2022-03-12 11:21:56 DEBUG [pyatv.support.knock]: Knocking at port 3689 on 192.168.1.170
2022-03-12 11:21:56 DEBUG [pyatv.support.knock]: Knocking at port 7000 on 192.168.1.170
2022-03-12 11:21:56 DEBUG [pyatv.support.knock]: Knocking at port 49152 on 192.168.1.170
2022-03-12 11:21:56 DEBUG [pyatv.support.knock]: Knocking at port 32498 on 192.168.1.170
Scan Results
========================================

i note that it does noy say its checking port 5000 for anything?

scyto commented 2 years ago

Could this be the issue - casatunes is not advertising itself with airplay service endpoints? only the raop service endpoints?

STUDY\C:\Users\alex> dns-sd -B _raop._tcp
Browsing for _raop._tcp
Timestamp     A/R Flags if Domain                    Service Type              Instance Name
11:33:45.817  Add     3 25 local.                    _raop._tcp.               6C4A8501B1D0@Living Room ATV
11:33:45.817  Add     3 25 local.                    _raop._tcp.               D050999B417E@ Master Bedroom - CT
11:33:45.818  Add     3 25 local.                    _raop._tcp.               D050999B417F@ SarahΓÇÖs Room - CT
11:33:45.818  Add     3 25 local.                    _raop._tcp.               D050999B4180@ Guest Bedroom - CT
11:33:45.818  Add     3 25 local.                    _raop._tcp.               D050999B4181@ Cat Room & Balcony - CT
11:33:45.819  Add     3 25 local.                    _raop._tcp.               D050999B4182@ Kitchen - CT
11:33:45.819  Add     3 25 local.                    _raop._tcp.               D050999B4183@ Dining Room - CT
11:33:45.819  Add     3 25 local.                    _raop._tcp.               D050999B4184@ Study - CT
11:33:45.820  Add     3 25 local.                    _raop._tcp.               D050999B4185@ Basement - CT
11:33:45.820  Add     3 25 local.                    _raop._tcp.               D050999B4186@ Denon - CT
11:33:45.820  Add     3 25 local.                    _raop._tcp.               D050999B4187@ All House
11:33:45.820  Add     3 25 local.                    _raop._tcp.               D050999B4188@ All UpStairs
11:33:45.821  Add     2 25 local.                    _raop._tcp.               D050999B4189@ All Ground Floor
11:33:45.948  Add     2 25 local.                    _raop._tcp.               D0D2B099CEF8@Guest Room ATV
11:33:45.969  Add     2 25 local.                    _raop._tcp.               045D4BB2728A@Sony
11:33:46.001  Add     2 25 local.                    _raop._tcp.               D0D2B08DB24D@Master Bed ATV
11:33:46.154  Add     2 25 local.                    _raop._tcp.               D050999B418A@ Casa Sony
11:33:46.464  Add     2 25 local.                    _raop._tcp.               4CAB4F8F42F3@Study ATV
STUDY\C:\Users\alex> dns-sd -B _airplay._tcp
Browsing for _airplay._tcp
Timestamp     A/R Flags if Domain                    Service Type              Instance Name
11:34:26.085  Add     2 25 local.                    _airplay._tcp.            Master Bed ATV
11:34:26.086  Add     2 25 local.                    _airplay._tcp.            Living Room ATV
11:34:26.090  Add     2 25 local.                    _airplay._tcp.            Sony
11:34:26.121  Add     2 25 local.                    _airplay._tcp.            Guest Room ATV
11:34:26.593  Add     2 25 local.                    _airplay._tcp.            Study ATV
postlund commented 2 years ago

Sorry for not responding here, we should of course try to fix this. It is OK that it only annonunces a RAOP service, that is sufficient (my Yamaha receiver works in the same way). The _airplay-service is really the "video" part of AirPlay anyway. It is however strange that unicast scanning doesn't find the device. Can't really tell you why that is, but as long as Home Assistant itself find it everything should be fine.

When you added a device with IP above (when it was discovered as a DENON device, which is what they have set in CasaTunes), did you get a device that you could use? The only real use case you have is to stream audio. Unfortunately pyatv doesn't support grouping of devices, so you will only be able to stream to one device at the time.