-
Notifications
You must be signed in to change notification settings - Fork 6
Adds climate, hvac and temperature requests #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
6610c3e
1d1cf9f
5371962
d6e6a68
145e69f
d70a185
c6b73ad
5cee5f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,4 @@ fastlane/screenshots | |
fastlane/test_output | ||
fastlane/README.md | ||
|
||
Tests/Credentials.swift | ||
Tests/Credentials.swift |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Foundation | ||
|
||
public struct ClimateState { | ||
let insideTemp: Double | ||
let outsideTemp: Double | ||
let driverTempSetting: Double | ||
let passengerTempSetting: Double | ||
let isAutoConditioningOn: Bool | ||
let isFrontDefrosterOn: Bool | ||
let isRearDefrosterOn: Bool | ||
let fanStatus: Int? | ||
|
||
init(dict: [String: Any]) { | ||
insideTemp = dict["inside_temp"] as! Double | ||
outsideTemp = dict["outside_temp"] as! Double | ||
driverTempSetting = dict["driver_temp_setting"] as! Double | ||
passengerTempSetting = dict["passenger_temp_setting"] as! Double | ||
isAutoConditioningOn = dict["is_auto_conditioning_on"] as! Bool | ||
isFrontDefrosterOn = dict["is_front_defroster_on"] as! Bool | ||
isRearDefrosterOn = dict["is_rear_defroster_on"] as! Bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Cast Violation: Force casts should be avoided. (force_cast) |
||
fanStatus = dict["fan_status"] as? Int | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Foundation | ||
|
||
public struct ClimateStateRequest: RequestProtocol { | ||
typealias CompletionType = ClimateState | ||
var path: String { | ||
return "/api/1/vehicles/\(vehicleIdentifier)/data_request/climate_state" | ||
} | ||
let method = WebRequest.RequestMethod.get | ||
let accessToken: String | ||
let vehicleIdentifier: String | ||
|
||
public init(accessToken: String, vehicleIdentifier: String) { | ||
self.accessToken = accessToken | ||
self.vehicleIdentifier = vehicleIdentifier | ||
} | ||
|
||
public func execute(completion: @escaping (Result<ClimateState>) -> Void) { | ||
WebRequest.request( | ||
path: path, | ||
method: method, | ||
accessToken: accessToken) { response, error in | ||
if let error = error { | ||
DispatchQueue.main.async { | ||
completion(Result.failure(error)) | ||
} | ||
return | ||
} | ||
let responseDict = response as! [String: [String: Any]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Cast Violation: Force casts should be avoided. (force_cast) |
||
let dataDict = responseDict["response"]! | ||
DispatchQueue.main.async { | ||
completion(Result.success(ClimateState(dict: dataDict))) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
|
||
public struct HVACRequest: RequestProtocol { | ||
public enum HVACState { | ||
case on | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'on' (identifier_name) |
||
case off | ||
} | ||
typealias CompletionType = Bool | ||
var path: String { | ||
switch state { | ||
case .on: | ||
return "/api/1/vehicles/\(vehicleIdentifier)/command/auto_conditioning_start" | ||
case .off: | ||
return "/api/1/vehicles/\(vehicleIdentifier)/command/auto_conditioning_stop" | ||
} | ||
} | ||
let method = WebRequest.RequestMethod.post | ||
let accessToken: String | ||
let vehicleIdentifier: String | ||
let state: HVACState | ||
|
||
public init(accessToken: String, vehicleIdentifier: String, state: HVACState) { | ||
self.accessToken = accessToken | ||
self.vehicleIdentifier = vehicleIdentifier | ||
self.state = state | ||
} | ||
|
||
public func execute(completion: @escaping (Result<Bool>) -> Void) { | ||
WebRequest.request( | ||
path: path, | ||
method: method, | ||
accessToken: accessToken) { response, error in | ||
if let error = error { | ||
DispatchQueue.main.async { | ||
completion(Result.failure(error)) | ||
} | ||
} else if let response = response as? [String: [String: Any]], | ||
let resultBool = response["response"]?["result"] as? Bool { | ||
DispatchQueue.main.async { | ||
completion(Result.success(resultBool)) | ||
} | ||
} else { | ||
DispatchQueue.main.async { | ||
completion(Result.failure(APIError())) | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
|
||
public struct SetTemperaturesRequest: RequestProtocol { | ||
typealias CompletionType = Bool | ||
var path: String { | ||
return "/api/1/vehicles/\(vehicleIdentifier)/command/set_temps" | ||
} | ||
let method = WebRequest.RequestMethod.post | ||
let accessToken: String | ||
let vehicleIdentifier: String | ||
let driverTemp: Double | ||
let passengerTemp: Double | ||
|
||
public init(accessToken: String, vehicleIdentifier: String, driverTemp: Double, passengerTemp: Double) { | ||
self.accessToken = accessToken | ||
self.vehicleIdentifier = vehicleIdentifier | ||
self.driverTemp = driverTemp | ||
self.passengerTemp = passengerTemp | ||
} | ||
|
||
public func execute(completion: @escaping (Result<Bool>) -> Void) { | ||
WebRequest.request( | ||
path: path, | ||
method: method, | ||
params: ["driver_temp": "\(driverTemp)", "passenger_temp": "\(passengerTemp)"], | ||
accessToken: accessToken) { response, error in | ||
if let error = error { | ||
DispatchQueue.main.async { | ||
completion(Result.failure(error)) | ||
} | ||
} else if let response = response as? [String: [String: Any]], | ||
let resultBool = response["response"]?["result"] as? Bool { | ||
DispatchQueue.main.async { | ||
completion(Result.success(resultBool)) | ||
} | ||
} else { | ||
DispatchQueue.main.async { | ||
completion(Result.failure(APIError())) | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force Cast Violation: Force casts should be avoided. (force_cast)