Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Add option to set prefix for the attribute (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus authored Jul 25, 2018
1 parent c1fdadc commit 3cdc42d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ labels:
- name: "Wont Fix"
color: "ffffff"
- name: "Enhancement"
color: a2eeef
color: "a2eeef"
- name: "Documentation"
color: "008672"
- name: "Stale"
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ This element is **not** all that useful as a card (it can be used for that to),

## Options

| Name | Type | Default | Description
| Name | Type | Requirement | Description
| ---- | ---- | ------- | -----------
| type | string | **Required** | `custom:state-attribute-element`
| entity | string | **Required** | The entity_id of the entity you want to show.
| attribute | string | **Required** | The attribute of the entity you want to show.
| prefix | string | **Optional** | The entity_id of the entity you want to show.

## Installation

Expand Down Expand Up @@ -43,4 +45,5 @@ Add a custom element in your `ui-lovelace.yaml`
- type: custom:state-attribute-element
entity: sensor.my_sensor
attribute: my_attribute
prefix: "My prefix string: "
```
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
7 changes: 6 additions & 1 deletion state-attribute-element.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
class StateAttributeElement extends HTMLElement {
set hass(hass) {
const entityId = this.config.entity;
const prefix_string = this.config.prefix
const attr = this.config.attribute;
const state = hass.states[entityId].attributes[attr];
const card = document.createElement('state-attribute-element');
this.innerHTML = state;
if (prefix_string) {
this.innerHTML = prefix_string + state;
} else {
this.innerHTML = state;
}
}
setConfig(config) {
if (!config.entity) {
Expand Down

0 comments on commit 3cdc42d

Please sign in to comment.