bajansen / home-assistant-frank_energie

Custom Component voor Home Assistant Frank Energie prijsinformatie
66 stars 18 forks source link

Delivery site selection in config flow #108

Open berendhaan opened 5 months ago

berendhaan commented 5 months ago

The PR adds an extra step to the config flow which the user can select his current site, if he has multiple. Related to #104

The code still needs some little clean-up, title is not set correctly atm and the step could be skipped if there is only one delivery site active.

afbeelding

berendhaan commented 3 months ago
            number_of_sites = len(me.deliverySites)
            if number_of_sites == 1:
                # for backward compatibility (do nothing)
                # Check if entry with CONF_USERNAME exists, then abort
                if CONF_USERNAME in user_input:
                    await self.async_set_unique_id(user_input[CONF_USERNAME])
                    self._abort_if_unique_id_configured()

                # Create entry with unique_id as me.deliverySites[0].reference
                first_site = me.deliverySites[0]
                self.sign_in_data[CONF_SITE] = first_site.reference
                self.sign_in_data[CONF_USERNAME] = self.create_title(first_site)
                return await self._async_create_entry(self.sign_in_data)

I'm missing the reference where you want this part of the code, is it in config_flow.py? I'll take a look in fixing all the linting issues aswell

berendhaan commented 3 months ago

I'm having some issues with the dependencies, propbaly because some components got updated on the way.

Updating some deps resolves some issues localy, running in python 3.12, I see that in ci.yaml python 3.10 is still used.

What do you think is best, fixing all this stuff in this PR, or first create a PR to bump deps?

HiDiHo01 commented 3 months ago

Yes this is a edit to have site selection so old config would continue as normal. This should go under deliverysite == 0

Op do 13 jun 2024 19:15 schreef Berend Haan @.***>:

        number_of_sites = len(me.deliverySites)
        if number_of_sites == 1:
            # for backward compatibility (do nothing)
            # Check if entry with CONF_USERNAME exists, then abort
            if CONF_USERNAME in user_input:
                await self.async_set_unique_id(user_input[CONF_USERNAME])
                self._abort_if_unique_id_configured()

            # Create entry with unique_id as me.deliverySites[0].reference
            first_site = me.deliverySites[0]
            self.sign_in_data[CONF_SITE] = first_site.reference
            self.sign_in_data[CONF_USERNAME] = self.create_title(first_site)
            return await self._async_create_entry(self.sign_in_data)

I'm missing the reference where you want this part of the code, is it in config_flow.py? I'll take a look in fixing all the linting issues aswell

— Reply to this email directly, view it on GitHub https://github.com/bajansen/home-assistant-frank_energie/pull/108#issuecomment-2166365237, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDM263I4SPNL3OLSZ2AFF3ZHHHUXAVCNFSM6AAAAABGXOTSMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRWGM3DKMRTG4 . You are receiving this because you commented.Message ID: @.***>

HiDiHo01 commented 3 months ago

Yes the depends should be updated

Op do 13 jun 2024 19:37 schreef Berend Haan @.***>:

I'm having some issues with the dependencies, propbaly because some components got updated on the way.

Updating some deps resolves some issues localy, running in python 3.12, I see that in ci.yaml python 3.10 is still used.

What do you think is best, fixing all this stuff in this PR, or first create a PR to bump deps?

— Reply to this email directly, view it on GitHub https://github.com/bajansen/home-assistant-frank_energie/pull/108#issuecomment-2166413844, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDM265LNGQOUZKOYC53US3ZHHKG3AVCNFSM6AAAAABGXOTSMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRWGQYTGOBUGQ . You are receiving this because you commented.Message ID: @.***>

HiDiHo01 commented 3 months ago

I was thinking.....should we do only sites in delivery or all sites including closed sites?

berendhaan commented 3 months ago

I was thinking.....should we do only sites in delivery or all sites including closed sites?

Yeah, I think that makes sense in a SmartHome context.