Make more info dialog more store dependent

This commit is contained in:
Paulus Schoutsen 2015-02-14 10:04:56 -08:00
parent faddb5d57e
commit 4047bf0775
5 changed files with 56 additions and 26 deletions

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """ """ DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "8a29fbc60ac02a7b0ac05fcc2f69c1fd" VERSION = "3822abfa5abb0a8d60ddf434a2f341d5"

File diff suppressed because one or more lines are too long

View File

@ -25,9 +25,13 @@
</template> </template>
<script> <script>
var storeListenerMixIn = window.hass.storeListenerMixIn; var storeListenerMixIn = window.hass.storeListenerMixIn;
var stateStore = window.hass.stateStore;
var stateHistoryStore = window.hass.stateHistoryStore;
var stateHistoryActions = window.hass.stateHistoryActions;
Polymer(Polymer.mixin({ Polymer(Polymer.mixin({
stateObj: {}, entityId: false,
stateObj: null,
stateHistory: null, stateHistory: null,
hasHistoryComponent: false, hasHistoryComponent: false,
@ -36,7 +40,7 @@ Polymer(Polymer.mixin({
}, },
ready: function() { ready: function() {
this.listenToStores(true); this.listenToStores();
}, },
detached: function() { detached: function() {
@ -47,22 +51,51 @@ Polymer(Polymer.mixin({
this.hasHistoryComponent = componentStore.isLoaded('history'); this.hasHistoryComponent = componentStore.isLoaded('history');
}, },
stateHistoryStoreChanged: function(stateHistoryStore) { stateStoreChanged: function() {
if (this.hasHistoryComponent && this.stateObj && this.stateObj.entityId) { var newState;
this.stateHistory = stateHistoryStore.get(this.stateObj.entityId);
if (!this.entityId) {
newState = null;
} else { } else {
this.stateHistory = null; newState = stateStore.get(this.entityId);
}
console.log('state store changed');
if (newState !== this.stateObj) {
console.log("Setting new stateobj");
this.stateObj = newState;
} }
}, },
stateObjChanged: function() { stateHistoryStoreChanged: function() {
if (this.hasHistoryComponent) { var newHistory;
if (this.stateObj && this.stateObj.entityId &&
window.hass.stateHistoryStore.isStale(this.stateObj.entityId)) {
window.hass.stateHistoryActions.fetch(this.stateObj.entityId);
}
this.stateHistoryStoreChanged(); if (this.hasHistoryComponent && this.entityId) {
newHistory = stateHistoryStore.get(this.entityId);
} else {
newHistory = null;
}
if (newHistory !== this.stateHistory) {
this.stateHistory = newHistory;
}
},
changeEntityId: function(entityId) {
this.entityId = entityId;
if (!entityId) {
this.stateObj = null;
this.stateHistory = null;
return;
}
this.stateStoreChanged();
this.stateHistoryStoreChanged();
if (this.hasHistoryComponent && stateHistoryStore.isStale(entityId)) {
stateHistoryActions.fetch(entityId);
} }
}, },
@ -79,8 +112,9 @@ Polymer(Polymer.mixin({
} }
}, },
show: function(stateObj) { show: function(entityId) {
this.stateObj = stateObj; this.changeEntityId(entityId);
this.job('showDialogAfterRender', function() { this.job('showDialogAfterRender', function() {
this.$.dialog.toggle(); this.$.dialog.toggle();
}.bind(this)); }.bind(this));

View File

@ -83,14 +83,10 @@
<script> <script>
Polymer({ Polymer({
ready: function() { ready: function() {
var getState = window.hass.stateStore.get;
dispatcher.register(function(payload) { dispatcher.register(function(payload) {
switch (payload.actionType) { switch (payload.actionType) {
case uiActions.ACTION_SHOW_DIALOG_MORE_INFO: case uiActions.ACTION_SHOW_DIALOG_MORE_INFO:
state = getState(payload.entityId); this.$.moreInfoDialog.show(payload.entityId);
this.$.moreInfoDialog.show(state);
break; break;
} }
}.bind(this)); }.bind(this));

@ -1 +1 @@
Subproject commit 229e3bfc12ca0270c45003cf3189530c0e9a0875 Subproject commit ccd60be0610acdebf9256b0ff0be5d0e41f3cfda