Skip to content

Commit

Permalink
Add supportedTrackControls event in infoChanged handling
Browse files Browse the repository at this point in the history
Whenever a profile is updated to a profile with mediaTrackControl
support, emit an event for the supportedTrackControlCommands.
  • Loading branch information
ctowns committed Dec 16, 2022
1 parent cac54ba commit 6fa8111
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions drivers/SmartThings/matter-media/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
local capabilities = require "st.capabilities"
local clusters = require "st.matter.clusters"
local MatterDriver = require "st.matter.driver"
local utils = require "st.utils"
local MediaPlaybackClusterAcceptedCommandList = clusters.MediaPlayback.attributes.AcceptedCommandList

local VOLUME_STEP = 5
Expand Down Expand Up @@ -46,8 +45,6 @@ local configure_handler = function(self, device)
}))
end

-- TODO: when to emit supported commands for MediaTrackControl?

device:emit_event(capabilities.keypadInput.supportedKeyCodes({
"UP",
"DOWN",
Expand Down Expand Up @@ -116,7 +113,6 @@ end
local function accepted_command_list_attr_handler(driver, device, ib, response)
for _, accepted_command_id in ipairs (ib.data.elements or {}) do
local new_profile = "media-video-player"
-- TODO: do you think it is safe to just check for the "Next" command? Or both/either?
if accepted_command_id.value == clusters.MediaPlayback.commands.Next.ID then
if device:supports_capability(capabilities.audioMute, device:endpoint_to_component(ib.endpoint_id)) then
new_profile = new_profile .. "-speaker"
Expand All @@ -125,12 +121,6 @@ local function accepted_command_list_attr_handler(driver, device, ib, response)

device.log.info(string.format("Updating device profile to %s.", new_profile))
device:try_update_metadata({profile = new_profile})

-- TODO: Should this be moved here or no? Should this event be emitted somewhere else now?
-- device:emit_event(capabilities.mediaTrackControl.supportedTrackControlCommands({
-- capabilities.mediaTrackControl.commands.previousTrack.NAME,
-- capabilities.mediaTrackControl.commands.nextTrack.NAME,
-- }))
return
end
end
Expand Down Expand Up @@ -217,10 +207,21 @@ local function handle_send_key(driver, device, cmd)
device:send(req)
end

local function info_changed(self, device, event, args)
-- if device was updated to a profile with mediaTrackControl, emit a supportedTrackControlCommands event
if device:supports_capability(capabilities.mediaTrackControl) then
device:emit_event(capabilities.mediaTrackControl.supportedTrackControlCommands({
capabilities.mediaTrackControl.commands.previousTrack.NAME,
capabilities.mediaTrackControl.commands.nextTrack.NAME,
}))
end
end

local matter_driver_template = {
lifecycle_handlers = {
init = device_init,
doConfigure = configure_handler
doConfigure = configure_handler,
infoChanged = info_changed
},
matter_handlers = {
attr = {
Expand Down

0 comments on commit 6fa8111

Please sign in to comment.