|
40 | 40 | ---@field private oauth { token: {accessToken: string, expiresAt: number}, endpoint_app_info: { state: "connected"|"disconnected" }, force_oauth: boolean? } cached OAuth info
|
41 | 41 | ---@field private startup_state_received boolean
|
42 | 42 | ---@field private devices_waiting_for_startup_state SonosDevice[]
|
| 43 | +---@field private have_alerted_unauthorized boolean Used to track if we have requested an oauth token, this will trigger the notification used for account linking |
43 | 44 | ---@field package bonded_devices table<string, boolean> map of Device device_network_id to a boolean indicating if the device is currently known as a bonded device.
|
44 | 45 | ---
|
45 | 46 | ---@field public ssdp_task SonosPersistentSsdpTask?
|
@@ -388,6 +389,25 @@ function SonosDriver:oauth_app_connected()
|
388 | 389 | and self.oauth.endpoint_app_info.state == "connected"
|
389 | 390 | end
|
390 | 391 |
|
| 392 | +--- Used to trigger the notification that the user must link their sonos account. |
| 393 | +--- Will request a token a single time which will trigger preinstall isa flow. |
| 394 | +function SonosDriver:alert_unauthorized() |
| 395 | + if api_version < 14 or security == nil then |
| 396 | + return |
| 397 | + end |
| 398 | + if self.have_alerted_unauthorized then |
| 399 | + return |
| 400 | + end |
| 401 | + -- Do the request regardless if we think oauth is connected, because |
| 402 | + -- there is a possibility that we have stale data. |
| 403 | + local result, err = security.get_sonos_oauth() |
| 404 | + if not result then |
| 405 | + log.warn(string.format("Failed to alert unauthorized: %s", err)) |
| 406 | + return |
| 407 | + end |
| 408 | + self.have_alerted_unauthorized = true |
| 409 | +end |
| 410 | + |
391 | 411 | ---Create a cosock task that handles events from the persistent SSDP task.
|
392 | 412 | ---@param driver SonosDriver
|
393 | 413 | ---@param discovery_event_subscription cosock.Bus.Subscription
|
@@ -644,6 +664,7 @@ function SonosDriver.new_driver_template()
|
644 | 664 | oauth_token_bus = oauth_token_bus,
|
645 | 665 | oauth_info_bus = oauth_info_bus,
|
646 | 666 | oauth = {},
|
| 667 | + have_alerted_unauthorized = false, |
647 | 668 | startup_state_received = false,
|
648 | 669 | devices_waiting_for_startup_state = {},
|
649 | 670 | bonded_devices = utils.new_mac_address_keyed_table(),
|
|
0 commit comments