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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve type hints in group #78350
Improve type hints in group #78350
Conversation
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
"""Update the member entity IDs.""" | ||
asyncio.run_coroutine_threadsafe( | ||
self.async_update_tracked_entity_ids(entity_ids), self.hass.loop | ||
).result() | ||
|
||
async def async_update_tracked_entity_ids(self, entity_ids): | ||
async def async_update_tracked_entity_ids( | ||
self, entity_ids: Iterable[str] | None |
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.
self, entity_ids: Iterable[str] | None | |
self, entity_ids: Collection[str] | None |
You could also consider using Collection
instead. Something I learned recently, since Iterable
doesn't include a __len__
method, bool(some_iterable)
can always be True
(in particular for generators).
Collection
however will require __len__
to be implemented and thus enable a small shortcut later.
The difference in this case is probably negligible but since the method is called with sets
anyway, you could also just use it.
core/homeassistant/components/group/__init__.py
Lines 659 to 681 in 6c0ad54
def _set_tracked(self, entity_ids): | |
"""Tuple of entities to be tracked.""" | |
# tracking are the entities we want to track | |
# trackable are the entities we actually watch | |
if not entity_ids: | |
self.tracking = () | |
self.trackable = () | |
return | |
excluded_domains = self.hass.data[REG_KEY].exclude_domains | |
tracking = [] | |
trackable = [] | |
for ent_id in entity_ids: | |
ent_id_lower = ent_id.lower() | |
domain = split_entity_id(ent_id_lower)[0] | |
tracking.append(ent_id_lower) | |
if domain not in excluded_domains: | |
trackable.append(ent_id_lower) | |
self.trackable = tuple(trackable) | |
self.tracking = tuple(tracking) |
Proposed change
Improve type hints in group
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: