Fix some frontend bugs

This commit is contained in:
Paulus Schoutsen 2015-02-07 21:37:50 -08:00
parent 09bf64db42
commit f8fc8c888f
6 changed files with 38 additions and 33 deletions

View file

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "be9fb38e992137e8e3b83e4ff91f9c7c"
VERSION = "db6b9c263c4be99af5b25b8c1cb20e57"

File diff suppressed because one or more lines are too long

View file

@ -47,43 +47,45 @@
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
var stateTimeToDate = function(time) {
if (!time) return new Date();
return window.hass.util.parseTime(time).toDate();
var addRow = function(entityDisplay, stateStr, start, end) {
dataTable.addRow([entityDisplay, stateStr, start, end]);
};
var addRow = function(baseState, state, tillState) {
tillState = tillState || {};
dataTable.addRow([
baseState.entityDisplay, state.state,
stateTimeToDate(state.last_changed),
stateTimeToDate(tillState.last_changed)]);
};
if (this.stateHistory.length === 0) {
return;
}
// 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.forEach(function(stateInfo) {
if(stateInfo.length === 0) return;
var baseState = new window.hass.stateModel(stateInfo[0]);
var prevRow = null;
var entityDisplay = stateInfo[0].entityDisplay;
var newLastChanged, prevState = null, prevLastChanged = null;
stateInfo.forEach(function(state) {
if (prevRow !== null && state.state !== prevRow.state) {
addRow(baseState, prevRow, state);
prevRow = state;
} else if (prevRow === null) {
prevRow = state;
if (prevState !== null && state.state !== prevState) {
newLastChanged = state.lastChangedAsDate;
addRow(entityDisplay, prevState, prevLastChanged, newLastChanged);
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));
chart.draw(dataTable, {

View file

@ -11,8 +11,11 @@
// Register some polymer filters
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) {
return (timeString || "").split(' ')[0];
};

@ -1 +1 @@
Subproject commit bf56426c553863e21790c7f1718b18e7dd89427c
Subproject commit 4bba39bf1503bd98669cb3deba0d2e17bc03336d

View file

@ -31,8 +31,8 @@
Polymer({
stateObjChanged: function() {
var rising = window.hass.util.parseTime(this.stateObj.attributes.next_rising);
var setting = window.hass.util.parseTime(this.stateObj.attributes.next_setting);
var rising = window.hass.util.parseDateTime(this.stateObj.attributes.next_rising);
var setting = window.hass.util.parseDateTime(this.stateObj.attributes.next_setting);
if(rising > setting) {
this.$.sunData.appendChild(this.$.rising);