Skip to content

Commit

Permalink
Remove state cache usage from sonos
Browse files Browse the repository at this point in the history
The intent of this is to reduce the size of the datastore for this
driver.

It needs to be tested though because I dont think the
`emit_component_event` override will work with our readonly device
object.
  • Loading branch information
cjswedes committed Oct 8, 2024
1 parent 96f5474 commit 7fa8a93
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drivers/SmartThings/sonos/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,29 @@ local function device_added(driver, device)
_initialize_device(driver, device)
end

local function emit_component_event_no_cache(device, component, capability_event)
if not device:supports_capability(capability_event.capability, component.id) then
local err_msg = string.format("Attempted to generate event for %s.%s but it does not support capability %s", device.id, component.id, capability_event.capability.NAME)
log.warn_with({ hub_logs = true }, err_msg)
return false, err_msg
end
local event, err = capabilities.emit_event(device, component.id, device.capability_channel, capability_event)
if err ~= nil then
log.warn_with({ hub_logs = true }, err)
end
return event, err
end

--- @param driver SonosDriver
--- @param device SonosDevice
local function device_init(driver, device)
log.trace(string.format("%s device init", device.label))
_initialize_device(driver, device)

-- Remove usage of the state cache for sonos devices to avoid large datastores
device:set_field("__state_cache", nil, {persist = true})
device:extend_device("emit_component_event", emit_component_event_no_cache)

device:emit_event(capabilities.mediaPlayback.supportedPlaybackCommands({
capabilities.mediaPlayback.commands.play.NAME,
capabilities.mediaPlayback.commands.pause.NAME,
Expand Down

0 comments on commit 7fa8a93

Please sign in to comment.