Skip to content

Commit

Permalink
Merge branch 'develop' into diffable
Browse files Browse the repository at this point in the history
  • Loading branch information
timbms authored Jan 9, 2024
2 parents 2b1febc + 50b6898 commit d2762f1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Prefer commandDescription options over stateDescription options if an item has them

## [Version 2.4.59, Build 1580410537] - 2023-08-19Z

- Implement iconify icons
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2010-2023 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 Foundation

public class OpenHABCommandDescription {
public var commandOptions: [OpenHABCommandOptions] = []

init(commandOptions: [OpenHABCommandOptions]?) {
self.commandOptions = commandOptions ?? []
}
}

public extension OpenHABCommandDescription {
struct CodingData: Decodable {
let commandOptions: [OpenHABCommandOptions]?
}
}

extension OpenHABCommandDescription.CodingData {
var openHABCommandDescription: OpenHABCommandDescription {
OpenHABCommandDescription(commandOptions: commandOptions)
}
}
17 changes: 17 additions & 0 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABCommandOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2010-2023 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 Foundation

public class OpenHABCommandOptions: Decodable {
public var command = ""
public var label = ""
}
7 changes: 5 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public final class OpenHABItem: NSObject, CommItem {
public var link = ""
public var label = ""
public var stateDescription: OpenHABStateDescription?
public var commandDescription: OpenHABCommandDescription?
public var readOnly = false
public var members: [OpenHABItem] = []
public var category = ""
Expand All @@ -52,7 +53,7 @@ public final class OpenHABItem: NSObject, CommItem {
isOfTypeOrGroupType(ItemType.player)
}

public init(name: String, type: String, state: String?, link: String, label: String?, groupType: String?, stateDescription: OpenHABStateDescription?, members: [OpenHABItem], category: String?, options: [OpenHABOptions]?) {
public init(name: String, type: String, state: String?, link: String, label: String?, groupType: String?, stateDescription: OpenHABStateDescription?, commandDescription: OpenHABCommandDescription?, members: [OpenHABItem], category: String?, options: [OpenHABOptions]?) {
self.name = name
self.type = type.toItemType()
if let state, state == "NULL" || state == "UNDEF" || state.caseInsensitiveCompare("undefined") == .orderedSame {
Expand All @@ -64,6 +65,7 @@ public final class OpenHABItem: NSObject, CommItem {
self.label = label.orEmpty
self.groupType = groupType?.toItemType()
self.stateDescription = stateDescription
self.commandDescription = commandDescription
readOnly = stateDescription?.readOnly ?? false
self.members = members
self.category = category.orEmpty
Expand Down Expand Up @@ -146,6 +148,7 @@ public extension OpenHABItem {
let state: String?
let label: String?
let stateDescription: OpenHABStateDescription.CodingData?
let commandDescription: OpenHABCommandDescription.CodingData?
let members: [OpenHABItem.CodingData]?
let category: String?
let options: [OpenHABOptions]?
Expand All @@ -156,7 +159,7 @@ public extension OpenHABItem.CodingData {
var openHABItem: OpenHABItem {
let mappedMembers = members?.map(\.openHABItem) ?? []

return OpenHABItem(name: name, type: type, state: state, link: link, label: label, groupType: groupType, stateDescription: stateDescription?.openHABStateDescription, members: mappedMembers, category: category, options: options)
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)
}
}

Expand Down
6 changes: 4 additions & 2 deletions OpenHABCore/Sources/OpenHABCore/Model/OpenHABWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ public class OpenHABWidget: NSObject, MKAnnotation, Identifiable {
}

public var mappingsOrItemOptions: [OpenHABWidgetMapping] {
if mappings.isEmpty, let itemOptions = item?.stateDescription?.options {
itemOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) }
if mappings.isEmpty, let commandOptions = item?.commandDescription?.commandOptions {
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 {
mappings
}
Expand Down
15 changes: 14 additions & 1 deletion OpenHABCore/Sources/OpenHABCore/Util/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,22 @@ public extension Endpoint {
icon = components[2]
} else if components.count == 2 {
source = components[0]
set = "classic"
if source == "material" {
set = "baseline"
} else {
set = "classic"
}
icon = components[1]
}
if source == "material" {
source = "iconify"
icon = "\(set)-\(icon)"
set = "ic"
}
if source == "f7" {
source = "iconify"
set = "f7"
}
if source == "if" || source == "iconify" {
queryItems = [URLQueryItem(name: "height", value: "64")]
if !iconColor.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ class ObservableOpenHABWidget: NSObject, MKAnnotation, Identifiable, ObservableO
}

var mappingsOrItemOptions: [OpenHABWidgetMapping] {
if mappings.isEmpty, let itemOptions = item?.stateDescription?.options {
itemOptions.map { OpenHABWidgetMapping(command: $0.value, label: $0.label) }
if mappings.isEmpty, let commandOptions = item?.commandDescription?.commandOptions {
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 {
mappings
}
Expand Down

0 comments on commit d2762f1

Please sign in to comment.