-
Notifications
You must be signed in to change notification settings - Fork 302
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
fix: process include/exclude devices #2478
fix: process include/exclude devices #2478
Conversation
Process `include_devices` and `exclude_devices` strings as CSV lists.
for more information, see https://pre-commit.ci
Something has changed. Those should already be lists. Not strings. The ingestion step should already convert them from strings. |
I've noticed that the code uses if include and dev_name not in include.splt(","): and if exclude and dev_name in exclude.splt(","): Just to clarify, is this intentional or could it be a typo, possibly due to a copy/paste error? I'm asking because Thanks! |
With the assistance of ChatGPT, I believe I've identified the root cause of the issue: Potential Issue in There is a potential problem in the way the Explanation:
Recommendation:Avoid converting lists into comma-separated strings using |
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.
There is a typo in split(). But I wouldn't apply the fix here, since in this case you would change the expected type to string instead of a list, which goes against the rest of the code (i.e, the function you changed expects an Optional[list[str]], not a Optional[str]. If you think this is the proper way, I'd change the rest of the code to conform to this change.
Instead, I'd just apply the fix inside save_user_input_to_config() at config_flow.py so that instead of transforming config[CONF...] insto a str, it keeps it as a list.
So this is probably worth checking as these were the prior assumptions:
If any of these have been broken, then they need to be fixed. This also suggests the proposed fix here is also incorrect since it breaks 3. Let's plan to close this after a few days unless your investigation shows that assumptions are wrong. |
Sorry, I've been busy today with 8 hours of landscaping work to make some $$$, and my body is not used to physical labor any more! @jleinenbach Yes, it's a stupid typo but not due to copy/paste error, instead a failure to use copy/paste and attempt to type such a small change correctly, and fail! @alandtse, @chrisvblemos I read the comments this morning and went back though AMP's version history until I found mention of UI config and that was v2.0.0. I downloaded it and saw this in config_flow.py: Line 140
Lines 163-178:
They used to be stored back then as lists in the .storage location and at some point over the years were changed to strings. |
I'm not seeing that in 4.12.8 or 4.10.3, which is before my Options feat change so I'm sure now I did not break it and think this has been a longstanding unnoticed possible failure point, which my particular setup has just now revealed. Or it may have been encountered before but never reported? In
So if I am to obey point #3, then it looks like the fix should be applied at lines 1266,1267? Is |
Make sure you understand fully how exclude/include work as that confuses people. That said, make sure that the behavior with empty lists is sane. For include, it used to ignore an empty list. If you've modified the code and it actually tries to process an empty list, then nothing will be included since they're not explicitly allowed. Exclude should not have that issue at all as it's a ban list and an empty list shouldn't ban anything. |
@alandtse Yes, I understand how exclude/include work.
Debugging tells me
I was thinking of that but that would seem to go against Alan's three assumptions. My original (rejected) fix works and after spending another 5 hours on this, the only other way I see to solve it is:
|
@chrisvblemos
but it continues to save the config entry in I don't know why the integration changed from lists to strings for these parameters sometime between v2.0.0 and now. I'm going to leave it you guys to figure out the best fix. Once you do, I can amend my PR with your recommended changes or, you can submit a new PR to fix my issue and I'll close this one. But I am done trying to wrap my my head around everything for now. Maybe in 3-6 months after I've readjusted my life, I can resume doing what I love doing... |
Thanks again for all you help. Good luck with your IRL stuff! |
Convert include/exclude strings to lists at point of ingestion.
Fix syntax error line 1257
Process
include_devices
andexclude_devices
strings as CSV lists.Fixes issue #2477