Skip to content

Commit

Permalink
fix: revert refactor and disable cyclomatic_complexity for code;
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1th committed Feb 21, 2024
1 parent 9b02925 commit 14e1f34
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ excluded:
- Tests
- Pods
- vendor
- "*/**/.build"
- "**/**/.build"
63 changes: 32 additions & 31 deletions Sources/Vehicle/Templates/Areas/CarPlayAreasViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,43 @@ final class CarPlayAreasViewModel {
)
}

// swiftlint:disable cyclomatic_complexity
private func updateAreas(
_ areas: [HAAreaResponse],
areasAndEntities: [HAEntityAreaResponse],
devicesAndAreas: [HADeviceAreaResponse],
server: Server
) {
let areasAndDevicesDict = mapToareasAndEntities(devicesAndAreas: devicesAndAreas)
var areasAndEntitiesDict = mapToAreasAndEntitiesDict(areasAndEntities: areasAndEntities)
/// area_id : [device_id]
var areasAndDevicesDict: [String: [String]] = [:]

// Get all devices from an area
for device in devicesAndAreas {
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
for entity in areasAndEntities {
if let areaId = entity.areaId, let entityId = entity.entityId {
if var entityIds = areasAndEntitiesDict[areaId] {
entityIds.append(entityId)
areasAndEntitiesDict[areaId] = entityIds
} else {
areasAndEntitiesDict[areaId] = [entityId]
}
}
}

/// device_id : [entity_id]
var deviceChildrenEntities: [String: [String]] = [:]

Expand Down Expand Up @@ -125,35 +154,7 @@ 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]
}
}
}
// swiftlint:enable cyclomatic_complexity

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

0 comments on commit 14e1f34

Please sign in to comment.