mirror of
https://github.com/kalkih/mini-graph-card.git
synced 2025-12-20 00:35:56 +01:00
fix: use a proper config in renderState() (#1217)
This commit is contained in:
15
src/main.js
15
src/main.js
@@ -259,12 +259,11 @@ class MiniGraphCard extends LitElement {
|
||||
}
|
||||
|
||||
renderStates() {
|
||||
const [firstEntityConfig] = this.config.entities;
|
||||
if (this.config.show.state)
|
||||
return html`
|
||||
<div class="states flex" loc=${this.config.align_state}>
|
||||
${this.renderState(firstEntityConfig, 0)}
|
||||
<div class="states--secondary">${this.config.entities.map((entityConfig, i) => i > 0 && this.renderState(entityConfig, i) || '')}</div>
|
||||
${this.renderState(0)}
|
||||
<div class="states--secondary">${this.config.entities.map((entityConfig, i) => i > 0 && this.renderState(i) || '')}</div>
|
||||
${this.config.align_icon === 'state' ? this.renderIcon() : ''}
|
||||
</div>
|
||||
`;
|
||||
@@ -285,14 +284,16 @@ class MiniGraphCard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
renderState(entityConfig, id) {
|
||||
renderState(id) {
|
||||
const isPrimary = id === 0; // rendering main state element?
|
||||
if (isPrimary || entityConfig.show_state) {
|
||||
if (isPrimary || this.config.entities[id].show_state) {
|
||||
const state = this.getEntityState(id);
|
||||
// use tooltip data for main state element, if tooltip is active
|
||||
const { entity: tooltipEntity, value: tooltipValue } = this.tooltip;
|
||||
const value = isPrimary && tooltipEntity !== undefined ? tooltipValue : state;
|
||||
const entity = isPrimary && tooltipEntity !== undefined ? tooltipEntity : id;
|
||||
const isTooltip = isPrimary && tooltipEntity !== undefined;
|
||||
const value = isTooltip ? tooltipValue : state;
|
||||
const entity = isTooltip ? tooltipEntity : id;
|
||||
const entityConfig = this.config.entities[entity];
|
||||
return html`
|
||||
<div
|
||||
class="state ${!isPrimary && 'state--small'}"
|
||||
|
||||
Reference in New Issue
Block a user