I copied and modified widget code from the demo site, but it doesn’t do what I want.
When the switch item is ON I want to change the background color and the text active in the footer
I probably made a typo, but I don’t see what’s wrong
uid: Scene_button
tags: []
props:
parameters:
- description: Scene name
label: Scene name
name: SceneName
required: false
type: TEXT
- description: Name of the Icon (see https://framework7.io/icons/ for available icons)
label: F7 Icon
name: icon
required: true
type: TEXT
- description: Color scheme for icons and toggles (see https://framework7.io/docs/color-themes.html for available color schemes)
label: Color
name: color
required: true
type: TEXT
- context: item
description: Scene switch item
label: Item
name: SceneSwitch
required: false
type: TEXT
parameterGroups: []
timestamp: May 16, 2021, 8:25:52 PM
component: oh-cell
config:
header: Activate scene
title: =props.SceneName
footer: "=props.SceneSwitch.state == ON ? 'Active' : ''"
icon: =props.icon
on: true
background-color: =props.SceneSwitch.state == ON ? 'blue' :'gray'
action: command
actionItem: =props.SceneSwitch
actionCommand: ON
props.SceneName is just a string of the item name so it doesn’t have a state property. In both those cases you’ll need to use the items dict that takes item name string as a key and returns the state (or display state if you want):
items[props.SceneName].state
Also, in the background-color line you’ll need to put quotes around the expression again or the : will confuse the parser.
=== checks for equality of value and type. == checks for equality of value making some sensible type changes as required. So, in scripting in OH item.state === "ON" will not work because ON, the state returned from the item itself, is one of the OH state types and "ON" is a string. On the other hand, item.state == "ON" will work because toString() can be called on OH state types to cast them to strings.
In the case of widgets, however, both work. The state values in the items dict are not state types but have already been retrieved from the api as strings so items[props.SceneSwitch].state === "ON" is comparing a string type to a string type.