I would like to test this code:
In other words, I would like to make sure these commands (lines 74 and 76) were called at “init” device lifecycle.
So I created this test: (currently, commented out)
Without the comments, I receive this error:
TRACE || Zigbee Device: 00000000-1111-2222-3333-000000000001
Manufacturer: single_switch Model: single_switch
[1]: Basic, OnOff
DEBUG || driver device thread event handled
TRACE || Received event with handler _resync
TRACE || Found DeviceLifecycleDispatcher handler in default-clusters
INFO || <ZigbeeDevice: 00000000-1111-2222-3333-000000000001 [0x0001]> sending Zigbee message: < ZigbeeMessageTx || Uint16: 0x0000, < AddressHeader || src_addr: 0x0000, src_endpoint: 0x01, dest_addr: 0x0001, dest_endpoint: 0x01, profile: 0x0104, cluster: Basic >, < ZCLMessageBody || < ZCLHeader || frame_ctrl: 0x00, seqno: 0x00, ZCLCommandId: 0x00 >, < ReadAttribute || AttributeId: 0x0004, AttributeId: 0x0000, AttributeId: 0x0001, AttributeId: 0x0005, AttributeId: 0x0007, AttributeId: 0xFFFE > > >
Failed with message:
Zigbee message channel send was given unexpected message:
ZigbeeMessageTx:
Uint16: 0x0000
AddressHeader:
src_addr: 0x0000
src_endpoint: 0x01
dest_addr: 0x0001
dest_endpoint: 0x01
profile: 0x0104
cluster: Basic
ZCLMessageBody:
ZCLHeader:
frame_ctrl: 0x00
seqno: 0x00
ZCLCommandId: 0x00
ReadAttribute:
AttributeId: 0x0004
AttributeId: 0x0000
AttributeId: 0x0001
AttributeId: 0x0005
AttributeId: 0x0007
AttributeId: 0xFFFE
FAILED
I understood the error happened because utils.spell_magic_trick(device)
was caught before “init” lifecycle ended.
The current implementation of test.register_message_test
requires I inform a “receive” message first before 0 or more “send” messages.
So my question: How can I create a test to make sure these commands are being called at “init” lifecycle ?