SmartThingsEdgeDrivers icon indicating copy to clipboard operation
SmartThingsEdgeDrivers copied to clipboard

Eve Energy: fix can handle and get switch state on child add

Open ctowns opened this issue 1 year ago • 4 comments

When a child device is added, request the switch state. This is done to account for a race condition where a subscription report arrives before the child device has been created and the child device misses the initial state.

ctowns avatar Feb 22 '24 17:02 ctowns

Test Results

   55 files    352 suites   0s :stopwatch: 1 646 tests 1 646 :white_check_mark: 0 :zzz: 0 :x: 2 891 runs  2 891 :white_check_mark: 0 :zzz: 0 :x:

Results for commit efa454bc.

:recycle: This comment has been updated with latest results.

github-actions[bot] avatar Feb 22 '24 17:02 github-actions[bot]

Invitation URL: https://bestow-regional.api.smartthings.com/invite/Boj0oxzOdlAw

github-actions[bot] avatar Feb 22 '24 17:02 github-actions[bot]

File Coverage
All files 94% :white_check_mark:
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 93% :white_check_mark:
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/eve-energy/init.lua 93% :white_check_mark:

Minimum allowed coverage is 90%

Generated by :monkey: cobertura-action against efa454bc5f3661743f97acdac562728ea1ff910f

github-actions[bot] avatar Feb 22 '24 17:02 github-actions[bot]

@greens Good call out on the test - I wrote a test to check this in the sub driver and this revealed that the can_handle check for the sub driver was failing for child devices. This means the added event was actually defaulting to being handled by the parent driver.

Technically, this means that this PR or https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/pull/1213 could address the child initial refresh issue since this creates an added handler in the parent driver, which would be used by child devices in this driver when the can_handle function fails. However, it would be better fix the can_handle function as I have done here. My only concern is that it may not be safe to call the get_parent_device function in the can_handle function due to race conditions on device creation. Tomorrow I will confirm that it is safe to call get_parent_device() in the can_handle() function, and if it is we can merge this PR after it has been tested with a real device.

ctowns avatar Feb 23 '24 07:02 ctowns