Default more info will show recent states

This commit is contained in:
Paulus Schoutsen 2015-01-31 20:07:04 -08:00
parent 807ceadf8b
commit e2f51ef557
7 changed files with 126 additions and 59 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 = "83b735c326edc749f0066a79a7eedbd6" VERSION = "212470c7842a8715f81fba76a3bd985f"

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,25 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-spinner/paper-spinner.html">
<polymer-element name="loading-box" attributes="text">
<template>
<style>
.text {
display: inline-block;
line-height: 28px;
vertical-align: top;
margin-left: 8px;
}
</style>
<div layout='horizontal'>
<paper-spinner active="true"></paper-spinner>
<div class='text'>{{text}}…</div>
</div>
</template>
<script>
Polymer({
text: "Loading"
});
</script>
</polymer-element>

View File

@ -1,29 +1,46 @@
<link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-style/core-style.html">
<link rel="import" href="./loading-box.html">
<polymer-element name="recent-states" attributes="api stateObj"> <polymer-element name="recent-states" attributes="api stateObj">
<template> <template>
<style> <core-style ref='ha-data-table'></core-style>
</style> <template if="{{recentStates === null}}">
<loading-box text="Loading recent states"></loading-box>
<h3>State history</h3>
<template repeat="{{recentStates as state}}">
<p>{{state.state}} - {{state.last_changed | relativeHATime}}</p>
</template> </template>
<template if="{{recentStates !== null}}">
<div layout vertical>
<template repeat="{{recentStates as state}}">
<div layout justified horizontal class='data-entry'>
<div>
{{state.state}}
</div>
<div class='data'>
{{state.last_changed | relativeHATime}}
</div>
</div>
</template>
<template if="{{recentStates.length == 0}}">
There are no recent states.
</template>
</div>
</template>
</template> </template>
<script> <script>
Polymer({ Polymer({
recentStates: [], recentStates: null,
stateObjChanged: function() { stateObjChanged: function() {
this.recentStates = []; this.recentStates = null;
this.api.call_api('GET', 'component/recorder/' + this.stateObj.entity_id + '/last_5_states', {}, this.newStates.bind(this)); this.api.call_api('GET', 'history/' + this.stateObj.entity_id + '/recent_states', {}, this.newStates.bind(this));
}, },
newStates: function(states) { newStates: function(states) {
// cut off the first one (which is the current)
this.recentStates = states.slice(1); this.recentStates = states.slice(1);
} }
}); });

View File

@ -1,22 +1,13 @@
<link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-style/core-style.html">
<link rel="import" href="../components/recent-states.html"> <link rel="import" href="../components/recent-states.html">
<polymer-element name="more-info-default" attributes="stateObj"> <polymer-element name="more-info-default" attributes="stateObj api">
<template> <template>
<core-style ref='ha-key-value-table'></core-style>
<style> <style>
.data-entry { .data-entry .value {
margin-bottom: 8px;
}
.data-entry:last-child {
margin-bottom: 0;
}
.data {
padding-left: 10px;
text-align: right;
word-break: break-all;
max-width: 200px; max-width: 200px;
} }
</style> </style>
@ -25,24 +16,32 @@
<template repeat="{{key in stateObj.attributes | getKeys}}"> <template repeat="{{key in stateObj.attributes | getKeys}}">
<div layout justified horizontal class='data-entry'> <div layout justified horizontal class='data-entry'>
<div> <div class='key'>
{{key}} {{key}}
</div> </div>
<div class='data'> <div class='value'>
{{stateObj.attributes[key]}} {{stateObj.attributes[key]}}
</div> </div>
</div> </div>
</template> </template>
<recent-states api="{{api}}" stateObj="{{stateObj}}"></recent-states> <template if="{{hasHistoryComponent}}">
<h4>Recent states</h4>
<recent-states api="{{api}}" stateObj="{{stateObj}}"></recent-states>
</template>
</div> </div>
</template> </template>
<script> <script>
Polymer({ Polymer({
hasHistoryComponent: false,
getKeys: function(obj) { getKeys: function(obj) {
return Object.keys(obj || {}); return Object.keys(obj || {});
}, },
apiChanged: function(oldVal, newVal) {
this.hasHistoryComponent = this.api && this.api.hasComponent('history');
}
}); });
</script> </script>
</polymer-element> </polymer-element>

View File

@ -1,42 +1,26 @@
<link rel="import" href="../bower_components/polymer/polymer.html"> <link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-style/core-style.html">
<polymer-element name="more-info-sun" attributes="stateObj api"> <polymer-element name="more-info-sun" attributes="stateObj api">
<template> <template>
<style> <core-style ref='ha-key-value-table'></core-style>
.data-entry {
margin-bottom: 8px;
}
.data-entry:last-child {
margin-bottom: 0;
}
.data {
text-align: right;
}
.time-ago {
color: darkgrey;
margin-top: -2px;
}
</style>
<div layout vertical id='sunData'> <div layout vertical id='sunData'>
<div layout justified horizontal class='data-entry' id='rising'> <div layout justified horizontal class='data-entry' id='rising'>
<div> <div class='key'>
Rising {{stateObj.attributes.next_rising | relativeHATime}} Rising {{stateObj.attributes.next_rising | relativeHATime}}
</div> </div>
<div class='data'> <div class='value'>
{{stateObj.attributes.next_rising | HATimeStripDate}} {{stateObj.attributes.next_rising | HATimeStripDate}}
</div> </div>
</div> </div>
<div layout justified horizontal class='data-entry' id='setting'> <div layout justified horizontal class='data-entry' id='setting'>
<div> <div class='key'>
Setting {{stateObj.attributes.next_setting | relativeHATime}} Setting {{stateObj.attributes.next_setting | relativeHATime}}
</div> </div>
<div class='data'> <div class='value'>
{{stateObj.attributes.next_setting | HATimeStripDate}} {{stateObj.attributes.next_setting | HATimeStripDate}}
</div> </div>
</div> </div>

View File

@ -55,6 +55,25 @@
html /deep/ .ha-form paper-input:first-child { html /deep/ .ha-form paper-input:first-child {
padding-top: 0; padding-top: 0;
} }
</core-style> </core-style>
<core-style id='ha-key-value-table'>
.data-entry {
margin-bottom: 8px;
}
.data-entry:last-child {
margin-bottom: 0;
}
.data-entry .key {
margin-right: 8px;
}
.data-entry .value {
text-align: right;
word-break: break-all;
}
</core-style>
</template> </template>
</polymer-element> </polymer-element>