Skip to content

Commit

Permalink
Merge pull request home-assistant#80 from balloob/component-logbook
Browse files Browse the repository at this point in the history
Add component logbook
  • Loading branch information
balloob committed Mar 31, 2015
2 parents a216730 + 30e7f09 commit b02c11c
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 25 deletions.
24 changes: 20 additions & 4 deletions homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SERVICE_HOMEASSISTANT_STOP, EVENT_TIME_CHANGED, EVENT_STATE_CHANGED,
EVENT_CALL_SERVICE, ATTR_NOW, ATTR_DOMAIN, ATTR_SERVICE, MATCH_ALL,
EVENT_SERVICE_EXECUTED, ATTR_SERVICE_CALL_ID, EVENT_SERVICE_REGISTERED,
TEMP_CELCIUS, TEMP_FAHRENHEIT)
TEMP_CELCIUS, TEMP_FAHRENHEIT, ATTR_FRIENDLY_NAME)
import homeassistant.util as util

DOMAIN = "homeassistant"
Expand Down Expand Up @@ -325,19 +325,23 @@ def __str__(self):
class Event(object):
""" Represents an event within the Bus. """

__slots__ = ['event_type', 'data', 'origin']
__slots__ = ['event_type', 'data', 'origin', 'time_fired']

def __init__(self, event_type, data=None, origin=EventOrigin.local):
def __init__(self, event_type, data=None, origin=EventOrigin.local,
time_fired=None):
self.event_type = event_type
self.data = data or {}
self.origin = origin
self.time_fired = util.strip_microseconds(
time_fired or dt.datetime.now())

def as_dict(self):
""" Returns a dict representation of this Event. """
return {
'event_type': self.event_type,
'data': dict(self.data),
'origin': str(self.origin)
'origin': str(self.origin),
'time_fired': util.datetime_to_str(self.time_fired),
}

def __repr__(self):
Expand Down Expand Up @@ -482,6 +486,18 @@ def domain(self):
""" Returns domain of this state. """
return util.split_entity_id(self.entity_id)[0]

@property
def object_id(self):
""" Returns object_id of this state. """
return util.split_entity_id(self.entity_id)[1]

@property
def name(self):
""" Name to represent this state. """
return (
self.attributes.get(ATTR_FRIENDLY_NAME) or
self.object_id.replace('_', ' '))

def copy(self):
""" Creates a copy of itself. """
return State(self.entity_id, self.state,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/frontend/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "a063d1482fd49e9297d64e1329324f1c"
VERSION = "b06d3667e9e461173029ded9c0c9b815"
49 changes: 39 additions & 10 deletions homeassistant/components/frontend/www_static/frontend.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<link rel="import" href="../bower_components/polymer/polymer.html">

<link rel="import" href="../resources/moment-js.html">

<polymer-element name="display-time" attributes="dateObj">
<template>
{{ time }}
</template>
<script>
(function() {
var timeFormatOptions = {hour: 'numeric', minute: '2-digit'};
Polymer({
time: "",

dateObjChanged: function(oldVal, newVal) {
if (!newVal) {
this.time = "";
}

this.time = newVal.toLocaleTimeString([], timeFormatOptions);
},
});
})();
</script>
</polymer-element>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<link rel="import" href="../bower_components/polymer/polymer.html">

<link rel="import" href="../components/logbook-entry.html">

<polymer-element name="ha-logbook" attributes="entries" noscript>
<template>
<style>
.logbook {
}
</style>
<div class='logbook'>
<template repeat="{{entries as entry}}">
<logbook-entry entryObj="{{entry}}"></logbook-entry>
</template>
</div>
</template>
</polymer>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-style/core-style.html">

<link rel="import" href="domain-icon.html">
<link rel="import" href="display-time.html">
<link rel="import" href="relative-ha-datetime.html">

<polymer-element name="logbook-entry" attributes="entryObj">
<template>
<core-style ref='ha-main'></core-style>
<style>
.logbook-entry {
line-height: 2em;
}

.time {
width: 55px;
font-size: .8em;
}

.icon {
margin: 0 8px 0 16px;
}

.name {
text-transform: capitalize;
}

.message {

}
</style>

<div horizontal layout class='logbook-entry'>
<display-time dateObj="{{entryObj.when}}" class='time secondary-text-color'></display-time>
<domain-icon domain="{{entryObj.domain}}" class='icon primary-text-color'></domain-icon>
<div class='message primary-text-color' flex>
<template if="{{!entryObj.entityId}}">
<span class='name'>{{entryObj.name}}</span>
</template>
<template if="{{entryObj.entityId}}">
<a href='#' on-click="{{entityClicked}}" class='name'>{{entryObj.name}}</a>
</template>
{{entryObj.message}}
</div>
</div>
</template>
<script>
(function() {
var uiActions = window.hass.uiActions;

Polymer({
entityClicked: function() {
uiActions.showMoreInfoDialog(this.entryObj.entityId);
}
});

})();
</script>
</polymer-element>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<link rel="import" href="../layouts/partial-states.html">
<link rel="import" href="../layouts/partial-history.html">
<link rel="import" href="../layouts/partial-logbook.html">
<link rel="import" href="../layouts/partial-dev-fire-event.html">
<link rel="import" href="../layouts/partial-dev-call-service.html">
<link rel="import" href="../layouts/partial-dev-set-state.html">
Expand Down Expand Up @@ -96,6 +97,13 @@
</paper-item>
</template>

<template if="{{hasLogbookComponent}}">
<paper-item data-panel="logbook">
<core-icon icon="list"></core-icon>
Logbook
</paper-item>
</template>

<div flex></div>

<paper-item on-click="{{handleLogOutClick}}">
Expand Down Expand Up @@ -136,6 +144,9 @@
<template if="{{selected == 'history'}}">
<partial-history main narrow="{{narrow}}" togglePanel="{{togglePanel}}"></partial-history>
</template>
<template if="{{selected == 'logbook'}}">
<partial-logbook main narrow="{{narrow}}" togglePanel="{{togglePanel}}"></partial-logbook>
</template>
<template if="{{selected == 'fire-event'}}">
<partial-dev-fire-event main narrow="{{narrow}}" togglePanel="{{togglePanel}}"></partial-dev-fire-event>
</template>
Expand All @@ -161,6 +172,7 @@
narrow: false,
activeFilters: [],
hasHistoryComponent: false,
hasLogbookComponent: false,

isStreaming: false,
hasStreamError: false,
Expand All @@ -185,7 +197,7 @@

componentStoreChanged: function(componentStore) {
this.hasHistoryComponent = componentStore.isLoaded('history');
this.hasScriptComponent = componentStore.isLoaded('script');
this.hasLogbookComponent = componentStore.isLoaded('logbook');
},

streamStoreChanged: function(streamStore) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<link rel="import" href="../bower_components/polymer/polymer.html">

<link rel="import" href="./partial-base.html">

<link rel="import" href="../components/ha-logbook.html">

<polymer-element name="partial-logbook" attributes="narrow togglePanel">
<template>
<style>
.content {
background-color: white;
padding: 8px;
}
</style>
<partial-base narrow="{{narrow}}" togglePanel="{{togglePanel}}">
<span header-title>Logbook</span>

<span header-buttons>
<paper-icon-button icon="refresh"
on-click="{{handleRefreshClick}}"></paper-icon-button>
</span>

<div flex class="{{ {content: true, narrow: narrow, wide: !narrow} | tokenList }}">
<ha-logbook entries="{{entries}}"></ha-logbook>
</div>
</partial-base>
</template>
<script>
var storeListenerMixIn = window.hass.storeListenerMixIn;
var logbookActions = window.hass.logbookActions;

Polymer(Polymer.mixin({
entries: null,

attached: function() {
this.listenToStores(true);
},

detached: function() {
this.stopListeningToStores();
},

logbookStoreChanged: function(logbookStore) {
if (logbookStore.isStale()) {
logbookActions.fetch();
}

this.entries = logbookStore.all.toArray();
},

handleRefreshClick: function() {
logbookActions.fetch();
},
}, storeListenerMixIn));
</script>
</polymer>
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
case "media_player":
var icon = "hardware:cast";

if (state !== "idle") {
if (state && state !== "idle") {
icon += "-connected";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
<link rel="import" href="../bower_components/core-style/core-style.html">

<core-style id='ha-main'>
/* Palette generated by Material Palette - materialpalette.com/light-blue/orange */

.dark-primary-color { background: #0288D1; }
.default-primary-color { background: #03A9F4; }
.light-primary-color { background: #B3E5FC; }
.text-primary-color { color: #FFFFFF; }
.accent-color { background: #FF9800; }
.primary-text-color { color: #212121; }
.secondary-text-color { color: #727272; }
.divider-color { border-color: #B6B6B6; }

/* extra */
.accent-text-color { color: #FF9800; }

body {
color: #212121;
}

a {
color: #FF9800;
text-decoration: none;
}
</core-style>

<core-style id='ha-animations'>
@-webkit-keyframes ha-spin {
0% {
Expand Down
Loading

0 comments on commit b02c11c

Please sign in to comment.