Fix some frontend bugs
This commit is contained in:
parent
09bf64db42
commit
f8fc8c888f
6 changed files with 38 additions and 33 deletions
|
@ -1,2 +1,2 @@
|
||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "be9fb38e992137e8e3b83e4ff91f9c7c"
|
VERSION = "db6b9c263c4be99af5b25b8c1cb20e57"
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -47,43 +47,45 @@
|
||||||
dataTable.addColumn({ type: 'date', id: 'Start' });
|
dataTable.addColumn({ type: 'date', id: 'Start' });
|
||||||
dataTable.addColumn({ type: 'date', id: 'End' });
|
dataTable.addColumn({ type: 'date', id: 'End' });
|
||||||
|
|
||||||
var stateTimeToDate = function(time) {
|
var addRow = function(entityDisplay, stateStr, start, end) {
|
||||||
if (!time) return new Date();
|
dataTable.addRow([entityDisplay, stateStr, start, end]);
|
||||||
|
|
||||||
return window.hass.util.parseTime(time).toDate();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var addRow = function(baseState, state, tillState) {
|
if (this.stateHistory.length === 0) {
|
||||||
tillState = tillState || {};
|
return;
|
||||||
|
}
|
||||||
dataTable.addRow([
|
|
||||||
baseState.entityDisplay, state.state,
|
|
||||||
stateTimeToDate(state.last_changed),
|
|
||||||
stateTimeToDate(tillState.last_changed)]);
|
|
||||||
};
|
|
||||||
|
|
||||||
// people can pass in history of 1 entityId or a collection.
|
// people can pass in history of 1 entityId or a collection.
|
||||||
var stateHistory = _.isArray(this.stateHistory[0]) ?
|
|
||||||
this.stateHistory : [this.stateHistory];
|
var stateHistory;
|
||||||
|
if (_.isArray(this.stateHistory[0])) {
|
||||||
|
stateHistory = this.stateHistory;
|
||||||
|
} else {
|
||||||
|
stateHistory = [this.stateHistory];
|
||||||
|
}
|
||||||
|
|
||||||
// stateHistory is a list of lists of sorted state objects
|
// stateHistory is a list of lists of sorted state objects
|
||||||
stateHistory.forEach(function(stateInfo) {
|
stateHistory.forEach(function(stateInfo) {
|
||||||
if(stateInfo.length === 0) return;
|
if(stateInfo.length === 0) return;
|
||||||
|
|
||||||
var baseState = new window.hass.stateModel(stateInfo[0]);
|
var entityDisplay = stateInfo[0].entityDisplay;
|
||||||
|
var newLastChanged, prevState = null, prevLastChanged = null;
|
||||||
var prevRow = null;
|
|
||||||
|
|
||||||
stateInfo.forEach(function(state) {
|
stateInfo.forEach(function(state) {
|
||||||
if (prevRow !== null && state.state !== prevRow.state) {
|
if (prevState !== null && state.state !== prevState) {
|
||||||
addRow(baseState, prevRow, state);
|
newLastChanged = state.lastChangedAsDate;
|
||||||
prevRow = state;
|
|
||||||
} else if (prevRow === null) {
|
addRow(entityDisplay, prevState, prevLastChanged, newLastChanged);
|
||||||
prevRow = state;
|
|
||||||
|
prevState = state.state;
|
||||||
|
prevLastChanged = newLastChanged;
|
||||||
|
} else if (prevState === null) {
|
||||||
|
prevState = state.state;
|
||||||
|
prevLastChanged = state.lastChangedAsDate;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addRow(baseState, prevRow, null);
|
addRow(entityDisplay, prevState, prevLastChanged, new Date());
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
chart.draw(dataTable, {
|
chart.draw(dataTable, {
|
||||||
|
|
|
@ -11,8 +11,11 @@
|
||||||
|
|
||||||
// Register some polymer filters
|
// Register some polymer filters
|
||||||
PolymerExpressions.prototype.relativeHATime = function(timeString) {
|
PolymerExpressions.prototype.relativeHATime = function(timeString) {
|
||||||
return window.hass.util.relativeTime(timeString);
|
if (!timeString) return;
|
||||||
|
|
||||||
|
return moment(window.hass.util.parseDateTime(timeString)).fromNow();
|
||||||
};
|
};
|
||||||
|
|
||||||
PolymerExpressions.prototype.HATimeStripDate = function(timeString) {
|
PolymerExpressions.prototype.HATimeStripDate = function(timeString) {
|
||||||
return (timeString || "").split(' ')[0];
|
return (timeString || "").split(' ')[0];
|
||||||
};
|
};
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit bf56426c553863e21790c7f1718b18e7dd89427c
|
Subproject commit 4bba39bf1503bd98669cb3deba0d2e17bc03336d
|
|
@ -31,8 +31,8 @@
|
||||||
Polymer({
|
Polymer({
|
||||||
|
|
||||||
stateObjChanged: function() {
|
stateObjChanged: function() {
|
||||||
var rising = window.hass.util.parseTime(this.stateObj.attributes.next_rising);
|
var rising = window.hass.util.parseDateTime(this.stateObj.attributes.next_rising);
|
||||||
var setting = window.hass.util.parseTime(this.stateObj.attributes.next_setting);
|
var setting = window.hass.util.parseDateTime(this.stateObj.attributes.next_setting);
|
||||||
|
|
||||||
if(rising > setting) {
|
if(rising > setting) {
|
||||||
this.$.sunData.appendChild(this.$.rising);
|
this.$.sunData.appendChild(this.$.rising);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue