Skip to content

Sonos: Remove Hardcoded Ports#2855

Open
hcarter-775 wants to merge 1 commit intomainfrom
sonos/remove-harcoded-ports
Open

Sonos: Remove Hardcoded Ports#2855
hcarter-775 wants to merge 1 commit intomainfrom
sonos/remove-harcoded-ports

Conversation

@hcarter-775
Copy link
Copy Markdown
Contributor

Description of Change

Let the port being used be defined by the websocket in all cases rather than being hardcoded.

Summary of Completed Tests

@hcarter-775 hcarter-775 force-pushed the sonos/remove-harcoded-ports branch from c9436f8 to 5e1f30f Compare March 26, 2026 15:14
@github-actions
Copy link
Copy Markdown

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 5e1f30f

@github-actions
Copy link
Copy Markdown

Test Results

   72 files    495 suites   0s ⏱️
2 708 tests 2 708 ✅ 0 💤 0 ❌
4 576 runs  4 576 ✅ 0 💤 0 ❌

Results for commit 5e1f30f.

@github-actions
Copy link
Copy Markdown

headers
local parsed_wss_url = net_url.parse(sonos_ssdp_info.wss_url) or {}
local base_url = net_url.parse(
string.format("https://%s:%s", parsed_wss_url.host, parsed_wss_url.port or SonosApi.DEFAULT_SONOS_PORT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the switch from sonos_ssdp_info.ip to parsed_wss_url.host? Is sonos_ssdp_info.wss_url guaranteed to be present with at least a hostname?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These should be the same. ip is parsed from the LOCATION header of the response:

A URL for more information about the device from the
group_description.xml file.

wss_url is parsed from the WEBSOCK.SMARTSPEAKER.AUD IO header:

The WebSocket URL.

Using the websocket url ip is consistent with the other rest call in the PR, but I don't know if one is better to use than the other.

After we get the discovery info here, we combine it with the ssdp info and generate the rest url from ip in the ssdp info. Eventually, the rest url gets set as a device field and is used for the other rest calls not in this PR (as they already use the provided port over the default).

For consistency, I wonder if we should be using ip here and then change the other call in the PR to use device:get_field(PlayerFields.REST_URL) example where we get it from device field

Comment on lines 490 to +491
local url_ip = lb_utils.force_url_table(coordinator_player.player.websocket_url).host
local url_port = lb_utils.force_url_table(coordinator_player.player.websocket_url).port or SonosApi.DEFAULT_SONOS_PORT
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
local url_ip = lb_utils.force_url_table(coordinator_player.player.websocket_url).host
local url_port = lb_utils.force_url_table(coordinator_player.player.websocket_url).port or SonosApi.DEFAULT_SONOS_PORT
local url_table = lb_utils.force_url_table(coordinator_player.player.websocket_url)
local url_ip = url_table.host
local url_port = url_table.port or SonosApi.DEFAULT_SONOS_PORT

headers
local parsed_wss_url = net_url.parse(sonos_ssdp_info.wss_url) or {}
local base_url = net_url.parse(
string.format("https://%s:%s", parsed_wss_url.host, parsed_wss_url.port or SonosApi.DEFAULT_SONOS_PORT)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These should be the same. ip is parsed from the LOCATION header of the response:

A URL for more information about the device from the
group_description.xml file.

wss_url is parsed from the WEBSOCK.SMARTSPEAKER.AUD IO header:

The WebSocket URL.

Using the websocket url ip is consistent with the other rest call in the PR, but I don't know if one is better to use than the other.

After we get the discovery info here, we combine it with the ssdp info and generate the rest url from ip in the ssdp info. Eventually, the rest url gets set as a device field and is used for the other rest calls not in this PR (as they already use the provided port over the default).

For consistency, I wonder if we should be using ip here and then change the other call in the PR to use device:get_field(PlayerFields.REST_URL) example where we get it from device field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants