Skip to content
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
3 changes: 2 additions & 1 deletion drivers/SmartThings/sonos/src/api/sonos_connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,9 @@ function SonosConnection.new(driver, device)
end

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
Comment on lines 490 to +491
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

local base_url = lb_utils.force_url_table(
string.format("https://%s:%s", url_ip, SonosApi.DEFAULT_SONOS_PORT)
string.format("https://%s:%s", url_ip, url_port)
)
local _, api_key = driver:check_auth(device)
local maybe_token = driver:get_oauth_token()
Expand Down
9 changes: 4 additions & 5 deletions drivers/SmartThings/sonos/src/api/sonos_ssdp_discovery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,11 @@ function sonos_ssdp.spawn_persistent_ssdp_task()

if is_new_information then
local headers = SonosApi.make_headers()
local discovery_info, err = SonosApi.RestApi.get_player_info(
net_url.parse(
string.format("https://%s:%s", sonos_ssdp_info.ip, 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.

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

)
local discovery_info, err = SonosApi.RestApi.get_player_info(base_url, headers)
if not discovery_info then
log.error(string.format("Error getting discovery info from SSDP response: %s", err))
elseif discovery_info._objectType == "globalError" then
Expand Down
Loading