-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Make BT support detection dynamic for Shelly RPC devices #137323
base: dev
Are you sure you want to change the base?
Make BT support detection dynamic for Shelly RPC devices #137323
Conversation
Hey there @balloob, @bieniu, @thecode, @bdraco, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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.
The approach looks good, left some comments
@@ -460,7 +483,7 @@ def async_supports_options_flow(cls, config_entry: ConfigEntry) -> bool: | |||
return ( | |||
get_device_entry_gen(config_entry) in RPC_GENERATIONS | |||
and not config_entry.data.get(CONF_SLEEP_PERIOD) | |||
and config_entry.data.get("model") != MODEL_WALL_DISPLAY | |||
and config_entry.data.get(CONF_SCRIPT, True) |
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.
We need the config_entry.data.get("model") != MODEL_WALL_DISPLAY
condition here in addition, the update of the entry data will happen after this is evaluated and will be incorrect
# Model Wall Display does not support scripts | ||
# even if Script.List method is available | ||
if device.model == MODEL_WALL_DISPLAY: | ||
return False | ||
|
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.
# Model Wall Display does not support scripts | |
# even if Script.List method is available | |
if device.model == MODEL_WALL_DISPLAY: | |
return False |
if entry.data.get(CONF_MODEL) == MODEL_WALL_DISPLAY and not entry.data.get( | ||
CONF_SCRIPT | ||
): | ||
data = {**entry.data} | ||
data[CONF_SCRIPT] = False | ||
hass.config_entries.async_update_entry(entry, data=data) | ||
|
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.
This will happen only after the config flow has already evaluated the condition if options are allowed or not and is not effective until device is reloaded, I also think it just complicates the PR, PR was already ready with a very simple solution, why do we need to complicate it?
if entry.data.get(CONF_MODEL) == MODEL_WALL_DISPLAY and not entry.data.get( | |
CONF_SCRIPT | |
): | |
data = {**entry.data} | |
data[CONF_SCRIPT] = False | |
hass.config_entries.async_update_entry(entry, data=data) |
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.
I think that if we store for other devices the info of script=False
and we know a device should be listed, we should update it.
The best option is indeed to migrate the config entry.
But I applied the same we did for the wrong sleep period.
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.
but as I explained it won't work for the first time as the device will load with the older value, this also makes a simple PR complicated, I already tested and validated a very simple solution (which you created) and now we complicate it. It would also mean we need to add tests for the migration of the data
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
@@ -460,7 +483,7 @@ def async_supports_options_flow(cls, config_entry: ConfigEntry) -> bool: | |||
return ( | |||
get_device_entry_gen(config_entry) in RPC_GENERATIONS | |||
and not config_entry.data.get(CONF_SLEEP_PERIOD) | |||
and config_entry.data.get("model") != MODEL_WALL_DISPLAY | |||
and config_entry.data.get(CONF_SCRIPT, True) |
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.
and config_entry.data.get(CONF_SCRIPT, True) | |
and config_entry.data.get(CONF_SCRIPT, True) | |
and config_entry.data.get("model") != MODEL_WALL_DISPLAY |
Coding completed and tested in all variations I was able to. |
Proposed change
Some devices, even if gen2+, has support for BT but not for scripts.
With the introduction of XMOD devices, "model" is no more reliable for such detection.
This PR test for the real capability so that is no more linked to a static list of devices.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: