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

GitHub integration revamp #38458

Closed
wants to merge 43 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c9bbc5e
Basic setup of integration
timmo001 Jul 25, 2020
133f9df
Working sensor
timmo001 Jul 25, 2020
1ebd9cf
Add missing attrs
timmo001 Jul 25, 2020
088e433
Reauth flow
timmo001 Jul 25, 2020
db9d08e
Add views
timmo001 Jul 25, 2020
ef591ea
Order
timmo001 Jul 25, 2020
e595596
Add homepage
timmo001 Jul 25, 2020
aab3377
Super classes
timmo001 Jul 26, 2020
8df4193
Data update coordinator
timmo001 Jul 26, 2020
52bcd1f
Sensor entity
timmo001 Jul 26, 2020
95ef5b4
Move attributes set into update
timmo001 Jul 26, 2020
bc24053
Split sensor into individual sensors
timmo001 Jul 26, 2020
e149cb0
Add TODOs
timmo001 Jul 26, 2020
f1ff436
Add TODO
timmo001 Jul 26, 2020
5aaf11c
Change name
timmo001 Jul 26, 2020
6d8eddf
Fix for clones and views for those without push access
timmo001 Jul 26, 2020
253e513
Options flow
timmo001 Jul 26, 2020
9dfa281
Cleanup and fix update
timmo001 Jul 26, 2020
145dbf7
Update and handle errors
timmo001 Jul 26, 2020
8fffd53
Unique ids
timmo001 Aug 1, 2020
5ac5c28
Fix unique id set position
timmo001 Aug 1, 2020
164a37c
Add tests
timmo001 Aug 1, 2020
e783a39
Add untested to coverage
timmo001 Aug 1, 2020
550801c
Cleanup
timmo001 Aug 1, 2020
96e564e
Fix typo
timmo001 Aug 1, 2020
c205dfa
Add reauth tests
timmo001 Aug 2, 2020
5dab906
Add tests and json fixture
timmo001 Aug 2, 2020
36ea668
Update aiogithubapi to 1.1.1
timmo001 Aug 2, 2020
25c29d0
Update data
timmo001 Aug 2, 2020
80498f0
Update aiogithubapi to 1.1.2 and add sha and message
timmo001 Aug 2, 2020
6d9c6ad
Make push access true for fixture
timmo001 Aug 2, 2020
549fcbe
Rework reauth logic
timmo001 Aug 2, 2020
8ac5bb4
Update tests for changes
timmo001 Aug 2, 2020
421fc33
Add reauth invalid auth test
timmo001 Aug 2, 2020
ab86e66
Typo
timmo001 Aug 2, 2020
4963d0f
Split identifiers and set as service
timmo001 Aug 2, 2020
21763a6
Tests
timmo001 Aug 3, 2020
2c826b3
Format
timmo001 Sep 5, 2020
ab8f55c
Lint
timmo001 Sep 5, 2020
e621394
Remove bad lines from rebase
timmo001 Sep 5, 2020
9419154
Remove unneeded removal
timmo001 Sep 5, 2020
c06d978
Update to use CoordinatorEntity
timmo001 Sep 5, 2020
31712fe
Update aiogithubapi to v2.0.0
timmo001 Oct 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix for clones and views for those without push access
  • Loading branch information
timmo001 committed Oct 11, 2020
commit 6d8eddf3d8f6b530c5d82795a2b72704e83dfd54
25 changes: 17 additions & 8 deletions homeassistant/components/github/__init__.py
Original file line number Diff line number Diff line change
@@ -123,24 +123,33 @@ async def async_update_data() -> GitHubData:
latest_commit = await repository.client.get(
endpoint=f"/repos/{repository.full_name}/branches/{repository.default_branch}"
)
clones = await repository.client.get(
endpoint=f"/repos/{repository.full_name}/traffic/clones"
)
issues: [AIOGitHubAPIRepositoryIssue] = await repository.get_issues()
releases: [AIOGitHubAPIRepositoryRelease] = await repository.get_releases()
views = await repository.client.get(
endpoint=f"/repos/{repository.full_name}/traffic/views"
)
if repository.attributes.get("permissions").get("push") is True:
clones = await repository.client.get(
endpoint=f"/repos/{repository.full_name}/traffic/clones"
)
views = await repository.client.get(
endpoint=f"/repos/{repository.full_name}/traffic/views"
)
else:
clones = None
views = None

return GitHubData(
repository,
GitHubLatestCommit(
latest_commit["commit"]["sha"],
latest_commit["commit"]["commit"]["message"],
),
GitHubClones(clones["count"], clones["uniques"]),
GitHubClones(clones["count"], clones["uniques"])
if clones is not None
else None,
issues,
releases,
GitHubViews(views["count"], views["uniques"]),
GitHubViews(views["count"], views["uniques"])
if views is not None
else None,
)

coordinator = DataUpdateCoordinator(
28 changes: 14 additions & 14 deletions homeassistant/components/github/sensor.py
Original file line number Diff line number Diff line change
@@ -45,20 +45,20 @@ async def async_setup_entry(hass, entry, async_add_entities):
DATA_REPOSITORY
]

async_add_entities(
[
ClonesSensor(coordinator, repository),
ForksSensor(coordinator, repository),
LatestCommitSensor(coordinator, repository),
LatestOpenIssueSensor(coordinator, repository),
LatestPullRequestSensor(coordinator, repository),
LatestReleaseSensor(coordinator, repository),
StargazersSensor(coordinator, repository),
ViewsSensor(coordinator, repository),
WatchersSensor(coordinator, repository),
],
True,
)
sensors = [
ForksSensor(coordinator, repository),
LatestCommitSensor(coordinator, repository),
LatestOpenIssueSensor(coordinator, repository),
LatestPullRequestSensor(coordinator, repository),
LatestReleaseSensor(coordinator, repository),
StargazersSensor(coordinator, repository),
WatchersSensor(coordinator, repository),
]
if repository.attributes.get("permissions").get("push") is True:
sensors.append(ClonesSensor(coordinator, repository))
sensors.append(ViewsSensor(coordinator, repository))

async_add_entities(sensors, True)


class GitHubSensor(GitHubDeviceEntity):