-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Bugfix: Electric Kiwi #135231
base: dev
Are you sure you want to change the base?
Bugfix: Electric Kiwi #135231
Conversation
@@ -24,6 +24,8 @@ | |||
|
|||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |||
"""Set up Electric Kiwi from a config entry.""" | |||
assert entry.unique_id is not 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.
So why do we assert it here if we are going to set it down below
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've removed the check further below.
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.
Okay so now we do the migrate so in theory this is true, but I also don't see any reason why we need this here
if entry.unique_id is not None and entry.unique_id.startswith(DOMAIN): | ||
ek_session = await ek_api.get_active_session() | ||
unique_id = "_".join(str(num) for num in ek_session.customer_numbers) | ||
hass.config_entries.async_update_entry(entry, unique_id=unique_id) |
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.
Let's do a minor version migration
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.
Also double check if you have any entities that need a migration of unique id
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.
entities are fine, I checked them, I set them up properly the first time :) , minor version migration, let me go look into that.
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
return self.async_abort(reason="no_customers") | ||
|
||
unique_id = "_".join(str(num) for num in session.customer_numbers) | ||
existing_entry = await self.async_set_unique_id(unique_id) |
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.
if we have an unique id, we should use this id to also abort if it is already setup, and when reauthentiucating we should make sure that the unique id is the same
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.
abort if configured added
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 what about reauth? Please check an integration like withings for that
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
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.
You missed the self._abort_if_unique_id_mismatch(reason="wrong_account")
where someone reauths with a completely different account
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.
Let's add this in a follow up and please check all the rules yourself so the file is synced with the codebase
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.
removed
|
||
ek_session = await ek_api.get_active_session() | ||
unique_id = "_".join(str(num) for num in ek_session.customer_numbers) | ||
hass.config_entries.async_update_entry(config_entry, unique_id=unique_id) |
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.
Let's also bump and check the minor version as well (next to version)
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.
where are the rules around config entry version bumping?
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 would assume they're in the documentation somewhere, but your guess is as good as mine.
Major version is breaking change (and makes integrations unable to load if a newer version is detected), minor version change is able to load if a newer version is found.
So if someone reverts back from 2025.2 to 2025.1, a major version change would not load, minor version change would
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.
Yeah major it is since multiple added EK's wouldn't work if rolled back potentially.
return self.async_abort(reason="no_customers") | ||
|
||
unique_id = "_".join(str(num) for num in session.customer_numbers) | ||
existing_entry = await self.async_set_unique_id(unique_id) |
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 what about reauth? Please check an integration like withings for that
@@ -24,6 +24,8 @@ | |||
|
|||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | |||
"""Set up Electric Kiwi from a config entry.""" | |||
assert entry.unique_id is not 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.
Okay so now we do the migrate so in theory this is true, but I also don't see any reason why we need this here
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: | ||
"""Migrate old entry.""" | ||
# convert title and unique_id to string | ||
if config_entry.version == 1 and config_entry.minor_version == 0: |
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.
Minor version also starts with 1
ek_session = await ek_api.get_active_session() | ||
unique_id = "_".join(str(num) for num in ek_session.customer_numbers) | ||
hass.config_entries.async_update_entry( | ||
config_entry, unique_id=unique_id, title=unique_id, version=2 |
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 avoid updating titles as they are considered user land
) | ||
|
||
ek_session = await ek_api.get_active_session() | ||
unique_id = "_".join(str(num) for num in ek_session.customer_numbers) |
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 are customer_numbers
return self.async_abort(reason="no_customers") | ||
|
||
unique_id = "_".join(str(num) for num in session.customer_numbers) | ||
existing_entry = await self.async_set_unique_id(unique_id) |
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.
You missed the self._abort_if_unique_id_mismatch(reason="wrong_account")
where someone reauths with a completely different account
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
But I am missing, why do we do this? What was the unique id before and what will it be now? |
…Assistant Cloud
Breaking change
Proposed change
Fix unique id and migrate, fix small issue where title would be Home Assistant Cloud, now is the customer id
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: