Hi, guys,
I am trying to write my own Device Handler, but I couldn’t fire an event with createEvent() in the parse().
Below is more information about the problem I met.
I am writing SmartAPPs and Device Handlers without a HUB.
The SmartAPPs are working, but some functions of Device Handlers are not.
I want to fire events in the Device Handlers.
If I used sendEvent() to do that, everything works fine.
The event is fired successfully (the events can be found in the event list of My Location in the IDE).
However, if I try to use createEvent() to fire the events.
The events were never fired since they didn’t show in the event list, and I also used a SmartApp to subscribe the event, the event handler was not triggered, either.
Could you guys tell me where I did wrong?
Thanks!
The codes are shown below.
/**
- Z-test-Switch
- Copyright 2018 B
- Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
- in compliance with the License. You may obtain a copy of the License at:
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- for the specific language governing permissions and limitations under the License.
*/
metadata {
definition (name: “Z-test-Switch”, namespace: “000000”, author: “B”) {
capability “Switch”
}
simulator {
// TODO: define status and reply messages here
}
tiles {
// TODO: define your main and details tiles here
}
}
// parse events into attributes
def parse(String description) {
log.debug “execute Parsing ‘${description}’”
def result = createEvent(name: “switch”, value: description)
result.each{k,v ->
log.debug “$k $v”
}
return result
}
// handle commands
def on() {
log.debug “Executing ‘on’”
parse(“on”)
}
def off() {
log.debug “Executing ‘off’”
parse(“off”)
}