light.tplink: initialize supported features in setup_platform#15534
light.tplink: initialize supported features in setup_platform#15534rytilahti wants to merge 1 commit intohome-assistant:devfrom
Conversation
| name = config.get(CONF_NAME) | ||
| add_devices([TPLinkSmartBulb(SmartBulb(host), name)], True) | ||
| bulb = TPLinkSmartBulb(SmartBulb(host), name) | ||
| bulb.get_features() |
There was a problem hiding this comment.
Why not keep this call inside the TPLinkSmartBulb class?
There was a problem hiding this comment.
Because I/O is not allowed inside constructor, and if those features are not set min_mireds may be called before there an initial update has happened. Or that's my understanding at least.
There was a problem hiding this comment.
In async_update_ha_state the call to update will be done before any entity properties are accessed. I propose to revert all changes except on line 45, which will make sure that update is called before the first state update, and that supported features should be up to date.
There was a problem hiding this comment.
Hmm, if that's the case, there's then no need for this PR at all actually and the problem itself should have been fixed by #15484, as the second parameter was True already.
Description:
Fetch supported features already in setup_platform, avoids calling
{min,max}_minreds(thanks to #15484 ) causing a zerodivisionerror on bulbs not supporting temperature changing.Related issue (if applicable): fixes #15339
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: