mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 06:16:33 +00:00
Override history names (#1405)
This commit is contained in:
parent
f2c56a624b
commit
834528506a
@ -25,6 +25,7 @@ class StateHistoryChartLine extends PolymerElement {
|
|||||||
return {
|
return {
|
||||||
chartData: Object,
|
chartData: Object,
|
||||||
data: Object,
|
data: Object,
|
||||||
|
names: Object,
|
||||||
unit: String,
|
unit: String,
|
||||||
identifier: String,
|
identifier: String,
|
||||||
|
|
||||||
@ -91,9 +92,10 @@ class StateHistoryChartLine extends PolymerElement {
|
|||||||
endTime = new Date();
|
endTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const names = this.names || {};
|
||||||
deviceStates.forEach((states) => {
|
deviceStates.forEach((states) => {
|
||||||
const domain = states.domain;
|
const domain = states.domain;
|
||||||
const name = states.name;
|
const name = names[states.entity_id] || states.name;
|
||||||
// array containing [value1, value2, etc]
|
// array containing [value1, value2, etc]
|
||||||
let prevValues;
|
let prevValues;
|
||||||
const data = [];
|
const data = [];
|
||||||
|
@ -34,6 +34,7 @@ class StateHistoryChartTimeline extends PolymerElement {
|
|||||||
type: Object,
|
type: Object,
|
||||||
observer: 'dataChanged',
|
observer: 'dataChanged',
|
||||||
},
|
},
|
||||||
|
names: Object,
|
||||||
noSingle: Boolean,
|
noSingle: Boolean,
|
||||||
endTime: Date,
|
endTime: Date,
|
||||||
rendered: {
|
rendered: {
|
||||||
@ -95,15 +96,15 @@ class StateHistoryChartTimeline extends PolymerElement {
|
|||||||
const labels = [];
|
const labels = [];
|
||||||
const datasets = [];
|
const datasets = [];
|
||||||
// stateHistory is a list of lists of sorted state objects
|
// stateHistory is a list of lists of sorted state objects
|
||||||
|
const names = this.names || {};
|
||||||
stateHistory.forEach((stateInfo) => {
|
stateHistory.forEach((stateInfo) => {
|
||||||
let newLastChanged;
|
let newLastChanged;
|
||||||
let prevState = null;
|
let prevState = null;
|
||||||
let locState = null;
|
let locState = null;
|
||||||
let prevLastChanged = startTime;
|
let prevLastChanged = startTime;
|
||||||
const entityDisplay = stateInfo.name;
|
const entityDisplay = names[stateInfo.entity_id] || stateInfo.name;
|
||||||
|
|
||||||
const dataRow = [];
|
const dataRow = [];
|
||||||
|
|
||||||
|
|
||||||
stateInfo.data.forEach((state) => {
|
stateInfo.data.forEach((state) => {
|
||||||
let newState = state.state;
|
let newState = state.state;
|
||||||
const timeStamp = new Date(state.last_changed);
|
const timeStamp = new Date(state.last_changed);
|
||||||
|
@ -31,12 +31,12 @@ class StateHistoryCharts extends LocalizeMixin(PolymerElement) {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template is="dom-if" if="[[historyData.timeline.length]]">
|
<template is="dom-if" if="[[historyData.timeline.length]]">
|
||||||
<state-history-chart-timeline data="[[historyData.timeline]]" end-time="[[_computeEndTime(endTime, upToNow, historyData)]]" no-single="[[noSingle]]">
|
<state-history-chart-timeline data="[[historyData.timeline]]" end-time="[[_computeEndTime(endTime, upToNow, historyData)]]" no-single="[[noSingle]]" names="[[names]]">
|
||||||
</state-history-chart-timeline>
|
</state-history-chart-timeline>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template is="dom-repeat" items="[[historyData.line]]">
|
<template is="dom-repeat" items="[[historyData.line]]">
|
||||||
<state-history-chart-line unit="[[item.unit]]" data="[[item.data]]" identifier="[[item.identifier]]" is-single-device="[[_computeIsSingleLineChart(item.data, noSingle)]]" end-time="[[_computeEndTime(endTime, upToNow, historyData)]]">
|
<state-history-chart-line unit="[[item.unit]]" data="[[item.data]]" identifier="[[item.identifier]]" is-single-device="[[_computeIsSingleLineChart(item.data, noSingle)]]" end-time="[[_computeEndTime(endTime, upToNow, historyData)]]" names="[[names]]">
|
||||||
</state-history-chart-line>
|
</state-history-chart-line>
|
||||||
</template>
|
</template>
|
||||||
`;
|
`;
|
||||||
@ -49,6 +49,7 @@ class StateHistoryCharts extends LocalizeMixin(PolymerElement) {
|
|||||||
type: Object,
|
type: Object,
|
||||||
value: null,
|
value: null,
|
||||||
},
|
},
|
||||||
|
names: Object,
|
||||||
|
|
||||||
isLoadingData: Boolean,
|
isLoadingData: Boolean,
|
||||||
|
|
||||||
|
@ -5,6 +5,9 @@ import '../../../components/ha-card.js';
|
|||||||
import '../../../components/state-history-charts.js';
|
import '../../../components/state-history-charts.js';
|
||||||
import '../../../data/ha-state-history-data.js';
|
import '../../../data/ha-state-history-data.js';
|
||||||
|
|
||||||
|
import processConfigEntities from '../common/process-config-entities.js';
|
||||||
|
|
||||||
|
|
||||||
class HuiHistoryGraphCard extends PolymerElement {
|
class HuiHistoryGraphCard extends PolymerElement {
|
||||||
static get template() {
|
static get template() {
|
||||||
return html`
|
return html`
|
||||||
@ -21,7 +24,7 @@ class HuiHistoryGraphCard extends PolymerElement {
|
|||||||
<ha-state-history-data
|
<ha-state-history-data
|
||||||
hass="[[hass]]"
|
hass="[[hass]]"
|
||||||
filter-type="recent-entity"
|
filter-type="recent-entity"
|
||||||
entity-id="[[_config.entities]]"
|
entity-id="[[_entities]]"
|
||||||
data="{{stateHistory}}"
|
data="{{stateHistory}}"
|
||||||
is-loading="{{stateHistoryLoading}}"
|
is-loading="{{stateHistoryLoading}}"
|
||||||
cache-config="[[_computeCacheConfig(_config)]]"
|
cache-config="[[_computeCacheConfig(_config)]]"
|
||||||
@ -30,6 +33,7 @@ class HuiHistoryGraphCard extends PolymerElement {
|
|||||||
hass="[[hass]]"
|
hass="[[hass]]"
|
||||||
history-data="[[stateHistory]]"
|
history-data="[[stateHistory]]"
|
||||||
is-loading-data="[[stateHistoryLoading]]"
|
is-loading-data="[[stateHistoryLoading]]"
|
||||||
|
names="[[_names]]"
|
||||||
up-to-now
|
up-to-now
|
||||||
no-single
|
no-single
|
||||||
></state-history-charts>
|
></state-history-charts>
|
||||||
@ -41,7 +45,11 @@ class HuiHistoryGraphCard extends PolymerElement {
|
|||||||
return {
|
return {
|
||||||
hass: Object,
|
hass: Object,
|
||||||
_config: Object,
|
_config: Object,
|
||||||
stateHistory: Object,
|
stateHistory: {
|
||||||
|
type: Object,
|
||||||
|
},
|
||||||
|
_names: Array,
|
||||||
|
_entities: Object,
|
||||||
stateHistoryLoading: Boolean,
|
stateHistoryLoading: Boolean,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -51,11 +59,20 @@ class HuiHistoryGraphCard extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
if (!config.entities || !Array.isArray(config.entities)) {
|
const entities = processConfigEntities(config.entities);
|
||||||
throw new Error('Error in card configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
|
|
||||||
|
const _entities = [];
|
||||||
|
const _names = {};
|
||||||
|
for (const entity of entities) {
|
||||||
|
_entities.push(entity.entity);
|
||||||
|
if (entity.name) {
|
||||||
|
_names[entity.entity] = entity.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._entities = _entities;
|
||||||
|
this._names = _names;
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeCacheConfig(config) {
|
_computeCacheConfig(config) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user