marcoboers / home-assistant-quatt

Unofficial Quatt heat pump integration for Home Assistant
MIT License
31 stars 4 forks source link

Autodiscovery (DHCP) #106

Closed patrickvorgers closed 4 days ago

patrickvorgers commented 2 months ago

Checklist

Is your feature request related to a problem? Please describe.

Home Assistant can detect some integrations automatically. It would be nice to detect the Quatt automatically and configure it accordingly.

Describe the solution you'd like

Automatically discover the Quatt IP and configure the integration automatically.

Describe alternatives you've considered

Current solution and manually configure the Quatt

Additional context

-

patrickvorgers commented 2 months ago

I am currently developing this feature using the DHCP capabilities of Home Assistant. The feature is almost finished and currently in the testing phase. A side benefit of this feature is that dynamicaly asigned ip-addresses are automatically updated when they change.

image

marcoboers commented 2 months ago

I tagged a beta release! Make sure to go to settings -> devices -> HACS -> Quatt and turn on "Pre-release" toggle to be able to download the beta. https://github.com/marcoboers/home-assistant-quatt/releases/tag/0.6.0b1

patrickvorgers commented 2 months ago

Some changes are missing. I created a new PR with the missing changes. Could you please include them because they are needed for the Optionsflow functionality to work.

In the release notes also the changes of PR #105, should be included.

marcoboers commented 2 months ago

With your latest changes both changing the update interval and the auto discovery is working. However, the auto discovery does not recognize it is the same as the already configured one.

I'm not sure if it is possible to recoginze that. This way everybody that already has the integration in use will get the message that a new CIC is discovered.

patrickvorgers commented 2 months ago

This case should be covered but I will check

patrickvorgers commented 2 months ago

I created a new PR (#110) that resolves this issue. On the CIC statuspage the 'CIC' part of the hostname is in uppercase and during DHCP discovery the 'CIC' part of the hostname is (sometimes) lowercase.

patrickvorgers commented 2 weeks ago

@marcoboers , any idea on when you are going to release 0,60?

marcoboers commented 2 weeks ago

I still have/had the issue with the new discovered CIC next to the existing CIC, which result in a duplicate. The detected hostname is a shortened version of the hostname which makes it different from the CIC hostname in the the json under which it was stored. I don't have a custom name set in my router (Unifi USG) so I am not sure if it is an issue with my CIC or USG. I will try to to temporarily connect it to another router next weekend to see if it is the USG.

patrickvorgers commented 2 weeks ago

I still have/had the issue with the new discovered CIC next to the existing CIC, which result in a duplicate. The detected hostname is a shortened version of the hostname which makes it different from the CIC hostname in the the json under which it was stored. I don't have a custom name set in my router (Unifi USG) so I am not sure if it is an issue with my CIC or USG. I will try to to temporarily connect it to another router next weekend to see if it is the USG.

In the DHCP autodetect function we already call the json page. I could easily adjust the code to do that call first and use the json-hostname for the comparison. Then it is possible to compare json's.

patrickvorgers commented 2 weeks ago

@marcoboers, I rewrote the code but the only challenge is that it takes below a minute before the hostname is filled in the CIC json response. Before that the hostname in the json is None. I added an async wait in the test_credentials function and try again (retry is set in DHCP flow). Do you have other suggestions on how to tackle this?

    async def _test_credentials(self, ip_address: str, retry: bool = False) -> str:
        """Validate credentials."""
        client = QuattApiClient(
            ip_address=ip_address,
            session=async_create_clientsession(self.hass),
        )
        data = await client.async_get_data()

        # During startup the hostname is not yet set so try again
        if (data["system"]["hostName"] is None) and retry:
            # Wait for the startup to complete
            await asyncio.sleep(60)
            data = await client.async_get_data()

        return data["system"]["hostName"]

An alternative approach could be to accept the match on the first part of the hostname. How many characters is the shortened version of the hostname in your case (my guess would be 31)? It should be safe enough in case the first 31 characters match and have to start with CIC-.

After some Google searches;

There are other manufactures that also impose shortened hostnames in the range of 30-32 characters.

patrickvorgers commented 1 week ago

@marcoboers, can you validate PR #128? I don't like having a "sleep" in the code so I decided to go an alternative route. Could you check whether this fixes your issue?

marcoboers commented 4 days ago

These were working and I didn't see comments from beta installs so this is released! Thank you very much! https://github.com/marcoboers/home-assistant-quatt/releases/tag/0.6.0