Skip to content

Commit d593cda

Browse files
authored
Sonos: Remove Hardcoded Ports (#2855)
1 parent e763995 commit d593cda

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

drivers/SmartThings/sonos/src/api/sonos_connection.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,11 @@ function SonosConnection.new(driver, device)
487487
return
488488
end
489489

490-
local url_ip = lb_utils.force_url_table(coordinator_player.player.websocket_url).host
490+
local url_table = lb_utils.force_url_table(coordinator_player.player.websocket_url)
491+
local url_ip = url_table.host
492+
local url_port = url_table.port or SonosApi.DEFAULT_SONOS_PORT
491493
local base_url = lb_utils.force_url_table(
492-
string.format("https://%s:%s", url_ip, SonosApi.DEFAULT_SONOS_PORT)
494+
string.format("https://%s:%s", url_ip, url_port)
493495
)
494496
local _, api_key = driver:check_auth(device)
495497
local maybe_token = driver:get_oauth_token()

drivers/SmartThings/sonos/src/api/sonos_ssdp_discovery.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,11 @@ function sonos_ssdp.spawn_persistent_ssdp_task()
421421

422422
if is_new_information then
423423
local headers = SonosApi.make_headers()
424-
local discovery_info, err = SonosApi.RestApi.get_player_info(
425-
net_url.parse(
426-
string.format("https://%s:%s", sonos_ssdp_info.ip, SonosApi.DEFAULT_SONOS_PORT)
427-
),
428-
headers
424+
local parsed_wss_url = net_url.parse(sonos_ssdp_info.wss_url) or {}
425+
local base_url = net_url.parse(
426+
string.format("https://%s:%s", parsed_wss_url.host, parsed_wss_url.port or SonosApi.DEFAULT_SONOS_PORT)
429427
)
428+
local discovery_info, err = SonosApi.RestApi.get_player_info(base_url, headers)
430429
if not discovery_info then
431430
log.error(string.format("Error getting discovery info from SSDP response: %s", err))
432431
elseif discovery_info._objectType == "globalError" then

0 commit comments

Comments
 (0)