mirror of
https://github.com/home-assistant/iOS.git
synced 2026-04-12 15:26:45 -05:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> This PR removes the `options` parameters which use the default value. ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> <img width="1014" alt="Screenshot 2024-03-03 at 21 17 55" src="https://github.com/home-assistant/iOS/assets/35694712/85324caf-c36d-4366-a9f8-9c349192a361"> <img width="1049" alt="Screenshot 2024-03-03 at 21 17 17" src="https://github.com/home-assistant/iOS/assets/35694712/cebddbe6-8ea4-415e-b12a-0e35f86bf5a3"> <img width="1022" alt="Screenshot 2024-03-03 at 21 16 53" src="https://github.com/home-assistant/iOS/assets/35694712/ccccb902-9791-42f6-8868-5900093c40ae"> <img width="991" alt="Screenshot 2024-03-03 at 21 16 28" src="https://github.com/home-assistant/iOS/assets/35694712/f2f33685-a55c-47ed-a555-8cc0fc1561ce"> <img width="1329" alt="Screenshot 2024-03-03 at 21 16 00" src="https://github.com/home-assistant/iOS/assets/35694712/2dc156da-29d6-44e4-a064-4fbdb79139bd"> <img width="1130" alt="Screenshot 2024-03-03 at 21 14 53" src="https://github.com/home-assistant/iOS/assets/35694712/628dd2ff-5bba-4ee7-912b-cdbdf73f18b2">
41 lines
1.4 KiB
Swift
41 lines
1.4 KiB
Swift
import Foundation
|
|
import Version
|
|
|
|
public extension Version {
|
|
private static func replacements() throws -> [(regex: NSRegularExpression, replacement: String)] {
|
|
try [
|
|
(regex: NSRegularExpression(pattern: #"\.([a-zA-Z])"#), replacement: #"-$1"#),
|
|
(regex: NSRegularExpression(pattern: #"([0-9])([a-zA-Z])"#), replacement: #"$1-$2"#),
|
|
]
|
|
}
|
|
|
|
init(hassVersion: String) throws {
|
|
let sanitized = try Self.replacements().reduce(into: hassVersion) { result, pair in
|
|
result = pair.regex.stringByReplacingMatches(
|
|
in: result,
|
|
range: NSRange(location: 0, length: result.count),
|
|
withTemplate: pair.replacement
|
|
)
|
|
}
|
|
|
|
let parser = VersionParser(strict: false)
|
|
self = try parser.parse(string: sanitized)
|
|
}
|
|
|
|
func compare(buildOf other: Version) -> ComparisonResult {
|
|
// Build can effectively be a sub-version
|
|
guard let buildVersion = build.flatMap({ try? Version(hassVersion: $0) }),
|
|
let otherBuildVersion = other.build.flatMap({ try? Version(hassVersion: $0) }) else {
|
|
return .orderedAscending
|
|
}
|
|
|
|
if buildVersion < otherBuildVersion {
|
|
return .orderedAscending
|
|
} else if buildVersion == otherBuildVersion {
|
|
return .orderedSame
|
|
} else {
|
|
return .orderedDescending
|
|
}
|
|
}
|
|
}
|