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 455b1c6 commit 39a0ea3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions drivers/SmartThings/matter-media/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,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 +114,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 +122,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 +208,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 supportTrackControlCommands 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 39a0ea3

Please sign in to comment.