-
Notifications
You must be signed in to change notification settings - Fork 522
Matter Camera: Only update profile if capabilities have changed #2686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,28 +120,51 @@ function CameraUtils.profile_changed(synced_components, prev_components) | |
| return false | ||
| end | ||
|
|
||
| function CameraUtils.optional_capabilities_list_changed(optional_capabilities, prev_component_list) | ||
| local prev_optional_capabilities = {} | ||
| for idx, comp in pairs(prev_component_list or {}) do | ||
| local cap_list = {} | ||
| for _, capability in pairs(comp.capabilities or {}) do | ||
| table.insert(cap_list, capability.id) | ||
| function CameraUtils.optional_capabilities_list_changed(new_component_capability_list, previous_component_capability_list) | ||
| local previous_capability_map = {} | ||
| local component_sizes = {} | ||
|
|
||
| local previous_component_count = 0 | ||
| for component_name, component in pairs(previous_component_capability_list or {}) do | ||
| previous_capability_map[component_name] = {} | ||
| component_sizes[component_name] = 0 | ||
| for _, capability in pairs(component.capabilities or {}) do | ||
| if capability.id ~= "firmwareUpdate" and capability.id ~= "refresh" then | ||
| previous_capability_map[component_name][capability.id] = true | ||
| component_sizes[component_name] = component_sizes[component_name] + 1 | ||
| end | ||
| end | ||
| table.insert(prev_optional_capabilities, {idx, cap_list}) | ||
| end | ||
| if #optional_capabilities ~= #prev_optional_capabilities then | ||
| return true | ||
| previous_component_count = previous_component_count + 1 | ||
| end | ||
| for _, capability in pairs(optional_capabilities or {}) do | ||
| if not switch_utils.tbl_contains(prev_optional_capabilities, capability) then | ||
|
|
||
| local number_of_components_counted = 0 | ||
| for _, new_component_capabilities in pairs(new_component_capability_list or {}) do | ||
| local component_name = new_component_capabilities[1] | ||
| local capability_list = new_component_capabilities[2] | ||
|
|
||
| number_of_components_counted = number_of_components_counted + 1 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, since this list is actually just a simple table that we know the structure of, we can just do and similar for the capabilities:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or maybe we don't even need to define them as variables in this case, and just call this directly as needed
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that but apparently it doesn't work for keyed tables. I didn't try very hard tho, so lemme see if it'll work
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah my bad, that's true. I forgot about that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, ins't the |
||
|
|
||
| if not previous_capability_map[component_name] then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit but can we do |
||
| return true | ||
| end | ||
| end | ||
| for _, capability in pairs(prev_optional_capabilities or {}) do | ||
| if not switch_utils.tbl_contains(optional_capabilities, capability) then | ||
|
|
||
| local capabilities_in_component = 0 | ||
| for _, capability in ipairs(capability_list) do | ||
| if not previous_capability_map[component_name][capability] then | ||
| return true | ||
| end | ||
| capabilities_in_component = capabilities_in_component + 1 | ||
| end | ||
|
|
||
| if capabilities_in_component ~= component_sizes[component_name] then | ||
| return true | ||
| end | ||
| end | ||
|
|
||
| if number_of_components_counted ~= previous_component_count then | ||
| return true | ||
| end | ||
|
|
||
| return false | ||
| end | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
button config can be put behind the
optional_capabilities_list_changedgate so it doesn't run each timeCameraAvStreamManagement.AttributeListis received.