Skip to content

Commit 296700b

Browse files
committed
Support new sensor changes from GitHub integration
1 parent e273046 commit 296700b

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed

README.md

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# github-entity-row
2+
23
Show GitHub repository sensor data on entity rows in Home Assistant's Lovelace UI
34

45
[![GH-release](https://img.shields.io/github/v/release/benct/lovelace-github-entity-row.svg?style=flat-square)](https://github.com/benct/lovelace-github-entity-row/releases)
@@ -7,12 +8,14 @@ Show GitHub repository sensor data on entity rows in Home Assistant's Lovelace U
78
[![GH-code-size](https://img.shields.io/github/languages/code-size/benct/lovelace-github-entity-row.svg?color=red&style=flat-square)](https://github.com/benct/lovelace-github-entity-row)
89
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=flat-square)](https://github.com/hacs)
910

10-
**NOTE:** This is not a standalone lovelace card, but a row element for the [entities](https://www.home-assistant.io/lovelace/entities/) card.
11+
**NOTE:** This is not a standalone lovelace card, but a row element for
12+
the [entities](https://www.home-assistant.io/lovelace/entities/) card.
1113

1214
## Installation
1315

1416
Add [github-entity-row.js](https://raw.githubusercontent.com/benct/lovelace-github-entity-row/master/github-entity-row.js)
1517
to your `<config>/www/` folder and add the following to the `configuration.yaml` file:
18+
1619
```yaml
1720
lovelace:
1821
resources:
@@ -21,24 +24,39 @@ lovelace:
2124
```
2225
2326
_OR_ install using [HACS](https://hacs.xyz/) and add this (if in YAML mode):
27+
2428
```yaml
2529
lovelace:
2630
resources:
2731
- url: /hacsfiles/lovelace-github-entity-row/github-entity-row.js
2832
type: module
2933
```
3034
31-
The above configuration can be managed directly in the Configuration -> Lovelace Dashboards -> Resources panel when not using YAML mode,
32-
or added by clicking the "Add to lovelace" button on the HACS dashboard after installing the plugin.
35+
The above configuration can be managed in the Configuration -> Dashboards -> Resources panel when not using YAML mode.
3336
3437
## Configuration
3538
36-
| Name | Type | Default | Description
37-
| ---- | ---- | ------- | -----------
38-
| type | string | **Required** | `custom:github-entity-row`
39-
| entity | string | **Required** | `sensor.my_github_repository`
40-
| name | string | `friendly_name` | Override entity friendly name
41-
| icon | string | `mdi:github-circle` | Override default entity icon
39+
| Name | Type | Default | Description |
40+
|--------|--------|-----------------|-------------------------------------------|
41+
| type | string | **Required** | `custom:github-entity-row` |
42+
| user | string | **Required** | Your GitHub user name |
43+
| repo | string | **Required** | Your GitHub repository |
44+
| sensor | string | `<user>_<repo>` | Specify a custom sensor entity (optional) |
45+
| name | string | `repo` | Override repository name |
46+
| icon | string | `mdi:github` | Override default entity icon |
47+
48+
The `user` and `repo` fields need to exactly match your GitHub user and repository names. If you rename the sensor
49+
entity IDs from the GitHub integration, you can specify the updated sensor ID with the `sensor` field (without the
50+
domain and type suffix). For example, if the integration exposes `sensor.custom_sensor_id_latest_release`, you should
51+
specify `custom_sensor_id`.
52+
53+
## Migrate to version 2
54+
55+
The GitHub [integration](https://www.home-assistant.io/integrations/github/) was changed in HA version `2022.2.0` to
56+
include several sensors for each GitHub repository. If you are using the latest HA installation, you need to upgrade to
57+
version `>2.0.0` of this card. The main change is that the `entity` field has been replaced by `user` and `repo`. You
58+
might also need to manually enable the following sensors from your GitHub integration; `Stars`, `Issues`
59+
and `Pull Requests`.
4260

4361
## Example
4462

@@ -49,24 +67,19 @@ type: entities
4967
title: GitHub
5068
entities:
5169
- type: custom:github-entity-row
52-
entity: sensor.home_assistant_config
70+
user: benct
71+
repo: home-assistant-config
72+
name: HA Config
5373
- type: custom:github-entity-row
54-
entity: sensor.lovelace_github_entity_row
74+
user: benct
75+
repo: lovelace-github-entity-row
76+
icon: mdi:github
5577
- type: custom:github-entity-row
56-
entity: sensor.lovelace_xiaomi_vacuum_card
57-
```
58-
59-
Usage with [auto-entities](https://github.com/thomasloven/lovelace-auto-entities) card:
60-
```yaml
61-
type: custom:auto-entities
62-
card:
63-
type: entities
64-
filter:
65-
include:
66-
- entity_id: sensor.github* # or use other matchers
67-
options:
68-
type: custom:github-entity-row
69-
<github-entity-row options>
78+
user: benct
79+
repo: lovelace-multiple-entity-row
80+
- type: custom:github-entity-row
81+
user: benct
82+
repo: lovelace-xiaomi-vacuum-card
7083
```
7184

7285
## My cards

github-entity-row.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ class GithubEntityRow extends Polymer.Element {
2525
<div class="flex">
2626
<div class="entity" on-click="issues" title="Open issues">
2727
<ha-icon class="icon" icon="mdi:alert-circle-outline"></ha-icon>
28-
<span>[[stateObj.attributes.open_issues]]</span>
28+
<span>[[stateObjIssues.state]]</span>
2929
</div>
3030
<div class="entity" on-click="pulls" title="Open pull requests">
3131
<ha-icon class="icon" icon="mdi:source-pull"></ha-icon>
32-
<span>[[stateObj.attributes.open_pull_requests]]</span>
32+
<span>[[stateObjPRs.state]]</span>
3333
</div>
3434
<div class="entity" on-click="stars" title="Stargazers">
3535
<ha-icon class="icon" icon="mdi:star"></ha-icon>
36-
<span>[[stateObj.attributes.stargazers]]</span>
36+
<span>[[stateObjStars.state]]</span>
3737
</div>
3838
</div>
3939
</hui-generic-entity-row>
@@ -46,21 +46,34 @@ class GithubEntityRow extends Polymer.Element {
4646

4747
goto(event, path) {
4848
event.stopPropagation();
49-
window.open(`https://github.com/${this.stateObj.attributes.path}/${path}`);
49+
window.open(`https://github.com/${this._config.user}/${this._config.repo}/${path}`);
5050
}
5151

5252
setConfig(config) {
53-
if (!config.entity) throw new Error('Please define an entity.');
54-
if (config.entity.split('.')[0] !== 'sensor') throw new Error('Please define a GitHub sensor entity.');
53+
if (!config.user || !config.repo) throw new Error('Please define a GitHub user and repository.');
5554

56-
this._config = config;
55+
const sensor = config.sensor || `${config.user}_${config.repo}`.replaceAll('-', '_');
56+
this._config = {
57+
...config,
58+
name: config.name || config.repo,
59+
icon: config.icon || 'mdi:github',
60+
sensor: sensor,
61+
entity: `sensor.${sensor}_issues`, // required by ha-generic-entity-row
62+
};
63+
}
64+
65+
getStateObject(hass, sensor, suffix) {
66+
const entity = `sensor.${sensor}_${suffix}`;
67+
return entity in hass.states ? hass.states[entity] : null;
5768
}
5869

5970
set hass(hass) {
6071
this._hass = hass;
6172

6273
if (hass && this._config) {
63-
this.stateObj = this._config.entity in hass.states ? hass.states[this._config.entity] : null;
74+
this.stateObjStars = this.getStateObject(hass, this._config.sensor, 'stars');
75+
this.stateObjIssues = this.getStateObject(hass, this._config.sensor, 'issues');
76+
this.stateObjPRs = this.getStateObject(hass, this._config.sensor, 'pull_requests');
6477
}
6578
}
6679
}

0 commit comments

Comments
 (0)