Force line chart for climate state history. (#1617)

* Force line chart for climate state history.

* Simplify climate check
This commit is contained in:
Jerad Meisner 2018-08-31 03:44:07 -07:00 committed by Paulus Schoutsen
parent 2bd5dc21a8
commit af7a85eeb7

View File

@ -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
); );