Add configuration flow to Google Calendar (#22026)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
Allen Porter 2022-03-15 10:44:44 -07:00 committed by GitHub
parent e310c352a1
commit b1718423f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 8 deletions

View File

@ -5,6 +5,7 @@ ha_category:
- Calendar
ha_iot_class: Cloud Polling
ha_release: 0.33
ha_config_flow: true
ha_domain: google
ha_platforms:
- calendar
@ -37,7 +38,6 @@ This section explains how to generate a Client ID and Client Secret on
1. You will then be presented with a pop-up saying 'OAuth client created' showing `Your Client ID` and `Your Client Secret`. Make a note of these (for example, copy and paste them into a text editor) as you will need to put these in your `configuration.yaml` file shortly. Once you have noted these strings, click `OK`. If you need to find these credentials again at any point then simply navigate to `APIs & Services` > `Credentials` and you will see `Home Assistant Credentials` (or whatever you named them in the previous step) under `OAuth 2.0 Clident IDs`. To view both the `Client ID` and `Client secret`, click on the pencil icon, this will take you to the settings page for these credentials and the information will be on the right hand side of the page.
1. We need to double check that the "Google Calendar API" has been automatically enabled. To do this, select `Library` from the menu, then search for "Google Calendar API". If it is enabled you will see `API Enabled` with a green tick next to it. If it is not enabled, then enable it.
If you will later be adding more scopes than just the "Google Calendar API" to the OAuth for this application, you will need to delete your token file under your Home Assistant Profile. You will lose your refresh token due to the re-authenticating to add more API access. It's recommended to use different authorizations for different pieces of Google.
{% enddetails %}
@ -78,16 +78,60 @@ calendar_access:
default: read_write
{% endconfiguration %}
The next time you run or restart Home Assistant, you should find a new notification (the little bell icon in the lower-left corner). Click on that notification it will give you a link and an authentication code. Click on that link to open a Google website where you should enter the code found in the notification (**NOTE**: You may get a message telling you that the API has not been verified and you will need to acknowledge that in order to proceed). This will grant your Home Assistant service `read-only` or `read-write` access (based on configuration) to all the Google Calendars that the account you authenticate with can read.
Then make sure to restart Home Assistant under _**Server Controls**_.
{% my server_controls badge %}
After that, you need to add Google Calendars *Integration*.
{% my config_flow_start badge domain=page.ha_domain %}
{% details "Manual configuration steps" %}
1. Browse to your Home Assistant instance.
1. In the sidebar click on _**{% my config icon %}**_.
1. From the configuration menu select: _**{% my integrations icon %}**_.
1. In the bottom right, click on the
_**{% my config_flow_start icon domain=page.ha_domain %}**_ button.
1. From the list, search and select _**"Google Calendars"**_ and follow the instructions.
{% enddetails %}
The integration setup will next give you instructions on how to authorize Home Assistant to access your account and Calendars.
{% details "OAuth and Device Authorization steps" %}
1. The first step shows a link and a code.
![Screenshot of Link Account](/images/integrations/google/link_account.png)
1. Click on the link [https://www.google.com/device](https://www.google.com/device) to open a Google website which should open a new window where you can enter the code.
1. Home Assistant will wait for a short time while you complete the authorization steps, checking in the background for the authorization to be completed.
![Screenshot of Enter Code](/images/integrations/google/enter_code.png)
1. Continue through the steps of selecting the account you used when creating the credentials in the Google Developer Console.
1. **NOTE**: You may get a message telling you that the app has not been verified and you will need to acknowledge that in
order to proceed.
1. Depending on your `configuration.yaml`, you will either be granting Home Assistant *read only* or *read write* access
to all the Google Calendars available to your linked account.
1. You should then see a *Success!* message from Google.
![Screenshot of Device Connected](/images/integrations/google/device_connected.png)
1. You may close the window, and return back to Home Assistant where you should see a *Success!* message from Home Assistant.
![Screenshot of Success](/images/integrations/google/success.png)
{% enddetails %}
## Troubleshooting
If you are trying to switch to a new Google account then you would run into the following error message. Make sure to delete the existing **.google.token** file from your `config` folder and restart Home Assistant to try again.
'oauth2client.client.HttpAccessTokenRefreshError: deleted_client: The OAuth client was deleted'
In case you get an `Authentication code expired, please restart Home-Assistant and try again` error message, switch your timezone to `Etc/GMT` and restart Home Assistant. This should fix the issue and the `google_calendars.yaml` configuration file will be created.
You can then switch back the timezone to your original one and restart Home Assistant again.
If the setup process fails and you see an error message such as *Authentication code expired, please try again* you may want to try the flow again. You may also check the logs for additional error messages that may indicate a misconfiguration such as an invalid client id or secret.
## Calendar Configuration

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB