Can somebody provide an example how to define a ToggleAction?
The only example I found is a Fader that has multiple properties but how do i implement an action without properties like a ToggleAction?
Am i looking at the right source for docs about the schemas for development?
The @type
field, which refers to the schemas, is totally optional, so you can just omit that. Similarly, the input object is optional. You’d want to do something like this:
thing.add_available_action(
'toggle',
{
'title': 'Toggle',
'description': 'Toggle something',
'input': {},
},
ToggleAction
)
I get an unexpected visual interface. It looks like this node called “digitalSwitch”
If I press it, it opens to this:
What I expected is a button that does nothing visual. In Background, it sends a
True
or something I can work with…Am I doing something wrong?
i tried with and without the @type
statment.
self.add_available_action('digitalSwitch',
{
'@type': 'ToggleAction',
'title': 'digitalSwitch',
'description': 'Toggle the Led Strip on or off',
'input': {},
},
ToggleDigitalSwitch)
I found it.
Deleted the input:{} then it toggles. Had also to figure out that perform_action(self)
is a magic word.
so as a solution to others coming across this:
class ToggleDigitalSwitch(Action):
def __init__(self, thing, input_):
Action.__init__(self, uuid.uuid4().hex, thing, 'state', input_=input_)
logging.debug("ToggleDigitalSwitch.__init__ - gets printed to log")
def toggle_digitalSwitch(self):
logging.debug("ToggleDigitalSwitch.toggle_digitalSwitch - does not get printed")
pass
def perform_action(self):
logging.debug("ToggleDigitalSwitch.perform_action - will magicaly get printed to log")
perform_action
gets hit while my self-writen function toggle_digitalSwitch
does not.
…and the UI Button will be created by this part inside the Thing
definition:
self.add_available_action('digitalSwitch',
{
'@type': 'ToggleAction',
'title': 'digitalSwitch',
'description': 'Toggle the Led Strip on or off',
},ToggleDigitalSwitch)