From f54c8b23df83486694a67d79fe1ca83425e59085 Mon Sep 17 00:00:00 2001 From: Tim Bert <5411131+timbms@users.noreply.github.com> Date: Sun, 19 Nov 2023 22:28:25 +0100 Subject: [PATCH 1/2] Support for switchSupport --- openHAB.xcodeproj/project.pbxproj | 8 + openHAB/Main.storyboard | 150 ++++++++++++------ openHAB/OpenHABSitemapViewController.swift | 7 +- ...iderWithSwitchSupportUITableViewCell.swift | 137 ++++++++++++++++ openHABUITests/OpenHABUITests.swift | 2 +- .../Views/ContentView.swift | 4 +- .../Rows/SliderWithSwitchSupportRow.swift | 89 +++++++++++ 7 files changed, 348 insertions(+), 49 deletions(-) create mode 100644 openHAB/SliderWithSwitchSupportUITableViewCell.swift create mode 100644 openHABWatch Extension/Views/Rows/SliderWithSwitchSupportRow.swift diff --git a/openHAB.xcodeproj/project.pbxproj b/openHAB.xcodeproj/project.pbxproj index 02eae31fc..e69099782 100644 --- a/openHAB.xcodeproj/project.pbxproj +++ b/openHAB.xcodeproj/project.pbxproj @@ -92,6 +92,8 @@ DA2E0B0E23DCC153009B0A99 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2E0B0D23DCC152009B0A99 /* MapView.swift */; }; DA2E0B1023DCC439009B0A99 /* MapViewRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA2E0B0F23DCC439009B0A99 /* MapViewRow.swift */; }; DA4D4DB5233F9ACB00B37E37 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = DA4D4DB4233F9ACB00B37E37 /* README.md */; }; + DA50C7BD2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA50C7BC2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift */; }; + DA50C7BF2B0A65300009F716 /* SliderWithSwitchSupportUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA50C7BE2B0A652F0009F716 /* SliderWithSwitchSupportUITableViewCell.swift */; }; DA65871F236F83CE007E2E7F /* UserDefaultsExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA65871E236F83CD007E2E7F /* UserDefaultsExtension.swift */; }; DA6587222370C9D8007E2E7F /* PreferencesHostingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA6587212370C9D8007E2E7F /* PreferencesHostingController.swift */; }; DA7224D223828D3400712D20 /* PreviewConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA7224D123828D3300712D20 /* PreviewConstants.swift */; }; @@ -367,6 +369,8 @@ DA2E0B0F23DCC439009B0A99 /* MapViewRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapViewRow.swift; sourceTree = ""; }; DA4D4DB4233F9ACB00B37E37 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; DA4D4E0E2340A00200B37E37 /* Changes.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Changes.md; sourceTree = ""; }; + DA50C7BC2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderWithSwitchSupportRow.swift; sourceTree = ""; }; + DA50C7BE2B0A652F0009F716 /* SliderWithSwitchSupportUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderWithSwitchSupportUITableViewCell.swift; sourceTree = ""; }; DA65871E236F83CD007E2E7F /* UserDefaultsExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsExtension.swift; sourceTree = ""; }; DA6587212370C9D8007E2E7F /* PreferencesHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesHostingController.swift; sourceTree = ""; }; DA7224D123828D3300712D20 /* PreviewConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewConstants.swift; sourceTree = ""; }; @@ -757,6 +761,7 @@ children = ( DA077649234683BC0086C685 /* SwitchRow.swift */, DA0F37CF23D4ACC7007EAB48 /* SliderRow.swift */, + DA50C7BC2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift */, DAF457A123DB6C640018B495 /* RollershutterRow.swift */, DAF4579F23DA3E1C0018B495 /* SegmentRow.swift */, DAF457A523DB9CE00018B495 /* SetpointRow.swift */, @@ -850,6 +855,7 @@ DF05FF221896BD2D00FF2F9B /* SelectionUITableViewCell.swift */, DFA16EB718883CF300EDB0BB /* SetpointUITableViewCell.swift */, DFA16EBA18883DE500EDB0BB /* SliderUITableViewCell.swift */, + DA50C7BE2B0A652F0009F716 /* SliderWithSwitchSupportUITableViewCell.swift */, DFA13CB318872EBD006355C3 /* SwitchUITableViewCell.swift */, DAA42BA921DC983B00244B2A /* VideoUITableViewCell.swift */, DAA42BAB21DC984A00244B2A /* WebUITableViewCell.swift */, @@ -1350,6 +1356,7 @@ DA0776F0234788010086C685 /* UserData.swift in Sources */, DA6587222370C9D8007E2E7F /* PreferencesHostingController.swift in Sources */, DAC6608D236F771600F4501E /* PreferencesSwiftUIView.swift in Sources */, + DA50C7BD2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift in Sources */, DAF457A623DB9CE00018B495 /* SetpointRow.swift in Sources */, DAF4581823DC4A050018B495 /* ImageRow.swift in Sources */, 9350F17923814FAC00054BA8 /* ObservableOpenHABWidget.swift in Sources */, @@ -1395,6 +1402,7 @@ DF4B84041885A53700F34902 /* OpenHABDataObject.swift in Sources */, DAC65FC7236EDF3900F4501E /* SpinnerViewController.swift in Sources */, DF4A02421CF34096006C3456 /* OpenHABDrawerItem.swift in Sources */, + DA50C7BF2B0A65300009F716 /* SliderWithSwitchSupportUITableViewCell.swift in Sources */, DF4A022C1CF315BA006C3456 /* OpenHABDrawerTableViewController.swift in Sources */, DFDF452F1932032B00A6E581 /* OpenHABLegalViewController.swift in Sources */, DA21EAE22339621C001AB415 /* Throttler.swift in Sources */, diff --git a/openHAB/Main.storyboard b/openHAB/Main.storyboard index fd3790ea0..938cda96a 100644 --- a/openHAB/Main.storyboard +++ b/openHAB/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -392,9 +392,31 @@ - + + + + + + + + + + + + + + + + + + + + + + + @@ -476,28 +498,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -545,6 +545,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -567,7 +627,7 @@ - + @@ -1119,7 +1179,7 @@ - @@ -1338,6 +1336,7 @@ + @@ -1725,7 +1724,7 @@ - + diff --git a/openHABWatch Extension/Views/ContentView.swift b/openHABWatch Extension/Views/ContentView.swift index 988395f40..45fba2a97 100644 --- a/openHABWatch Extension/Views/ContentView.swift +++ b/openHABWatch Extension/Views/ContentView.swift @@ -65,7 +65,9 @@ struct ContentView: View { case .slider: if widget.switchSupport { SliderRow(widget: widget) - } else {} + } else { + SliderWithSwitchSupportRow(widget: widget) + } case .segmented: SegmentRow(widget: widget) case .rollershutter: diff --git a/openHABWatch Extension/Views/Rows/SliderWithSwitchSupportRow.swift b/openHABWatch Extension/Views/Rows/SliderWithSwitchSupportRow.swift index 3cd1b2336..1c82658ad 100644 --- a/openHABWatch Extension/Views/Rows/SliderWithSwitchSupportRow.swift +++ b/openHABWatch Extension/Views/Rows/SliderWithSwitchSupportRow.swift @@ -32,17 +32,20 @@ struct SliderWithSwitchSupportRow: View { let stateBinding = Binding( get: { - widget.stateEnumBinding.boolState + if widget.adjustedValue > widget.minValue { + true + } else { + false + } }, set: { if $0 { os_log("Switch to ON", log: .viewCycle, type: .info) - widget.sendCommand("ON") + widget.sendCommand(widget.maxValue.valueText(step: widget.step)) } else { os_log("Switch to OFF", log: .viewCycle, type: .info) - widget.sendCommand("OFF") + widget.sendCommand(widget.minValue.valueText(step: widget.step)) } - widget.stateEnumBinding = .switcher($0) } )