Skip to content

Add config flow for Tuya#35422

Merged
bdraco merged 29 commits intohome-assistant:devfrom
ollo69:tuya-config-flow
May 11, 2020
Merged

Add config flow for Tuya#35422
bdraco merged 29 commits intohome-assistant:devfrom
ollo69:tuya-config-flow

Conversation

@ollo69
Copy link
Copy Markdown
Contributor

@ollo69 ollo69 commented May 9, 2020

Breaking change

Adding config flow, the Tuya configuration from configuration.yaml is used only the first time during import phase. In case of credential change it is required to reconfigure the integration, changing credential in configuration.yaml is not enought.
Al other features are maintened.

Proposed change

This PR is to add config flow to Tuya and so simplify the configuration process of the integration and benefit of all the additional information provided by the devices registry.

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

Configuration.yaml entries are not changed and are explained on integration manual page

Additional information

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@joogps
Copy link
Copy Markdown
Contributor

joogps commented May 9, 2020

Did you format your code with black?

@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 9, 2020

Did you format your code with black?

Yes I did, seem few exception in my last commit. Fixing now...

ollo69 added 2 commits May 9, 2020 20:25
Added pylint:disable=unused-import in config_flow.py
@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 9, 2020

@ollo69

Thank you for your contribution thus far! 🎖 Since this is a significant contribution, we would appreciate you'd added yourself to the list of code owners for this integration. ❤️

Please, add your GitHub username to the manifest.json of this integration.

For more information about "code owners", see: Architecture Decision Record 0008: Code owners.

Comment thread homeassistant/components/tuya/config_flow.py
Comment thread homeassistant/components/tuya/__init__.py Outdated
Comment thread homeassistant/components/tuya/__init__.py
@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 10, 2020

Do you think I should set to deprecated the configuration file option?

CONFIG_SCHEMA = vol.Schema(
    vol.All(
        cv.deprecated(DOMAIN),
        {
            DOMAIN: vol.Schema(
                {
                    vol.Required(CONF_PASSWORD): cv.string,
                    vol.Required(CONF_USERNAME): cv.string,
                    vol.Required(CONF_COUNTRYCODE): cv.string,
                    vol.Optional(CONF_PLATFORM, default="tuya"): cv.string,
                }
            )
        },
    ),
    extra=vol.ALLOW_EXTRA,
)

@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 10, 2020

cv.deprecated

Yes, there doesn't seem anything that is yaml only here.

Comment thread homeassistant/components/tuya/__init__.py Outdated
- Set config schema "deprecated"
- Removed async from update_callback
Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Looks good. I did some basic testing with this. I don't have a tuya account so I could only test the fail paths.

Comment thread tests/components/tuya/test_config_flow.py Outdated
Comment thread tests/components/tuya/test_config_flow.py Outdated
Copy link
Copy Markdown
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Sorry I missed it before, but there is one more change needed in the test to use hass.config_entries.flow.async_init

If you need an example of how this works, check harmony

@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 10, 2020

Sorry I missed it before, but there is one more change needed in the test to use hass.config_entries.flow.async_init

If you need an example of how this works, check harmony

Not so expert here. I changed using also FritzBox implementation as example.
Now is using hass.config_entries.flow.async_init, let me know if is ok.

@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 10, 2020

Sorry I missed it before, but there is one more change needed in the test to use hass.config_entries.flow.async_init
If you need an example of how this works, check harmony

Not so expert here. I changed using also FritzBox implementation as example.
Now is using hass.config_entries.flow.async_init, let me know if is ok.

For the ones that will create a config entry we should mock out async_setup and async_setup_entry to make sure the integration isn't actually setup and won't do I/O in the future from the test which can cause flapping test failures.

patch(
        "homeassistant.components.tuya.async_setup", return_value=True
    ) as mock_setup, patch(
        "homeassistant.components.tuya.async_setup_entry", return_value=True,
    ) as mock_setup_entry:

Then we can assert that the setup was called.

    await hass.async_block_till_done()
    assert len(mock_setup.mock_calls) == 1
    assert len(mock_setup_entry.mock_calls) == 1

ollo69 added 2 commits May 10, 2020 22:28
- mock out async_setup and async_setup_entry
@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 10, 2020

@ollo69 did you get a chance to retest all your devices to make sure everything is still working as expected?

@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 10, 2020

I always check locally that everything is OK before commiting, so I can confirm that last change work properly.
Of course I can test only my devices, Tuya have tons...
I suppose that this will be tested in beta release and a issue will be open if something do not work,

@bdraco
Copy link
Copy Markdown
Member

bdraco commented May 10, 2020

Looks like we just need a docs PR, and this is good to merge

@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 10, 2020

Looks like we just need a docs PR, and this is good to merge

I'll open doc PR shortly

@bdraco bdraco merged commit b3ee54b into home-assistant:dev May 11, 2020
@ollo69 ollo69 deleted the tuya-config-flow branch May 11, 2020 09:18
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Please address the comments in a new PR. Thanks!

Comment thread homeassistant/components/tuya/__init__.py
Comment thread homeassistant/components/tuya/climate.py
Comment thread homeassistant/components/tuya/strings.json
@ollo69 ollo69 mentioned this pull request May 11, 2020
20 tasks
@ollo69
Copy link
Copy Markdown
Contributor Author

ollo69 commented May 11, 2020

New PR #35497 opened.

@lock lock Bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants