Skip to content

Commit 8569fcc

Browse files
authored
Merge pull request #1670 from SmartThingsCommunity/fix/sonos-datastore-size-reduction
Remove state cache usage from sonos
2 parents 96f5474 + 7fa8a93 commit 8569fcc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/SmartThings/sonos/src/init.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,29 @@ local function device_added(driver, device)
242242
_initialize_device(driver, device)
243243
end
244244

245+
local function emit_component_event_no_cache(device, component, capability_event)
246+
if not device:supports_capability(capability_event.capability, component.id) then
247+
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)
248+
log.warn_with({ hub_logs = true }, err_msg)
249+
return false, err_msg
250+
end
251+
local event, err = capabilities.emit_event(device, component.id, device.capability_channel, capability_event)
252+
if err ~= nil then
253+
log.warn_with({ hub_logs = true }, err)
254+
end
255+
return event, err
256+
end
257+
245258
--- @param driver SonosDriver
246259
--- @param device SonosDevice
247260
local function device_init(driver, device)
248261
log.trace(string.format("%s device init", device.label))
249262
_initialize_device(driver, device)
250263

264+
-- Remove usage of the state cache for sonos devices to avoid large datastores
265+
device:set_field("__state_cache", nil, {persist = true})
266+
device:extend_device("emit_component_event", emit_component_event_no_cache)
267+
251268
device:emit_event(capabilities.mediaPlayback.supportedPlaybackCommands({
252269
capabilities.mediaPlayback.commands.play.NAME,
253270
capabilities.mediaPlayback.commands.pause.NAME,

0 commit comments

Comments
 (0)