mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Force line chart for climate state history. (#1617)
* Force line chart for climate state history. * Simplify climate check
This commit is contained in:
parent
2bd5dc21a8
commit
af7a85eeb7
@ -14,7 +14,7 @@ const DOMAINS_USE_LAST_UPDATED = ['thermostat', 'climate'];
|
|||||||
const LINE_ATTRIBUTES_TO_KEEP = ['temperature', 'current_temperature', 'target_temp_low', 'target_temp_high'];
|
const LINE_ATTRIBUTES_TO_KEEP = ['temperature', 'current_temperature', 'target_temp_low', 'target_temp_high'];
|
||||||
const stateHistoryCache = {};
|
const stateHistoryCache = {};
|
||||||
|
|
||||||
function computeHistory(stateHistory, localize, language) {
|
function computeHistory(hass, stateHistory, localize, language) {
|
||||||
const lineChartDevices = {};
|
const lineChartDevices = {};
|
||||||
const timelineDevices = [];
|
const timelineDevices = [];
|
||||||
if (!stateHistory) {
|
if (!stateHistory) {
|
||||||
@ -28,8 +28,12 @@ function computeHistory(stateHistory, localize, language) {
|
|||||||
|
|
||||||
const stateWithUnit = stateInfo.find(state => 'unit_of_measurement' in state.attributes);
|
const stateWithUnit = stateInfo.find(state => 'unit_of_measurement' in state.attributes);
|
||||||
|
|
||||||
const unit = stateWithUnit ?
|
let unit = false;
|
||||||
stateWithUnit.attributes.unit_of_measurement : false;
|
if (stateWithUnit) {
|
||||||
|
unit = stateWithUnit.attributes.unit_of_measurement;
|
||||||
|
} else if (computeStateDomain(stateInfo[0]) === 'climate') {
|
||||||
|
unit = hass.config.unit_system.temperature;
|
||||||
|
}
|
||||||
|
|
||||||
if (!unit) {
|
if (!unit) {
|
||||||
timelineDevices.push({
|
timelineDevices.push({
|
||||||
@ -311,7 +315,7 @@ class HaStateHistoryData extends LocalizeMixin(PolymerElement) {
|
|||||||
// Use only data from the new fetch. Old fetch is already stored in cache.data
|
// Use only data from the new fetch. Old fetch is already stored in cache.data
|
||||||
.then(oldAndNew => oldAndNew[1])
|
.then(oldAndNew => oldAndNew[1])
|
||||||
// Convert data into format state-history-chart-* understands.
|
// Convert data into format state-history-chart-* understands.
|
||||||
.then(stateHistory => computeHistory(stateHistory, localize, language))
|
.then(stateHistory => computeHistory(this.hass, stateHistory, localize, language))
|
||||||
// Merge old and new.
|
// Merge old and new.
|
||||||
.then((stateHistory) => {
|
.then((stateHistory) => {
|
||||||
this.mergeLine(stateHistory.line, cache.data.line);
|
this.mergeLine(stateHistory.line, cache.data.line);
|
||||||
@ -341,7 +345,7 @@ class HaStateHistoryData extends LocalizeMixin(PolymerElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const prom = this.fetchRecent(entityId, startTime, endTime).then(
|
const prom = this.fetchRecent(entityId, startTime, endTime).then(
|
||||||
stateHistory => computeHistory(stateHistory, localize, language),
|
stateHistory => computeHistory(this.hass, stateHistory, localize, language),
|
||||||
() => {
|
() => {
|
||||||
RECENT_CACHE[entityId] = false;
|
RECENT_CACHE[entityId] = false;
|
||||||
return null;
|
return null;
|
||||||
@ -376,7 +380,7 @@ class HaStateHistoryData extends LocalizeMixin(PolymerElement) {
|
|||||||
const filter = startTime.toISOString() + '?end_time=' + endTime.toISOString();
|
const filter = startTime.toISOString() + '?end_time=' + endTime.toISOString();
|
||||||
|
|
||||||
const prom = this.hass.callApi('GET', 'history/period/' + filter).then(
|
const prom = this.hass.callApi('GET', 'history/period/' + filter).then(
|
||||||
stateHistory => computeHistory(stateHistory, localize, language),
|
stateHistory => computeHistory(this.hass, stateHistory, localize, language),
|
||||||
() => null
|
() => null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user