-
-
Notifications
You must be signed in to change notification settings - Fork 30.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
Add options to SelectEntityDescription #78882
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
@@ -72,6 +72,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |||
class SelectEntityDescription(EntityDescription): | |||
"""A class that describes select entities.""" | |||
|
|||
options: list[str] | UndefinedType = UNDEFINED |
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.
Can we skip the UndefinedType
to make it easier with type checking in all the platforms that use this description attribute? UNDEFINED
is just needed here in the integration to make it optional with a default.
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.
Done, using type: ignore
@@ -25,7 +25,7 @@ class PlugwiseSelectDescriptionMixin: | |||
|
|||
command: Callable[[Smile, str, str], Awaitable[Any]] | |||
current_option: str | |||
options: str | |||
options_key: str |
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 risk of breaking change for components that have the options
key already defined.
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 should perhaps make a dev blog, and search HACS for matches?
@@ -72,6 +72,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |||
class SelectEntityDescription(EntityDescription): | |||
"""A class that describes select entities.""" | |||
|
|||
options: list[str] | UndefinedType = UNDEFINED |
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.
Done, using type: ignore
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.
@frenck what do you think?
@@ -72,6 +72,8 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |||
class SelectEntityDescription(EntityDescription): | |||
"""A class that describes select entities.""" | |||
|
|||
options: list[str] = UNDEFINED # type: ignore[assignment] |
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 feels way too hacky for my taste (messing with the typing that is).
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.
It's convenience. Same reason why we ignore type for hass
in Entity
.
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.
What we do in hass
is a very exceptional case.
In this case, options
cannot be None
, so we don't need to use sentinel values.
As in: We don't need to "hacky" around it or use typing exceptions to make this work nicely.
options: list[str] = UNDEFINED # type: ignore[assignment] | |
options: list[str] | None = None |
EDIT: this comment looks weird, as its shown as part of a review, there is more context above. This was original a response to Martin.
I'm kinda lost on why we do this? (Motivation? SSIA doesn't help in this case). Adding this level of things to the entity descriptions by default, opens up a can of worms we originally avoided. For example, effects in lights, HVAC modes and many others. It could be fine to implement those as well, but I think it should be consistent if we do that (and not just one off). |
I have adjusted the PR description. It originated from #78873 (comment) |
We already use the descriptions for many different kind of attributes in the implementing integrations. I don't think the can of worms is closed. |
Yeah sure, they can extend it they way they like. |
14d6499
to
7fd9e05
Compare
I was surprised that Looking at the SelectEntityDescription in the core, it looks like more components would also benefit:
So 7 out of 13 components would directly benefit from this, if it is accepted. If it is not accepted, then I am happy to close (and maybe adjust the seven components to use the same code style). |
@epenet for plugwise, I would suggest changing In plugwise |
I am not sure if this PR will be accepted or not. I think plugwise should be adjusted regardless to avoid confusion and I have opened the corresponding PR: #78935 |
There was a conflict... solved now. |
👍 Will be getting back to this after the beta stuff is out. |
|
5c89ede
to
af3dfb1
Compare
I have rebased over dev to pick-up lametric which also benefits from this change. |
Sure, but it can provide a default. When setting the entity description |
I have added it because it was requested, but I couldn't find a use case for it in the core. |
I've seen you've applied
Well, that might be a sign not to do it 🤷 |
This reverts commit 296ace2.
I think it's good to be consistent and have attributes for all properties in the descriptions but if we don't see a use case in the current code we could wait with adding it. |
I agree that all properties in the description should have corresponding attributes, and I think that's already the case. |
In that case, this PR is invalid, as |
Point taken. I should have phrased it as |
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.
LGTM
@MartinHjelmare Do you agree on the typing change that I suggested (and has been applied by @epenet)?
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.
Looks good!
I have added a breaking change section (for custom component developers) and a blog post PR. |
Thanks, @epenet 👍 |
Breaking change
FOR CUSTOM COMPONENTS ONLY:
As of Home Assistant Core 2022.11,
options
is available as a standard property ofSelectEntityDescription
.This may cause issues in custom components if a custom
options
property was previously implemented.Please adjust the custom component by either dropping or renaming the custom
options
property.Proposed change
Add options to
SelectEntityDescription
I was originally surprised that
options
was not part of the standardSelectEntityDescription
and I thought it was missed in the initial implementation.Then I bumped into the issue that "we don't want a default" so I backed out.
Then I received the request from @MartinHjelmare in #78873 (comment) so I worked on it again and found a (maybe not pretty) solution.
Looking at the
SelectEntityDescription
in the core, it looks like more components would also benefit:kostal_plenticore
,overkiz
,renault
andxiaomi_miio
use a customoptions
property that is updated in this PRgoodwe
,lifx
andsenseme
use a local constant which could be moved to theSelectEntityDescription
litterrobot
,roku
,sensibo
,tuya
andunifiprotect
use a dynamic list, and would not be impacted by this PRplugwise
usesoptions
in a weird way, adjusted in Rename property in Plugwise EntityDescription #78935rainmachine
usesoptions
in a weird way, adjusted in Rename options key in rainmachine #79249So 7 out of 14 components would directly benefit from this, if it is accepted.
HACS:
These use a custom
options
property that replicates this PRLavermanJJ/home-assistant-solarfocus
Options is available as a standard property of SelectEntityDescription LavermanJJ/home-assistant-solarfocus#13elad-bar/ha-shinobi
Options is available as a standard property of SelectEntityDescription elad-bar/ha-shinobi#35iMicknl/ha-nest-protect
Options is available as a standard property of SelectEntityDescription iMicknl/ha-nest-protect#106imicknl/ha-tahoma
Options is available as a standard property of SelectEntityDescription iMicknl/ha-tahoma#820jcgoette/baby_buddy_homeassistant
: Options is available as a standard property of SelectEntityDescription jcgoette/baby_buddy_homeassistant#80syssi/homeassistant-goecharger-mqtt
: Options is available as a standard property of SelectEntityDescription syssi/homeassistant-goecharger-mqtt#52wills106/homsassistant-solax-modbus
: Options is available as a standard property of SelectEntityDescription wills106/homeassistant-solax-modbus#140These do not use a custom
options
property and are not impacted by the changeDeebotUniverse/Deebot-4-Home-Assistant
MTrab/landroid_cloud
dmamontov/hass-ledfx
dmamontov/hass-miwifi
eifinger/hass-foldingathomecontrol
eifinger/hass-weenect
mletenay/home-assistant-goodwe-inverter
-music-assistant/hass-music-assistant
wlcrs/huawei_solar
If it is not accepted, then I am happy to close (and maybe adjust the seven components to use the same code style).
Type of change
Additional information
Checklist
black --fast 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
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: