Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detection Sonos player and Sonos app #567

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions regexes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,13 @@ user_agent_parsers:
# AnyConnect
- regex: '(AnyConnect)\/(\d+)(?:\.(\d+)(?:\.(\d+)|)|)'

# Sonos
# @ref: https://docs.sonos.com/docs/soap-requests-and-responses#user-agent-header
- regex: '(Sonos)/(\d+)\.(\d+)()-[^(]+\((ACR|ICRU|MDCR|WDCR)'
family_replacement: 'SonosApp'
- regex: '(Sonos)/(\d+)\.(\d+)-[^(]+\(ZP'
family_replacement: 'SonosPlayer'

# Monitis
- regex: 'compatible; monitis'
family_replacement: 'Monitis'
Expand Down Expand Up @@ -4354,6 +4361,16 @@ device_parsers:
brand_replacement: 'Motorola'
model_replacement: 'XT902'

#########
# Sonos
# @ref: https://docs.sonos.com/docs/soap-requests-and-responses#user-agent-header
# @ref: https://explore.whatismybrowser.com/useragents/explore/software_name/sonos-player/
#########
- regex: 'Sonos/\d+[^(]+\((ZP[^)]+)\)'
brand_replacement: 'Sonos'
device_replacement: 'Player'
model_replacement: '$1'

#########
# Trekstor
# @ref: http://www.trekstor.co.uk/surftabs-en.html
Expand Down
14 changes: 13 additions & 1 deletion tests/test_device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80584,5 +80584,17 @@ test_cases:
brand: 'Motorola'
model: 'motorola moto g play (2021)'

- user_agent_string: 'Linux UPnP/1.0 Sonos/76.2-47142 (ZPS22)'
family: 'Player'
brand: 'Sonos'
model: 'ZPS22'


- user_agent_string: 'Linux UPnP/1.0 Sonos/26.7-48310 (ZP120)'
family: 'Player'
brand: 'Sonos'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be only iPhone7?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, my question was whether we want the model to be iPhone7 or iPhone7,1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm not really sure what iPhone7,1 even means.. but I'll change it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing, mind having a look?

Copy link
Author

@ddurham2 ddurham2 Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sorry for the delay.
So, I reverted the model back to expect it as "iPhone7,1" since:
A) that's the literal example on the Sonos docs site
B) the general parser is correctly parsing the model as "iPhone7,1" and it the tests fail when I muck with it in the way suggested (they now pass).

and

C) I see precedent for both versioned and unversioned model values, depending on whether the UA contained it.
For example, from test_device.yaml
user_agent_string: 'Mozilla/5.0 (iPhone; U; fr; CPU iPhone OS 4_2_1 like Mac OS X; fr) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5'
parses as model: 'iPhone'

and

user_agent_string: 'Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0 [FBAN/FBIOS;FBAV/7.0.0.17.1;FBBV/1325030;FBDV/iPhone6,2;FBMD/iPhone;FBSN/iPhone OS;FBSV/7.0.6;FBSS/2; FBCR/Telekom.de;FBID/phone;FBLC/de_DE;FBOP/5]'
parses as model: 'iPhone6,2'

and many more examples.

Is that acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm, @migueldemoura what do you think?

model: 'ZP120'

- user_agent_string: 'Linux UPnP/1.0 Sonos/29.3-87071 (ICRU\_iPhone7,1); iOS/Version 8.2 (Build 12D508)'
family: 'iPhone'
brand: 'Apple'
model: 'iPhone7,1'
24 changes: 24 additions & 0 deletions tests/test_ua.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8688,6 +8688,30 @@ test_cases:
minor: '2'
patch: '1'

- user_agent_string: 'Linux UPnP/1.0 Sonos/76.2-47142 (ZPS22)'
family: 'SonosPlayer'
major: '76'
minor: '2'
patch:

- user_agent_string: 'Linux UPnP/1.0 Sonos/26.7-48310 (ZP120)'
family: 'SonosPlayer'
major: '26'
minor: '7'
patch:

- user_agent_string: 'Linux UPnP/1.0 Sonos/29.3-87071 (ICRU\_iPhone7,1); iOS/Version 8.2 (Build 12D508)'
family: 'SonosApp'
major: '29'
minor: '3'
patch:

- user_agent_string: 'Linux UPnP/1.0 Sonos/76.2-48062 (ACR_:samsung:p3quew:SM-G998U1)'
family: 'SonosApp'
major: '76'
minor: '2'
patch:

- user_agent_string: 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari/605.1.15 (Ecosia [email protected])'
family: 'Ecosia iOS'
major: '8'
Expand Down
Loading