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

Add YouTube integration #92988

Merged
merged 37 commits into from May 27, 2023
Merged

Add YouTube integration #92988

merged 37 commits into from May 27, 2023

Conversation

joostlek
Copy link
Member

@joostlek joostlek commented May 12, 2023

Proposed change

Add YouTube integration. First you login via Google, after which you can select channels from your subscription list. It will fetch the latest video and the amount of subscribers for a youtube channel.

This is a very early draft, please take a look and give some feedback for code and for how it works.

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

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
  • I have followed the perfect PR recommendations
  • 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.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@joostlek joostlek changed the title Youtube Add YouTube integration May 12, 2023
Copy link
Contributor

@tkdrob tkdrob left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Please provide return types for all functions and methods. We also require tests for the config flow. See the Google Mail example.

@joostlek
Copy link
Member Author

Thanks for the PR. Please provide return types for all functions and methods. We also require tests for the config flow. See the Google Mail example.

Yea working on it, but I thought I'd throw it out for other to give some preliminary feedback :)

@joostlek
Copy link
Member Author

@tkdrob Are you maybe able to help me out with the test for triggering a reauth after setup? I can't get the method to work.

@tkdrob
Copy link
Contributor

tkdrob commented May 12, 2023

@tkdrob Are you maybe able to help me out with the test for triggering a reauth after setup? I can't get the method to work.

It is good practice to limit the first PR to the minimum needed to provide the user functionality. Let's leave to reauth step for a followup PR to keep things small. This is only an issue when the user changes the password which likely revokes the oauth authorization.

@joostlek
Copy link
Member Author

@tkdrob Are you maybe able to help me out with the test for triggering a reauth after setup? I can't get the method to work.

It is good practice to limit the first PR to the minimum needed to provide the user functionality. Let's leave to reauth step for a followup PR to keep things small. This is only an issue when the user changes the password which likely revokes the oauth authorization.

What would you suggest, since I took google mail as basis (as you obviously noticed), what's the best way to keep that out of here?

Copy link
Contributor

@tkdrob tkdrob left a comment

Choose a reason for hiding this comment

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

See below

homeassistant/components/youtube/config_flow.py Outdated Show resolved Hide resolved
@joostlek joostlek marked this pull request as ready for review May 12, 2023 18:03
@joostlek
Copy link
Member Author

Do you have an example json response for the unit test?

@tkdrob
Copy link
Contributor

tkdrob commented May 15, 2023

Do you have an example json response for the unit test?

This is printed with ex.args

({'vary': 'Origin, X-Origin, Referer', 'content-type': 'application/json; charset=UTF-8', 'date': 'Mon, 15 May 2023 21:25:42 GMT', 'server': 'scaffolding on HTTPServer2', 'cache-control': 'private', 'x-xss-protection': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'transfer-encoding': 'chunked', 'status': '403', 'content-length': '947', '-content-encoding': 'gzip'}, b'{\n  "error": {\n    "code": 403,\n    "message": "YouTube Data API v3 has not been used in project 0 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=0 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",\n    "errors": [\n      {\n        "message": "YouTube Data API v3 has not been used in project 0 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=0 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",\n        "domain": "usageLimits",\n        "reason": "accessNotConfigured",\n        "extendedHelp": "https://console.developers.google.com"\n      }\n    ],\n    "status": "PERMISSION_DENIED"\n  }\n}\n')

Copy link
Contributor

@tkdrob tkdrob left a comment

Choose a reason for hiding this comment

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

See below

homeassistant/components/youtube/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/youtube/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/youtube/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/youtube/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/youtube/coordinator.py Outdated Show resolved Hide resolved
@joostlek joostlek requested a review from tkdrob May 16, 2023 09:27
homeassistant/components/youtube/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/youtube/config_flow.py Outdated Show resolved Hide resolved
"homeassistant.components.youtube.config_flow.build",
side_effect=HttpError(
Response(
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: I'd suggest extracting constants for these large dicts.

Copy link
Member Author

Choose a reason for hiding this comment

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

To what place would be the best?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know, maybe a constant somewhere? I don't have a strong opinion about this so feel free to do later or not.

@home-assistant home-assistant bot marked this pull request as draft May 20, 2023 20:40
@joostlek joostlek marked this pull request as ready for review May 22, 2023 20:06
@allenporter allenporter merged commit e4c51d4 into home-assistant:dev May 27, 2023
52 checks passed
@allenporter
Copy link
Contributor

Thanks @joostlek 👍🏼

@joostlek joostlek deleted the youtube branch May 27, 2023 18:31
Copy link
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!

@joostlek joostlek mentioned this pull request May 28, 2023
20 tasks
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2023
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.

None yet

4 participants