Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion drivers/SmartThings/sonos/src/sonos_driver.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local api_version = require "version".api
local version = require "version"
local api_version = version.api
local rpc_version = version.rpc
local capabilities = require "st.capabilities"
local cosock = require "cosock"
local json = require "st.json"
Expand Down Expand Up @@ -651,6 +653,59 @@ local function do_refresh(driver, device, cmd)
sonos_conn:refresh_subscriptions()
end

--- In RPC version 100, the events for augmented driver store were changed
--- to no longer match the parsing done in API version 18 and below.
---
--- API version 19 will handle both before and after RPC 100 changes so this only needs
--- to be applied for RPC version >= 100 and API version <= 18.
if rpc_version >= 100 and api_version <= 18 then
log.info_with({ hub_logs = true }, "Overriding environment info handler for RPC >= 100 and API <= 18")
function SonosDriver:environment_info_handler(channel)
log.info_with({ hub_logs = true }, "Starting environment info handler for RPC >= 100 and API <= 18")
local msg_type, msg_val = channel:receive()
-- This driver only cares about augmentDriverStore messages currently.
-- Previously, this was augmentDatastore msg_type.
if msg_type == "augmentDriverStore" then
if type(msg_val.payload) ~= "table" then
log.warn(
string.format(
"Unexpected augmentDriverStore payload type: %s",
type(msg_val.payload)
)
)
return
end
-- The field evt_kind was renamed to kind and is a string of the enum rather than
-- the integer value of the enum.
if msg_val.kind == "Upsert" then
-- This type was changed to table of u8s instead of a string
local data = ""
for _, v in pairs(msg_val.payload.data_value) do
data = data .. string.char(v)
end
self.hub_augmented_driver_data[msg_val.payload.data_key] = data
-- notify with the updated record
if self.notify_augmented_data_changed ~= nil then
self:notify_augmented_data_changed("upsert", msg_val.payload.data_key, data)
end
elseif msg_val.kind == "Delete" then
self.hub_augmented_driver_data[msg_val.payload.data_key] = nil
-- notify with just the key that got deleted
if self.notify_augmented_data_changed ~= nil then
self:notify_augmented_data_changed("delete", msg_val.payload.data_key)
end
else
log.warn(
string.format(
"Unexpected augmentDriverStore kind: %s",
msg_val.kind
)
)
end
end
end
end

function SonosDriver.new_driver_template()
local oauth_token_bus = cosock.bus()
local oauth_info_bus = cosock.bus()
Expand All @@ -667,6 +722,8 @@ function SonosDriver.new_driver_template()
bonded_devices = utils.new_mac_address_keyed_table(),
dni_to_device_id = utils.new_mac_address_keyed_table(),
lifecycle_handlers = SonosDriverLifecycleHandlers,
-- Only overriden in the case of RPC version 100+ with API version <= 18
environment_info_handler = SonosDriver.environment_info_handler,
capability_handlers = {
[capabilities.refresh.ID] = {
[capabilities.refresh.commands.refresh.NAME] = do_refresh,
Expand Down
Loading