Files
duooomi-ios-sdk/Sources/DuooomiBleSDK/Models/VersionInfo.swift

28 lines
846 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
public struct VersionInfo: Sendable, Equatable {
public let version: String
/// Int ( 7) String ( "0x07")
public let type: String
}
extension VersionInfo: Codable {
enum CodingKeys: String, CodingKey {
case version, type
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
version = try container.decode(String.self, forKey: .version)
// type may come as Int or String from different firmware versions
if let str = try? container.decode(String.self, forKey: .type) {
type = str
} else if let num = try? container.decode(Int.self, forKey: .type) {
type = "\(num)"
} else {
type = ""
}
}
}