Skip to content

Commit

Permalink
Add support for 'staticIcon' widget parameter
Browse files Browse the repository at this point in the history
If set, icon state should not be included when fetching the icon for a
given widget.

See openhab#3404

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Aug 31, 2023
1 parent 6016392 commit a3979dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ internal fun String?.toOH2WidgetIconResource(
state: ParsedState?,
item: Item?,
type: Widget.Type,
hasMappings: Boolean
hasMappings: Boolean,
useState: Boolean
): IconResource? {
if (isNullOrEmpty() || this == "none") {
return null
}

val itemState = item?.state
var iconState = state?.asString.orEmpty()
if (itemState != null) {
if (itemState != null && useState) {
if (item.isOfTypeOrGroupType(Item.Type.Color)) {
// For items that control a color item fetch the correct icon
if (type == Widget.Type.Slider || type == Widget.Type.Switch && !hasMappings) {
Expand Down
7 changes: 5 additions & 2 deletions mobile/src/main/java/org/openhab/habdroid/model/Widget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ data class Widget(
val item = Item.updateFromEvent(source.item, eventPayload.optJSONObject("item"))
val state = determineWidgetState(eventPayload.optStringOrNull("state"), item)
val iconName = eventPayload.optStringOrFallback("icon", source.icon?.icon)
val icon = iconName.toOH2WidgetIconResource(state, item, source.type, source.mappings.isNotEmpty())
val staticIcon = source.icon?.customState?.isEmpty() == true
val hasMappings = source.mappings.isNotEmpty()
val icon = iconName.toOH2WidgetIconResource(state, item, source.type, hasMappings, !staticIcon)
return Widget(
id = source.id,
parentId = source.parentId,
Expand Down Expand Up @@ -338,12 +340,13 @@ fun JSONObject.collectWidgets(parent: Widget?): List<Widget> {
val type = getString("type").toWidgetType()
val icon = optStringOrNull("icon")
val state = Widget.determineWidgetState(optStringOrNull("state"), item)
val staticIcon = optBoolean("staticIcon", false)

val widget = Widget(
id = getString("widgetId"),
parentId = parent?.id,
rawLabel = optString("label", ""),
icon = icon.toOH2WidgetIconResource(state, item, type, mappings.isNotEmpty()),
icon = icon.toOH2WidgetIconResource(state, item, type, mappings.isNotEmpty(), !staticIcon),
state = state,
type = type,
url = optStringOrNull("url"),
Expand Down

0 comments on commit a3979dd

Please sign in to comment.