Skip to content

Commit

Permalink
feat(ios): update swiftlint and swiftformat + fix swiftlint issues;
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1th committed Feb 16, 2024
1 parent f7dfc4c commit ae2b608
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ jobs:
- name: SwiftLint
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
ghcr.io/realm/swiftlint:0.49.1 \
ghcr.io/realm/swiftlint:0.54.0 \
swiftlint lint --strict --config .swiftlint.yml --reporter github-actions-logging
- name: SwiftFormat
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
ghcr.io/nicklockwood/swiftformat:0.50.3 \
ghcr.io/nicklockwood/swiftformat:0.53.1 \
--lint --config .swiftformat .
test:
Expand Down
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ project 'HomeAssistant', 'Debug' => :debug, 'Release' => :release, 'Beta' => :re

def support_modules
pod 'SwiftGen', '~> 6.5.0'
pod 'SwiftLint', '0.49.1' # also update ci.yml GHA
pod 'SwiftFormat/CLI', '0.50.3' # also update ci.yml GHA
pod 'SwiftLint', '0.54.0' # also update ci.yml GHA
pod 'SwiftFormat/CLI', '0.53.1' # also update ci.yml GHA
end

if ENV['ONLY_SUPPORT_MODULES']
Expand Down
16 changes: 8 additions & 8 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ PODS:
- Realm (= 10.35.0)
- Sodium (0.9.1)
- Starscream (4.0.4)
- SwiftFormat/CLI (0.50.3)
- SwiftFormat/CLI (0.53.1)
- SwiftGen (6.5.1)
- SwiftLint (0.49.1)
- SwiftLint (0.54.0)
- SwiftMessages (9.0.6):
- SwiftMessages/App (= 9.0.6)
- SwiftMessages/App (9.0.6)
Expand Down Expand Up @@ -141,9 +141,9 @@ DEPENDENCIES:
- RealmSwift
- Sodium (from `https://github.com/zacwest/swift-sodium.git`, branch `xcode-14.0.1`)
- Starscream (from `https://github.com/zacwest/starscream`, branch `ha-swift-api`)
- SwiftFormat/CLI (= 0.50.3)
- SwiftFormat/CLI (= 0.53.1)
- SwiftGen (~> 6.5.0)
- SwiftLint (= 0.49.1)
- SwiftLint (= 0.54.0)
- SwiftMessages
- UIColor_Hex_Swift
- Version
Expand Down Expand Up @@ -274,16 +274,16 @@ SPEC CHECKSUMS:
RealmSwift: b358779c10ba6d2648d541f8a1bcd671f73485c1
Sodium: a7d42cb46e789d2630fa552d35870b416ed055ae
Starscream: 5178aed56b316f13fa3bc55694e583d35dd414d9
SwiftFormat: 61cda3819dc3a7d69795ce0430e1e1d53c4a4fb2
SwiftFormat: a8623113c7adcbeb4289a013cac68ec801e1ed24
SwiftGen: a6d22010845f08fe18fbdf3a07a8e380fd22e0ea
SwiftLint: 32ee33ded0636d0905ef6911b2b67bbaeeedafa5
SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211
SwiftMessages: f0c7ef4705a570ad6c5e208b611f4333e660ed92
UIColor_Hex_Swift: 31cd3e47440f07a20d2503a36bb0437a445b3c29
Version: de5907f2c5d0f3cf21708db7801d1d5401139486
ViewRow: 8da541e9c019f3be63f4e28f311a62cac2045ecf
XCGLogger: 1943831ef907df55108b0b18657953f868de973b
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced

PODFILE CHECKSUM: 22fc24cfd665bd31532e7b68cf2aee22abb132b2
PODFILE CHECKSUM: a1fb8b74054208eb193f5366db79acab04a209b0

COCOAPODS: 1.13.0
COCOAPODS: 1.15.2
67 changes: 35 additions & 32 deletions Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,14 @@ final class CarPlayAreasViewModel {
devicesAndAreas: [HADeviceAreaResponse],
server: Server
) {
/// area_id : [device_id]
var areasAndDevicesDict: [String: [String]] = [:]

// Get all devices from an area
devicesAndAreas.forEach { device in
if let areaId = device.areaId, let deviceId = device.deviceId {
if var deviceIds = areasAndDevicesDict[areaId] {
deviceIds.append(deviceId)
areasAndDevicesDict[areaId] = deviceIds
} else {
areasAndDevicesDict[areaId] = [deviceId]
}
}
}

/// area_id : [entity_id]
var areasAndEntitiesDict: [String: [String]] = [:]

// Get all entities from an area
areasAndEntities.forEach { entity in
if let areaId = entity.areaId, let entityId = entity.entityId {
if var entityIds = areasAndEntitiesDict[areaId] {
entityIds.append(entityId)
areasAndEntitiesDict[areaId] = entityIds
} else {
areasAndEntitiesDict[areaId] = [entityId]
}
}
}

let areasAndDevicesDict = mapToareasAndEntities(devicesAndAreas: devicesAndAreas)
var areasAndEntitiesDict = mapToAreasAndEntitiesDict(areasAndEntities: areasAndEntities)
/// device_id : [entity_id]
var deviceChildrenEntities: [String: [String]] = [:]

// Get entities from a device
areasAndDevicesDict.forEach { areaAndDevices in
areaAndDevices.value.forEach { deviceId in
for areaAndDevices in areasAndDevicesDict {
for deviceId in areaAndDevices.value {
deviceChildrenEntities[deviceId] = areasAndEntities.filter { $0.deviceId == deviceId }
.compactMap(\.entityId)
}
Expand Down Expand Up @@ -152,6 +124,37 @@ final class CarPlayAreasViewModel {

templateProvider?.paginatedList.updateItems(items: items)
}

/// - returns: area_id : [device_id]
private func mapToareasAndEntities(devicesAndAreas: [HADeviceAreaResponse]) -> [String: [String]] {
devicesAndAreas.reduce(into: [:]) { partialResult, device in
guard let areaId = device.areaId, let deviceId = device.deviceId else {
return
}
if var deviceIds = partialResult[deviceId] {
deviceIds.append(deviceId)
partialResult[areaId] = deviceIds
} else {
partialResult[areaId] = [deviceId]
}
}
}

/// - returns: area_id : [entity_id]
private func mapToAreasAndEntitiesDict(areasAndEntities: [HAEntityAreaResponse]) -> [String: [String]] {
areasAndEntities.reduce(into: [:]) { partialResult, entity in
guard let areaId = entity.areaId, let entityId = entity.entityId else {
return
}
if var entityIds = partialResult[areaId] {
entityIds.append(entityId)
partialResult[areaId] = entityIds
} else {
partialResult[areaId] = [entityId]
}
}

}

private func listItemHandler(area: HAAreaResponse, entityIdsForAreaId: [String], server: Server) {
let entitiesCachedStates = Current.api(for: server).connection.caches.states
Expand Down

0 comments on commit ae2b608

Please sign in to comment.