From 46c361093ce622384f092a6f9fb53dd3068a3e29 Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Mon, 9 Sep 2024 14:51:26 -0700 Subject: [PATCH] Make label optional in command items (#805) Fixes #803 Fixes #792 Signed-off-by: Dan Cunningham --- .../Sources/OpenHABCore/Model/OpenHABCommandOptions.swift | 2 +- OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift | 2 +- openHAB/OpenHABSitemapViewController.swift | 5 +++++ .../Model/ObservableOpenHABWidget.swift | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenHABCore/Sources/OpenHABCore/Model/OpenHABCommandOptions.swift b/OpenHABCore/Sources/OpenHABCore/Model/OpenHABCommandOptions.swift index 5484d214..1e610277 100644 --- a/OpenHABCore/Sources/OpenHABCore/Model/OpenHABCommandOptions.swift +++ b/OpenHABCore/Sources/OpenHABCore/Model/OpenHABCommandOptions.swift @@ -13,5 +13,5 @@ import Foundation public class OpenHABCommandOptions: Decodable { public var command = "" - public var label = "" + public var label: String? = "" } diff --git a/OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift b/OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift index b881bd56..f0fe5511 100644 --- a/OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift +++ b/OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift @@ -118,7 +118,7 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable { public var mappingsOrItemOptions: [OpenHABWidgetMapping] { if mappings.isEmpty, let commandOptions = item?.commandDescription?.commandOptions { - commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label) } + commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label ?? "") } } else if mappings.isEmpty, let stateOptions = item?.stateDescription?.options { stateOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) } } else { diff --git a/openHAB/OpenHABSitemapViewController.swift b/openHAB/OpenHABSitemapViewController.swift index c0a329d6..37926003 100644 --- a/openHAB/OpenHABSitemapViewController.swift +++ b/openHAB/OpenHABSitemapViewController.swift @@ -341,7 +341,12 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel return sitemapPageCodingData.openHABSitemapPage }() } catch { + //Printing the error is the only way to actually get the real issue, localizedDescription is pretty useless here + print(error) os_log("Should not throw %{PUBLIC}@", log: OSLog.remoteAccess, type: .error, error.localizedDescription) + DispatchQueue.main.async { + self.showPopupMessage(seconds: 5, title: NSLocalizedString("error", comment: ""), message: error.localizedDescription, theme: .error) + } } currentPage = openHABSitemapPage diff --git a/openHABWatch Extension/openHABWatch Extension/Model/ObservableOpenHABWidget.swift b/openHABWatch Extension/openHABWatch Extension/Model/ObservableOpenHABWidget.swift index 8e0c798b..051ea2e2 100644 --- a/openHABWatch Extension/openHABWatch Extension/Model/ObservableOpenHABWidget.swift +++ b/openHABWatch Extension/openHABWatch Extension/Model/ObservableOpenHABWidget.swift @@ -95,7 +95,7 @@ class ObservableOpenHABWidget: NSObject, MKAnnotation, Identifiable, ObservableO var mappingsOrItemOptions: [OpenHABWidgetMapping] { if mappings.isEmpty, let commandOptions = item?.commandDescription?.commandOptions { - commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label) } + commandOptions.map { OpenHABWidgetMapping(command: $0.command, label: $0.label ?? "") } } else if mappings.isEmpty, let stateOptions = item?.stateDescription?.options { stateOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) } } else {