Skip to content

Commit 1a9fe00

Browse files
authored
Merge pull request #2179 from SmartThingsCommunity/fix/sonos-non-group-command-routing-in-groups
2 parents 6cecf1b + cd40838 commit 1a9fe00

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ local CapCommandHandlers = {}
1111

1212
local QUEUE_ACTION_PREF = "queueAction"
1313

14-
local function _do_send(device, payload)
14+
local function _do_send(device, payload, use_coordinator)
1515
local conn = device:get_field(PlayerFields.CONNECTION)
1616
if conn and conn:is_running() then
17-
conn:send_command(payload)
17+
conn:send_command(payload, use_coordinator)
1818
else
1919
log.warn("No sonos connection for handling capability command")
2020
end
@@ -33,7 +33,7 @@ local function _do_send_to_group(driver, device, payload)
3333
payload[1].authorization = string.format("Bearer %s", maybe_token.accessToken)
3434
end
3535

36-
_do_send(device, payload)
36+
_do_send(device, payload, true)
3737
end
3838

3939
local function _do_send_to_self(driver, device, payload)
@@ -48,7 +48,7 @@ local function _do_send_to_self(driver, device, payload)
4848
if maybe_token then
4949
payload[1].authorization = string.format("Bearer %s", maybe_token.accessToken)
5050
end
51-
_do_send(device, payload)
51+
_do_send(device, payload, false)
5252
end
5353

5454
function CapCommandHandlers.handle_play(driver, device, _cmd)

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,21 @@ end
586586

587587
--- Send a Sonos command object to the player for this connection
588588
--- @param cmd SonosCommand
589-
function SonosConnection:send_command(cmd)
589+
--- @param use_coordinator boolean
590+
function SonosConnection:send_command(cmd, use_coordinator)
590591
log.debug("Sending command over websocket channel for device " .. self.device.label)
591-
local household_id, coordinator_id = self.driver.sonos:get_coordinator_for_device(self.device)
592+
local household_id, target_id
593+
if use_coordinator then
594+
household_id, target_id = self.driver.sonos:get_coordinator_for_device(self.device)
595+
else
596+
household_id, target_id = self.driver.sonos:get_player_for_device(self.device)
597+
end
592598
local json_payload, err = json.encode(cmd)
593599

594600
if err or not json_payload then
595601
log.error("Json encoding error: " .. err)
596602
else
597-
local unique_key, bad_key_part = utils.sonos_unique_key(household_id, coordinator_id)
603+
local unique_key, bad_key_part = utils.sonos_unique_key(household_id, target_id)
598604
if not unique_key then
599605
self.device.log.error(string.format("Invalid Sonos Unique Key Part: %s", bad_key_part))
600606
return

0 commit comments

Comments
 (0)