rstrouse / ESPSomfy-RTS-HA

Control your somfy shades in Home Assistant
The Unlicense
125 stars 9 forks source link

Zeroconf rediscover doesn't udpate config entry #53

Closed chemelli74 closed 5 months ago

chemelli74 commented 5 months ago

When the device change ip, zeroconf discover it correctly, but it ask to configure a new entry instead of updating the previous one (based on unique_id).

rstrouse commented 5 months ago

Isn't that what _abort_if_unique_id_configured() is supposed to do? Perhaps I don't know all the mechanics of the discovery process and I need to be doing something else outside of the ConfigFlow.

       """Handle zeroconf discovery."""
        self.zero_conf = discovery_info
        # Do not probe the device if the host is already configured
        self._async_abort_entries_match({CONF_HOST: discovery_info.host})

        # Check if already configured
        self.server_id = discovery_info.properties.get("serverId", "")
        await self.async_set_unique_id(f"espsomfy_{self.server_id}")
        self.host = discovery_info.host
        self._abort_if_unique_id_configured()
chemelli74 commented 5 months ago

I think I found the issue and is located on config_flow.py.

in async_step_zeroconf() line 130:

await self.async_set_unique_id(f"espsomfy_{self.server_id}")

while on all other places (example async_step_user() at line 96):

await self.async_set_unique_id(api.server_id)

EDIT:

If I was you I would use the f"espsomfy_{server_id}" and create a method to set it so to avoid mis-alligments.

chemelli74 commented 5 months ago

Created a PR to fix it.

Side note: I also created a separate PR for the dev container. And if you agree, I would also like to contribute more adding pre-commit for ruff, pylint, mypy checks.