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

Upgrade Dialogflow to work with V2 API #25975

Merged
merged 2 commits into from Aug 18, 2019

Conversation

@jshridha
Copy link
Contributor

commented Aug 16, 2019

Description:

On October 23, 2019, the V1 API for Dialogflow will be shut down forcing users to use the V2 API. Additionally, new Dialogflow accounts are being forced to use the new API. Currently, home assistant does not support this API, so all old Dialogflow intents will stop working and new Dialogflow accounts cannot create workable intents.

This is my first PR to home-assistant, but I tried to follow the docs closely. I'm sure I have messed something up, so please let me know what I can do to fix it.

Related issue (if applicable):
Fixes #18411 and fixes #14343

Pull request with documentation for home-assistant.io (if applicable): home-assistant/home-assistant.io#10149

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist

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. Update and include derived files by running python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.
@homeassistant

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2019

Hi @jshridha,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@project-bot project-bot bot added this to Needs review in Dev Aug 16, 2019

@jshridha jshridha referenced this pull request Aug 16, 2019
2 of 2 tasks complete

@homeassistant homeassistant added cla-signed and removed cla-needed labels Aug 16, 2019

@jshridha jshridha force-pushed the jshridha:dialogflow_v2 branch 2 times, most recently from 8269585 to d861c9d Aug 16, 2019

@jshridha jshridha force-pushed the jshridha:dialogflow_v2 branch from d861c9d to b53dc8f Aug 16, 2019

@jshridha jshridha changed the title [WIP] Upgrade Dialogflow to work with V2 API Upgrade Dialogflow to work with V2 API Aug 16, 2019

@jshridha

This comment has been minimized.

Copy link
Contributor Author

commented Aug 16, 2019

This PR is ready for review.

@balloob

This comment has been minimized.

Copy link
Member

commented Aug 16, 2019

Is this a breaking change or is this backwards compatible ?

@@ -84,23 +87,45 @@ class DialogFlowError(HomeAssistantError):

def dialogflow_error_response(message, error):
"""Return a response saying the error message."""
dialogflow_response = DialogflowResponse(message["result"]["parameters"])
_api_version = get_api_version(message)
if _api_version is V1:

This comment has been minimized.

Copy link
@balloob

balloob Aug 16, 2019

Member

Use == for comparison, not is. is is for pointer equivalency.

This comment has been minimized.

Copy link
@jshridha

jshridha Aug 16, 2019

Author Contributor

I intended pointer equivalency here since it's comparing integers, but I'm happy to change it to ==.

parameters = message["result"]["parameters"]
elif _api_version is V2:
parameters = message["queryResult"]["parameters"]
dialogflow_response = DialogflowResponse(parameters, get_api_version(message))

This comment has been minimized.

Copy link
@balloob

balloob Aug 16, 2019

Member

You should be able to use _api_version here ?

This comment has been minimized.

Copy link
@jshridha

jshridha Aug 16, 2019

Author Contributor

Good eye! Should be fixed now.

@@ -84,23 +87,45 @@ class DialogFlowError(HomeAssistantError):

def dialogflow_error_response(message, error):
"""Return a response saying the error message."""
dialogflow_response = DialogflowResponse(message["result"]["parameters"])
_api_version = get_api_version(message)

This comment has been minimized.

Copy link
@balloob

balloob Aug 16, 2019

Member

Please don't prefix parameters with _ if you're using them.

This comment has been minimized.

Copy link
@jshridha

jshridha Aug 16, 2019

Author Contributor

Agreed - that was bad styling on my part. It's fixed now.

req = message.get("result")
action_incomplete = req["actionIncomplete"]
_api_version = get_api_version(message)
if _api_version is V1:

This comment has been minimized.

Copy link
@balloob

balloob Aug 16, 2019

Member

idem.

)
req = message.get("result")
action_incomplete = req.get("actionIncomplete", True)
if action_incomplete is True:

This comment has been minimized.

Copy link
@balloob

balloob Aug 16, 2019

Member
Suggested change
if action_incomplete is True:
if action_incomplete:
@balloob
Copy link
Member

left a comment

This looks great ! After reading the code it is backwards compatible 👏

A few minor comments but after that ok to merge 🐬

Dev automation moved this from Needs review to Review in progress Aug 16, 2019

@jshridha jshridha closed this Aug 16, 2019

Dev automation moved this from Review in progress to Cancelled Aug 16, 2019

@jshridha jshridha reopened this Aug 16, 2019

Dev automation moved this from Cancelled to Needs review Aug 16, 2019

@MartinHjelmare MartinHjelmare moved this from Needs review to Review in progress in Dev Aug 16, 2019

@jshridha

This comment has been minimized.

Copy link
Contributor Author

commented Aug 17, 2019

@balloob I added the changes you requested. Let me know if you want it rebased into one commit.

@balloob
Copy link
Member

left a comment

Looks great, awesome work ! 🎉

Dev automation moved this from Review in progress to Reviewer approved Aug 18, 2019

@balloob balloob merged commit 6907e8e into home-assistant:dev Aug 18, 2019

11 checks passed

CI Build #20190816.57 succeeded
Details
CI (FullCheck Mypy) FullCheck Mypy succeeded
Details
CI (FullCheck Pylint) FullCheck Pylint succeeded
Details
CI (Overview CheckFormat) Overview CheckFormat succeeded
Details
CI (Overview Lint) Overview Lint succeeded
Details
CI (Overview Validate) Overview Validate succeeded
Details
CI (Tests PyTest Python36) Tests PyTest Python36 succeeded
Details
CI (Tests PyTest Python37) Tests PyTest Python37 succeeded
Details
cla-bot Everyone involved has signed the CLA
codecov/patch Coverage not affected when comparing 23f2671...5a46550
Details
codecov/project 94.03% (target 90%)
Details

Dev automation moved this from Reviewer approved to Done Aug 18, 2019

@lock lock bot locked and limited conversation to collaborators Aug 19, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
3 participants
You can’t perform that action at this time.