Skip to content

Support battery powered Matter cameras - #3314

Open
samadDotDev wants to merge 2 commits into
mainfrom
camera-battery
Open

samadDotDev wants to merge 2 commits into
mainfrom
camera-battery

Conversation

@samadDotDev

Copy link
Copy Markdown
Contributor

Description of Change

In order to support battery powered Matter Cameras, we need to add these 3 capabilities to the profile:

  • battery (to expose battery %)
  • batteryLevel (to expose levels such as "critical", "warning" and "normal", when the % isn't supported)
  • chargingState (for cameras with rechargeable batteries, which is almost always the case)

All 3 were added based on feature map and attributes list in Power source cluster. These have been tested with their state updates (so critical level or low % results in a notification, and the % is shown in the top-right corner of live-view player) as well as conditions of automation (e.g., a user can setup notification when camera charging is complete if unmounted etc)

Note that we only expose % capability when camera supports both % and level for the battery. This is to remain consistent with our existing usages in other Matter drivers, but it should be re-evaluated given that level has device/battery-subjective thresholds (which can vary depending on battery chemistry).

Summary of Completed Tests

  • Added unit tests that cover the 3 capabilities in various combinations
  • Self-tested with a mock device
  • Partner tested with an actual battery powered camera

@samadDotDev samadDotDev added AIReview CGAI Contains code that was generated by AI labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown

Profile category check: ✅ Passed - all profiles have a category defined.

@github-actions

Copy link
Copy Markdown

Duplicate profile check: Passed - no duplicate profiles detected.

@github-actions

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Test Results

   73 files    545 suites   0s ⏱️
3 334 tests 3 334 ✅ 0 💤 0 ❌
5 334 runs  5 334 ✅ 0 💤 0 ❌

Results for commit 7c748c7.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

matter-switch_coverage.xml

File Coverage
All files 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_utils/event_utils.lua 52% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/init.lua 90% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/hager/init.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/utils.lua 98% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_utils/device_configuration.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/event_handlers.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/capability_handlers.lua 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_handlers/attribute_handlers.lua 81% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/capability_handlers.lua 83% ❌
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/camera_handlers/attribute_handlers.lua 96% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/utils.lua 92% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/switch_utils/device_configuration.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/eve_energy/init.lua 91% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/third_reality_mk1/init.lua 93% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/aqara_cube/init.lua 95% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/third_reality_garage_door/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/camera/init.lua 97% ✅
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/matter-switch/src/sub_drivers/ikea_scroll/scroll_handlers/event_handlers.lua 75% ❌

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 7c748c7

@Kwang-Hui

Copy link
Copy Markdown
Contributor

Question on power_source_attribute_list_handler:
Can a battery-powered camera expose multiple PowerSource clusters across different endpoints (e.g., one for wired/USB power and another for the battery)? If so, is there any chance that AttributeList reports arriving from different endpoints could race and overwrite BAT_PERCENT_REMAINING_PRESENT / BAT_CHARGE_LEVEL_PRESENT back to false?

@samadDotDev

Copy link
Copy Markdown
Contributor Author

Question on power_source_attribute_list_handler: Can a battery-powered camera expose multiple PowerSource clusters across different endpoints (e.g., one for wired/USB power and another for the battery)? If so, is there any chance that AttributeList reports arriving from different endpoints could race and overwrite BAT_PERCENT_REMAINING_PRESENT / BAT_CHARGE_LEVEL_PRESENT back to false?

Good question and valid concern! There can be multiple instances of power source cluster indeed, per spec

In case the node has multiple power sources, each SHALL be described by its own cluster instance. Each instance of this cluster MAY be associated with one or more endpoints or the entire node.

I have added that handling in 7c748c7

@Kwang-Hui Kwang-Hui left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

function CameraAttributeHandlers.bat_charge_state_handler(driver, device, ib, response)
local state = camera_fields.BAT_CHARGE_STATE_MAP[ib.data.value]
if state then
device:emit_event_for_endpoint(ib, capabilities.chargingState.chargingState[state]())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
device:emit_event_for_endpoint(ib, capabilities.chargingState.chargingState[state]())
device:emit_event_for_endpoint(ib, capabilities.chargingState.chargingState(state))

nit, but this is the syntax we use for everything else, so maybe we leave that here as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIReview CGAI Contains code that was generated by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants