Skip to content

Commit

Permalink
Fix link response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewc committed Feb 8, 2020
1 parent d0eebbb commit 6cf0451
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/Hue/Hue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class Hue {
return execute(endpoint: .login, method: .post, body: .link(deviceType: deviceType))
.tryMap { data throws in
let decoder = JSONDecoder()
if let response = try? decoder.decode(LinkErrorResponse.self, from: data), response.isLinkRequest {
if let response = try? decoder.decode([LinkErrorResponse].self, from: data), response.isLinkRequest {
return .linkRequired
}
do {
Expand Down
6 changes: 6 additions & 0 deletions Sources/Hue/Responses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public struct LinkSuccessResponse: Decodable {
public let success: SuccessContent
}

extension Array where Element == LinkErrorResponse {
var isLinkRequest: Bool {
return count == 1 && self.first?.isLinkRequest ?? false
}
}

// MARK: Lights

/// Describes all light elements for a bridge.
Expand Down

0 comments on commit 6cf0451

Please sign in to comment.