mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Add discussions sensors to GitHub (#66937)
This commit is contained in:
parent
2d52aca9eb
commit
5b28e2d983
@ -39,6 +39,17 @@ query ($owner: String!, $repository: String!) {
|
||||
watchers(first: 1) {
|
||||
total: totalCount
|
||||
}
|
||||
discussion: discussions(
|
||||
first: 1
|
||||
orderBy: {field: CREATED_AT, direction: DESC}
|
||||
) {
|
||||
total: totalCount
|
||||
discussions: nodes {
|
||||
title
|
||||
url
|
||||
number
|
||||
}
|
||||
}
|
||||
issue: issues(
|
||||
first: 1
|
||||
states: OPEN
|
||||
|
@ -44,6 +44,14 @@ class GitHubSensorEntityDescription(BaseEntityDescription, BaseEntityDescription
|
||||
|
||||
|
||||
SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
GitHubSensorEntityDescription(
|
||||
key="discussions_count",
|
||||
name="Discussions",
|
||||
native_unit_of_measurement="Discussions",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
value_fn=lambda data: data["discussion"]["total"],
|
||||
),
|
||||
GitHubSensorEntityDescription(
|
||||
key="stargazers_count",
|
||||
name="Stars",
|
||||
@ -96,6 +104,16 @@ SENSOR_DESCRIPTIONS: tuple[GitHubSensorEntityDescription, ...] = (
|
||||
"url": data["default_branch_ref"]["commit"]["url"],
|
||||
},
|
||||
),
|
||||
GitHubSensorEntityDescription(
|
||||
key="latest_discussion",
|
||||
name="Latest Discussion",
|
||||
avabl_fn=lambda data: data["discussion"]["discussions"],
|
||||
value_fn=lambda data: data["discussion"]["discussions"][0]["title"][:255],
|
||||
attr_fn=lambda data: {
|
||||
"url": data["discussion"]["discussions"][0]["url"],
|
||||
"number": data["discussion"]["discussions"][0]["number"],
|
||||
},
|
||||
),
|
||||
GitHubSensorEntityDescription(
|
||||
key="latest_release",
|
||||
name="Latest Release",
|
||||
|
@ -19,6 +19,16 @@
|
||||
"watchers": {
|
||||
"total": 9
|
||||
},
|
||||
"discussion": {
|
||||
"total": 1,
|
||||
"discussions": [
|
||||
{
|
||||
"title": "First discussion",
|
||||
"url": "https://github.com/octocat/Hello-World/discussions/1347",
|
||||
"number": 1347
|
||||
}
|
||||
]
|
||||
},
|
||||
"issue": {
|
||||
"total": 1,
|
||||
"issues": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user