Skip to content
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

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft

Bugfix: Electric Kiwi #135231

wants to merge 9 commits into from

Conversation

mikey0000
Copy link
Contributor

@mikey0000 mikey0000 commented Jan 9, 2025

…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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@mikey0000 mikey0000 marked this pull request as draft January 9, 2025 19:58
@@ -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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Comment on lines 61 to 64
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)
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abort if configured added

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@mikey0000 mikey0000 requested a review from joostlek January 9, 2025 22:07
@mikey0000 mikey0000 marked this pull request as ready for review January 9, 2025 22:08

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)
Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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

@mikey0000 mikey0000 requested a review from joostlek January 9, 2025 22:29
@@ -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
Copy link
Member

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:
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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

@home-assistant home-assistant bot marked this pull request as draft January 10, 2025 11:34
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@joostlek
Copy link
Member

But I am missing, why do we do this? What was the unique id before and what will it be now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants