Skip to content

Commit 2c3997e

Browse files
committed
fix: backwards compatibility fixes with older firmware versions.
- Inject `cosock.bus` if it doesn't exist. - Spawn the SSDP task during driver startup on versions that don't support the startup state handler, where it is normally spawned.
1 parent dc1f604 commit 2c3997e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

drivers/SmartThings/sonos/src/init.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
local api_version = require("version").api
2+
local cosock = require "cosock"
3+
4+
if type(cosock.bus) == "nil" then
5+
local cosock_bus = require "cosock.bus"
6+
cosock.bus = cosock_bus
7+
end
8+
19
---@module 'result'
210
require "result" {
311
register_globals = true,
@@ -22,6 +30,15 @@ if driver.datastore["dni_to_device_id"] ~= nil then
2230
driver.datastore["dni_to_device_id"] = nil
2331
end
2432

33+
-- API Version 14 was the version that came out with 0.57.x
34+
--
35+
-- In API >= 14, the SSDP task will start when the driver receives the startup state.
36+
-- To support older versions of hub core, we start the SSDP task before the run loop,
37+
-- where we won't be using the startup state handling.
38+
if api_version < 14 then
39+
driver:start_ssdp_event_task()
40+
end
41+
2542
log.info "Starting Sonos run loop"
2643
driver:run()
2744
log.info "Exiting Sonos run loop"

drivers/SmartThings/sonos/src/sonos_driver.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ end
296296
---@return { accessToken: string, expiresAt: number }? the token if a currently valid token is available, nil if not
297297
---@return "token expired"|"no token"|nil reason the reason a token was not provided, nil if there is a valid token available
298298
function SonosDriver:get_oauth_token()
299+
self.hub_augmented_driver_data = self.hub_augmented_driver_data or {}
299300
local decode_success, maybe_token =
300301
pcall(json.decode, self.hub_augmented_driver_data.sonosOAuthToken)
301302
if

0 commit comments

Comments
 (0)