Skip to content

Commit 9a22827

Browse files
committed
chore: Improve type annotations
1 parent 47cee6a commit 9a22827

File tree

5 files changed

+290
-216
lines changed

5 files changed

+290
-216
lines changed

drivers/SmartThings/sonos/src/api/rest.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ local function process_rest_response(response, err, partial, err_callback)
4949

5050
if not success then
5151
return nil, st_utils.stringify_table(
52-
{response_body = body, json = json_result}, "Couldn't decode JSON in SSE callback", false
52+
{response_body = body, json = json_result}, "Couldn't decode JSON in REST API Response", false
5353
)
5454
end
5555

drivers/SmartThings/sonos/src/api/sonos_connection.lua

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ local SonosRestApi = require "api.rest"
2222
--- @class SonosConnection
2323
--- @field public driver SonosDriver reference to the Edge Driver
2424
--- @field public device SonosDevice the player for this connection
25-
--- @field private _self_listener_uuid string
26-
--- @field private _coord_listener_uuid string
27-
--- @field private _initialized boolean
25+
--- @field package _self_listener_uuid string
26+
--- @field package _coord_listener_uuid string
27+
--- @field package _initialized boolean
28+
--- @field package on_message fun(...)?
29+
--- @field package on_error fun(...)?
30+
--- @field package on_close fun(...)?
2831
local SonosConnection = {}
2932
SonosConnection.__index = SonosConnection
3033

@@ -175,7 +178,7 @@ local function _spawn_reconnect_task(sonos_conn)
175178
cosock.spawn(function()
176179
local backoff = backoff_builder(60, 1, 0.1)
177180
while not sonos_conn:is_running() do
178-
if sonos_conn.driver.waiting_for_token and token_receive_handle then
181+
if sonos_conn.driver.is_waiting_for_token() and token_receive_handle then
179182
local token, channel_error = token_receive_handle:receive()
180183
if not token then
181184
log.warn(string.format("Error requesting token: %s", channel_error))
@@ -264,7 +267,7 @@ function SonosConnection.new(driver, device)
264267
end
265268
local group = household.groups[header.groupId] or { playerIds = {} }
266269
for _, player_id in ipairs(group.playerIds) do
267-
local device_for_player = self.driver._player_id_to_device[player_id]
270+
local device_for_player = self.driver:device_for_player_id(player_id)
268271
--- we've seen situations where these messages can be processed while a device
269272
--- is being deleted so we check for the presence of emit event as a proxy for
270273
--- whether or not this device is currently capable of emitting events.
@@ -286,7 +289,7 @@ function SonosConnection.new(driver, device)
286289
end
287290
local group = household.groups[header.groupId] or { playerIds = {} }
288291
for _, player_id in ipairs(group.playerIds) do
289-
local device_for_player = self.driver._player_id_to_device[player_id]
292+
local device_for_player = self.driver:device_for_player_id(player_id)
290293
--- we've seen situations where these messages can be processed while a device
291294
--- is being deleted so we check for the presence of emit event as a proxy for
292295
--- whether or not this device is currently capable of emitting events.
@@ -307,7 +310,7 @@ function SonosConnection.new(driver, device)
307310
end
308311
local group = household.groups[header.groupId] or { playerIds = {} }
309312
for _, player_id in ipairs(group.playerIds) do
310-
local device_for_player = self.driver._player_id_to_device[player_id]
313+
local device_for_player = self.driver:device_for_player_id(player_id)
311314
--- we've seen situations where these messages can be processed while a device
312315
--- is being deleted so we check for the presence of emit event as a proxy for
313316
--- whether or not this device is currently capable of emitting events.
@@ -355,7 +358,7 @@ function SonosConnection.new(driver, device)
355358
self.driver.sonos:update_household_favorites(header.householdId, new_favorites)
356359

357360
for _, player_id in ipairs(group.playerIds) do
358-
local device_for_player = self.driver._player_id_to_device[player_id]
361+
local device_for_player = self.driver:device_for_player_id(player_id)
359362
--- we've seen situations where these messages can be processed while a device
360363
--- is being deleted so we check for the presence of emit event as a proxy for
361364
--- whether or not this device is currently capable of emitting events.
@@ -479,12 +482,11 @@ function SonosConnection:start()
479482
-- once we know what a forbidden/unauthorized error will look like.
480483
local connection_successful = true
481484
if not connection_successful then
482-
if not self.driver.waiting_for_token then
485+
if not self.driver.is_waiting_for_token() then
483486
local err = self.driver:get_oauth_token()
484487
if err then
485488
log.warn(string.format("notice: get_oauth_token -> %s", err))
486489
end
487-
self.driver.waiting_for_token = true
488490
self.on_close()
489491
end
490492
return false

drivers/SmartThings/sonos/src/disco.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ local ssdp_discovery_callback = function(driver, ssdp_group_info, known_devices_
1919
local name = player_info.device.name or player_info.device.modelDisplayName or "Unknown Sonos Player"
2020
local model = player_info.device.modelDisplayName or "Unknown Sonos Model"
2121

22-
driver._field_cache[dni] = {
22+
driver:cache_fields_for_dni(dni, {
2323
household_id = inner_ssdp_group_info.household_id,
2424
player_id = player_info.playerId,
2525
wss_url = player_info.websocketUrl,
2626
swGen = player_info.device.swGen
27-
}
27+
})
2828

2929
driver.sonos:update_household_info(player_info.householdId, group_info)
3030

0 commit comments

Comments
 (0)