Skip to content

Commit

Permalink
Merge current status of develop with first step of migration to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
timbms committed Sep 15, 2024
2 parents e9764d3 + a0b2c22 commit b7f6397
Show file tree
Hide file tree
Showing 29 changed files with 1,183 additions and 2,137 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ build/
BuildTools/.build
OpenHABCore/Package.resolved


#OpenHABCore/Sources/OpenHABCore/GeneratedSources
OpenHABCore/swift-openapi-generator
OpenHABCore/swift-openapi-generator/
2 changes: 2 additions & 0 deletions BuildTools/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ disabled_rules: # rule identifiers to exclude from running

included:
- ../

excluded:
- ../fastlane
- ../OpenHABCore/.build
- .build
- ../OpenHABCore/Sources/OpenHABCore/GeneratedSources/*
- ../OpenHABCore/swift-openapi-generator

nesting:
type_level: 2

Expand Down
5 changes: 1 addition & 4 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,14 @@ public extension OpenHABItem {
}
}

// swiftlint:disable line_length
public extension OpenHABItem.CodingData {
var openHABItem: OpenHABItem {
let mappedMembers = members?.map(\.openHABItem) ?? []

// swiftlint:disable:next line_length
return OpenHABItem(name: name, type: type ?? "", state: state, link: link ?? "", label: label, groupType: groupType, stateDescription: stateDescription?.openHABStateDescription, commandDescription: commandDescription?.openHABCommandDescription, members: mappedMembers, category: category, options: options)
}
}

// swiftlint:enable line_length

extension CGFloat {
init(state string: String, divisor: Float) {
let numberFormatter = NumberFormatter()
Expand Down
24 changes: 22 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Util/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,34 @@ public enum ChartStyle {
case light
}

public enum IconType: Int {
public enum IconType: Int, CaseIterable, Identifiable, CustomStringConvertible {
case png
case svg

public var id: Self { self }

public var description: String {
switch self {
case .png:
"PNG"
case .svg:
"SVG"
}
}
}

public enum SortSitemapsOrder: Int {
public enum SortSitemapsOrder: Int, CaseIterable, CustomStringConvertible {
case label
case name

public var description: String {
switch self {
case .label:
"Label"
case .name:
"Name"
}
}
}

public struct Endpoint {
Expand Down
101 changes: 38 additions & 63 deletions openHAB.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions openHAB.xcodeproj/xcshareddata/xcschemes/openHAB.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
showNonLocalizedStrings = "YES">
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
Expand Down
30 changes: 15 additions & 15 deletions openHAB.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "748c7837511d0e6a507737353af268484e1745e2",
"version" : "1.2024011601.1"
"revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27",
"version" : "1.2024011602.0"
}
},
{
Expand All @@ -33,8 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "076b241a625e25eac22f8849be256dfb960fcdfe",
"version" : "10.19.1"
"revision" : "3b62f154d00019ae29a71e9738800bb6f18b236d",
"version" : "10.19.2"
}
},
{
Expand All @@ -60,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk.git",
"state" : {
"revision" : "9d17b500cd98d9a7009751ad62f802e152e97021",
"version" : "10.26.0"
"revision" : "eca84fd638116dd6adb633b5a3f31cc7befcbb7d",
"version" : "10.29.0"
}
},
{
Expand All @@ -78,8 +78,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "16244d177c4e989f87b25e9db1012b382cfedc55",
"version" : "10.25.0"
"revision" : "fe727587518729046fc1465625b9afd80b5ab361",
"version" : "10.28.0"
}
},
{
Expand Down Expand Up @@ -114,8 +114,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "0382ca27f22fb3494cf657d8dc356dc282cd1193",
"version" : "3.4.1"
"revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b",
"version" : "3.5.0"
}
},
{
Expand Down Expand Up @@ -187,7 +187,7 @@
"location" : "https://github.com/SVGKit/SVGKit.git",
"state" : {
"branch" : "3.x",
"revision" : "02421928cab787faaffb2403d47c39392936fbc7"
"revision" : "cf4dca96801dbbbdb2f37dc8c8571bfaf05c9d41"
}
},
{
Expand All @@ -213,8 +213,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
Expand All @@ -240,8 +240,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "9f0c76544701845ad98716f3f6a774a892152bcb",
"version" : "1.26.0"
"revision" : "edb6ed4919f7756157fe02f2552b7e3850a538e5",
"version" : "1.28.1"
}
},
{
Expand Down
35 changes: 35 additions & 0 deletions openHAB/ClientCertificatesView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2010-2024 Contributors to the openHAB project
//
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

import SwiftUI

struct ClientCertificatesView: View {
@StateObject private var viewModel = ClientCertificatesViewModel()

var body: some View {
List {
ForEach(viewModel.clientCertificates.indices, id: \.self) { index in
Text(viewModel.getIdentityName(for: index))
}
.onDelete { indices in
indices.forEach { viewModel.deleteCertificate(at: $0) }
}
}
.navigationTitle(Text(LocalizedStringKey("client_certificates")))
.onAppear {
viewModel.loadCertificates()
}
}
}

#Preview {
ClientCertificatesView()
}
37 changes: 37 additions & 0 deletions openHAB/ClientCertificatesViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2010-2024 Contributors to the openHAB project
//
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

import OpenHABCore
import os.log
import SwiftUI

class ClientCertificatesViewModel: ObservableObject {
@Published var clientCertificates: [SecIdentity] = []

init() {
loadCertificates()
}

func loadCertificates() {
clientCertificates = NetworkConnection.shared.clientCertificateManager.clientIdentities
}

func deleteCertificate(at index: Int) {
let status = NetworkConnection.shared.clientCertificateManager.deleteFromKeychain(index: index)
if status == noErr {
clientCertificates.remove(at: index)
}
}

func getIdentityName(for index: Int) -> String {
NetworkConnection.shared.clientCertificateManager.getIdentityName(index: index)
}
}
77 changes: 77 additions & 0 deletions openHAB/ColorPickerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) 2010-2024 Contributors to the openHAB project
//
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

import Combine
import OpenHABCore
import os
import SwiftUI

struct ColorPickerView: View {
@State private var selectedColor: Color = .white
@State private var hue: Double = 0.0
@State private var saturation: Double = 0.0
@State private var brightness: Double = 0.0

@ObservedObject var throttler = Throttler(maxInterval: 0.3)

var widget: OpenHABWidget? // OpenHAB widget for sending commands

private let logger = Logger(subsystem: "org.openhab.app", category: "ColorPickerView")

var body: some View {
VStack {
// SwiftUI Color Picker
ColorPicker("Pick a Color", selection: $selectedColor)
.onChange(of: selectedColor) { newColor in
throttler.throttle {
updateHSB(from: newColor)
sendColorUpdate()
}
}
.padding()

// Displaying HSB values
Text("Hue: \(hue, specifier: "%.2f")")
Text("Saturation: \(saturation, specifier: "%.2f")")
Text("Brightness: \(brightness, specifier: "%.2f")")
}
.onAppear {
// Set initial color from widget if available
if let initialColor = widget?.item?.stateAsUIColor() {
selectedColor = Color(initialColor)
}
}
.background(Color(UIColor.systemBackground))
}

// Update hue, saturation, brightness from Color
func updateHSB(from color: Color) {
let uiColor = UIColor(color)
// swiftlint:disable:next large_tuple
var (hue, saturation, brightness, alpha): (CGFloat, CGFloat, CGFloat, CGFloat) = (0.0, 0.0, 0.0, 0.0)
uiColor.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)

self.hue = Double(hue * 360) // Convert to degrees
self.saturation = Double(saturation * 100)
self.brightness = Double(brightness * 100)
}

// Send the color update to the widget
func sendColorUpdate() {
let command = "\(hue),\(saturation),\(brightness)"
logger.debug("Sending command: \(command)")
widget?.sendCommand(command)
}
}

#Preview {
ColorPickerView()
}
31 changes: 0 additions & 31 deletions openHAB/DrawerUITableViewCell.swift

This file was deleted.

Loading

0 comments on commit b7f6397

Please sign in to comment.