-
Notifications
You must be signed in to change notification settings - Fork 516
Matter Switch: Attempt re-profiling on device software updates #2466
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
Open
hcarter-775
wants to merge
6
commits into
main
Choose a base branch
from
switch-allow-reprofiling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
07cf40e
Add greater dynamic profiling to matter switch
hcarter-775 da4a05f
remove unused function
hcarter-775 eda1721
re-profile device if a matter_version update occurs
hcarter-775 4216332
improve configure_buttons api
hcarter-775 e87df60
remove extra comment
hcarter-775 d6fc0b4
update logic to avoid crashes
hcarter-775 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ local fields = require "utils.switch_fields" | |
| local switch_utils = require "utils.switch_utils" | ||
| local cfg = require "utils.device_configuration" | ||
| local device_cfg = cfg.DeviceCfg | ||
| local switch_cfg = cfg.SwitchCfg | ||
| local button_cfg = cfg.ButtonCfg | ||
|
|
||
| local attribute_handlers = require "generic_handlers.attribute_handlers" | ||
|
|
@@ -65,16 +64,21 @@ end | |
|
|
||
| function SwitchLifecycleHandlers.info_changed(driver, device, event, args) | ||
| if device.profile.id ~= args.old_st_store.profile.id then | ||
| device:subscribe() | ||
| local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH}) | ||
| if #button_eps > 0 and device.network_type == device_lib.NETWORK_TYPE_MATTER then | ||
| button_cfg.configure_buttons(device) | ||
| if device.network_type == device_lib.NETWORK_TYPE_MATTER then | ||
| device:subscribe() | ||
| button_cfg.configure_buttons(device, | ||
| device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH}) | ||
| ) | ||
| elseif device.network_type == device_lib.NETWORK_TYPE_CHILD then | ||
| switch_utils.update_subscriptions(device:get_parent_device()) -- parent device required to scan through EPs and update subscriptions | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function SwitchLifecycleHandlers.device_removed(driver, device) | ||
| device.log.info("device removed") | ||
| if device.network_type == device_lib.NETWORK_TYPE_MATTER and not switch_utils.detect_bridge(device) then | ||
| if device.matter_version.software ~= args.old_st_store.matter_version.software then | ||
| device_cfg.match_profile(driver, device) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function SwitchLifecycleHandlers.device_init(driver, device) | ||
|
|
@@ -85,33 +89,7 @@ function SwitchLifecycleHandlers.device_init(driver, device) | |
| if device:get_field(fields.IS_PARENT_CHILD_DEVICE) then | ||
| device:set_find_child(switch_utils.find_child) | ||
| end | ||
| local main_endpoint = switch_utils.find_default_endpoint(device) | ||
| -- ensure subscription to all endpoint attributes- including those mapped to child devices | ||
| for idx, ep in ipairs(device.endpoints) do | ||
| if ep.endpoint_id ~= main_endpoint then | ||
| if device:supports_server_cluster(clusters.OnOff.ID, ep) then | ||
| local child_profile = switch_cfg.assign_child_profile(device, ep) | ||
| if idx == 1 and string.find(child_profile, "energy") then | ||
| -- when energy management is defined in the root endpoint(0), replace it with the first switch endpoint and process it. | ||
| device:set_field(fields.ENERGY_MANAGEMENT_ENDPOINT, ep, {persist = true}) | ||
| end | ||
| end | ||
| local id = 0 | ||
| for _, dt in ipairs(ep.device_types) do | ||
| id = math.max(id, dt.device_type_id) | ||
| end | ||
| for _, attr in pairs(fields.device_type_attribute_map[id] or {}) do | ||
| if id == fields.GENERIC_SWITCH_ID and | ||
| attr ~= clusters.PowerSource.attributes.BatPercentRemaining and | ||
| attr ~= clusters.PowerSource.attributes.BatChargeLevel then | ||
| device:add_subscribed_event(attr) | ||
| else | ||
| device:add_subscribed_attribute(attr) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| device:subscribe() | ||
| switch_utils.update_subscriptions(device) | ||
|
|
||
| -- device energy reporting must be handled cumulatively, periodically, or by both simulatanously. | ||
| -- To ensure a single source of truth, we only handle a device's periodic reporting if cumulative reporting is not supported. | ||
|
|
@@ -127,6 +105,10 @@ function SwitchLifecycleHandlers.device_init(driver, device) | |
| end | ||
| end | ||
|
|
||
| function SwitchLifecycleHandlers.device_removed(driver, device) | ||
|
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 just moved this to the bottom of the file. We never touch this and I personally am always getting confused where device_init is when developing with this placed above it. |
||
| device.log.info("device removed") | ||
| end | ||
|
|
||
| local matter_driver_template = { | ||
| lifecycle_handlers = { | ||
| added = SwitchLifecycleHandlers.device_added, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is the checking for button support done inside
button_cfg?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.
yes, this function will be a no-op if there are no button-mappable endpoints. So I could revert it, but it removes an extra check. Maybe this adds confusion though?
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.
thought about this more, and I improved the api by having the caller pass in the endpoints that will be mapped, still cutting out the extra check while keeping this clarity