FIx ESlint warnings

This commit is contained in:
Paulus Schoutsen 2015-08-12 20:32:36 -07:00
parent cb5ba3a80b
commit 15cb01cb5b
60 changed files with 436 additions and 458 deletions

View File

@ -25,6 +25,7 @@
"babel-eslint": "^4.0.5", "babel-eslint": "^4.0.5",
"babel-loader": "^5.3.2", "babel-loader": "^5.3.2",
"bower": "^1.4.1", "bower": "^1.4.1",
"eslint": "^1.1.0",
"eslint-config-airbnb": "0.0.7", "eslint-config-airbnb": "0.0.7",
"eslint-plugin-react": "^3.2.1", "eslint-plugin-react": "^3.2.1",
"html-minifier": "^0.7.2", "html-minifier": "^0.7.2",

View File

@ -3,7 +3,7 @@ import Polymer from '../polymer';
require('../components/state-info'); require('../components/state-info');
require('./state-card-display'); require('./state-card-display');
export default Polymer({ export default new Polymer({
is: 'state-card-configurator', is: 'state-card-configurator',
properties: { properties: {

View File

@ -9,18 +9,18 @@ require('./state-card-configurator');
require('./state-card-scene'); require('./state-card-scene');
require('./state-card-media_player'); require('./state-card-media_player');
export default Polymer({ export default new Polymer({
is: 'state-card-content', is: 'state-card-content',
properties: { properties: {
stateObj: { stateObj: {
type: Object, type: Object,
observer: 'stateObjChanged', observer: 'stateObjChanged',
} },
}, },
stateObjChanged: function(newVal, oldVal) { stateObjChanged(newVal, oldVal) {
var root = Polymer.dom(this); const root = Polymer.dom(this);
if (!newVal) { if (!newVal) {
if (root.lastChild) { if (root.lastChild) {
@ -29,14 +29,14 @@ export default Polymer({
return; return;
} }
var newCardType = stateCardType(newVal); const newCardType = stateCardType(newVal);
if (!oldVal || stateCardType(oldVal) != newCardType) { if (!oldVal || stateCardType(oldVal) !== newCardType) {
if (root.lastChild) { if (root.lastChild) {
root.removeChild(root.lastChild); root.removeChild(root.lastChild);
} }
var stateCard = document.createElement("state-card-" + newCardType); const stateCard = document.createElement(`state-card-${newCardType}`);
stateCard.stateObj = newVal; stateCard.stateObj = newVal;
root.appendChild(stateCard); root.appendChild(stateCard);
} else { } else {

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
require('../components/state-info'); require('../components/state-info');
export default Polymer({ export default new Polymer({
is: 'state-card-display', is: 'state-card-display',
properties: { properties: {

View File

@ -34,7 +34,7 @@
<state-info state-obj="[[stateObj]]"></state-info> <state-info state-obj="[[stateObj]]"></state-info>
<div class='state'> <div class='state'>
<div class='main-text'>[[computePrimaryText(stateObj, isPlaying)]]</div> <div class='main-text'>[[computePrimaryText(stateObj, isPlaying)]]</div>
<div class='secondary-text'>[[computeSecondaryText(stateObj, isPlaying)]]</div> <div class='secondary-text'>[[computeSecondaryText(stateObj)]]</div>
</div> </div>
</div> </div>
</template> </template>

View File

@ -4,7 +4,7 @@ require('../components/state-info');
const PLAYING_STATES = ['playing', 'paused']; const PLAYING_STATES = ['playing', 'paused'];
export default Polymer({ export default new Polymer({
is: 'state-card-media_player', is: 'state-card-media_player',
properties: { properties: {
@ -18,33 +18,29 @@ export default Polymer({
}, },
}, },
computeIsPlaying: function(stateObj) { computeIsPlaying(stateObj) {
return PLAYING_STATES.indexOf(stateObj.state) !== -1; return PLAYING_STATES.indexOf(stateObj.state) !== -1;
}, },
computePrimaryText: function(stateObj, isPlaying) { computePrimaryText(stateObj, isPlaying) {
return isPlaying ? stateObj.attributes.media_title : stateObj.stateDisplay; return isPlaying ? stateObj.attributes.media_title : stateObj.stateDisplay;
}, },
computeSecondaryText: function(stateObj, isPlaying) { computeSecondaryText(stateObj) {
var text; let text;
if (stateObj.attributes.media_content_type == 'music') { if (stateObj.attributes.media_content_type === 'music') {
return stateObj.attributes.media_artist; return stateObj.attributes.media_artist;
} else if (stateObj.attributes.media_content_type === 'tvshow') {
} else if (stateObj.attributes.media_content_type == 'tvshow') {
text = stateObj.attributes.media_series_title; text = stateObj.attributes.media_series_title;
if (stateObj.attributes.media_season && stateObj.attributes.media_episode) { if (stateObj.attributes.media_season && stateObj.attributes.media_episode) {
text += ` S${stateObj.attributes.media_season}E${stateObj.attributes.media_episode}`; text += ` S${stateObj.attributes.media_season}E${stateObj.attributes.media_episode}`;
} }
return text; return text;
} else if (stateObj.attributes.app_name) { } else if (stateObj.attributes.app_name) {
return stateObj.attributes.app_name; return stateObj.attributes.app_name;
} else {
return '';
} }
return '';
}, },
}); });

View File

@ -3,7 +3,7 @@ import Polymer from '../polymer';
require('./state-card-display'); require('./state-card-display');
require('./state-card-toggle'); require('./state-card-toggle');
export default Polymer({ export default new Polymer({
is: 'state-card-scene', is: 'state-card-scene',
properties: { properties: {
@ -18,7 +18,7 @@ export default Polymer({
}, },
}, },
computeAllowToggle: function(stateObj) { computeAllowToggle(stateObj) {
return stateObj.state === 'off' || stateObj.attributes.active_requested; return stateObj.state === 'off' || stateObj.attributes.active_requested;
}, },
}); });

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
require('../components/state-info'); require('../components/state-info');
export default Polymer({ export default new Polymer({
is: 'state-card-thermostat', is: 'state-card-thermostat',
properties: { properties: {

View File

@ -4,7 +4,7 @@ import Polymer from '../polymer';
require('../components/state-info'); require('../components/state-info');
export default Polymer({ export default new Polymer({
is: 'state-card-toggle', is: 'state-card-toggle',
properties: { properties: {
@ -28,11 +28,11 @@ export default Polymer({
}, },
toggleChanged(ev) { toggleChanged(ev) {
var newVal = ev.target.checked; const newVal = ev.target.checked;
if(newVal && this.stateObj.state === "off") { if (newVal && this.stateObj.state === 'off') {
this.turn_on(); this.turn_on();
} else if(!newVal && this.stateObj.state === "on") { } else if (!newVal && this.stateObj.state === 'on') {
this.turn_off(); this.turn_off();
} }
}, },
@ -44,7 +44,7 @@ export default Polymer({
}, },
updateToggle(stateObj) { updateToggle(stateObj) {
this.toggleChecked = stateObj && stateObj.state === "on"; this.toggleChecked = stateObj && stateObj.state === 'on';
}, },
forceStateChange() { forceStateChange() {

View File

@ -4,7 +4,7 @@ import Polymer from '../polymer';
require('./state-card-content'); require('./state-card-content');
export default Polymer({ export default new Polymer({
is: 'state-card', is: 'state-card',
properties: { properties: {

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
import formatTime from '../util/format-time'; import formatTime from '../util/format-time';
export default Polymer({ export default new Polymer({
is: 'display-time', is: 'display-time',
properties: { properties: {

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
import domainIcon from '../util/domain-icon'; import domainIcon from '../util/domain-icon';
export default Polymer({ export default new Polymer({
is: 'domain-icon', is: 'domain-icon',
properties: { properties: {

View File

@ -3,7 +3,7 @@ import { entityGetters } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
export default Polymer({ export default new Polymer({
is: 'entity-list', is: 'entity-list',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -13,7 +13,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
entityGetters.entityMap, entityGetters.entityMap,
(map) => map.valueSeq().sortBy((entity) => entity.entityId).toArray() (map) => map.valueSeq().sortBy((entity) => entity.entityId).toArray(),
], ],
}, },
}, },

View File

@ -3,7 +3,7 @@ import { eventGetters } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
export default Polymer({ export default new Polymer({
is: 'events-list', is: 'events-list',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -13,7 +13,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
eventGetters.entityMap, eventGetters.entityMap,
(map) => map.valueSeq().sortBy((event) => event.event).toArray() (map) => map.valueSeq().sortBy((event) => event.event).toArray(),
], ],
}, },
}, },

View File

@ -11,17 +11,17 @@ import Polymer from '../polymer';
* given red, green, blue values, return the equivalent hexidecimal value * given red, green, blue values, return the equivalent hexidecimal value
* base source: http://stackoverflow.com/a/5624139 * base source: http://stackoverflow.com/a/5624139
*/ */
var componentToHex = function(c) { function componentToHex(c) {
var hex = c.toString(16); const hex = c.toString(16);
return hex.length === 1 ? "0" + hex : hex; return hex.length === 1 ? '0' + hex : hex;
}; }
var rgbToHex = function(color) { function rgbToHex(color) {
return "#" + componentToHex(color.r) + componentToHex(color.g) + return '#' + componentToHex(color.r) + componentToHex(color.g) +
componentToHex(color.b); componentToHex(color.b);
}; }
export default Polymer({ export default new Polymer({
is: 'ha-color-picker', is: 'ha-color-picker',
properties: { properties: {
@ -51,7 +51,7 @@ export default Polymer({
this.addEventListener('mousemove', this.onMouseMove); this.addEventListener('mousemove', this.onMouseMove);
}, },
onMouseUp(e) { onMouseUp() {
this.removeEventListener('mousemove', this.onMouseMove); this.removeEventListener('mousemove', this.onMouseMove);
}, },
@ -60,7 +60,7 @@ export default Polymer({
this.addEventListener('touchmove', this.onTouchMove); this.addEventListener('touchmove', this.onTouchMove);
}, },
onTouchEnd(e) { onTouchEnd() {
this.removeEventListener('touchmove', this.onTouchMove); this.removeEventListener('touchmove', this.onTouchMove);
}, },
@ -69,7 +69,7 @@ export default Polymer({
}, },
onTouchMove(e) { onTouchMove(e) {
var touch = e.touches[0]; const touch = e.touches[0];
this.onColorSelect(e, {x: touch.clientX, y: touch.clientY}); this.onColorSelect(e, {x: touch.clientX, y: touch.clientY});
}, },
@ -84,8 +84,8 @@ export default Polymer({
onColorSelect(e, coords) { onColorSelect(e, coords) {
if (this.context) { if (this.context) {
coords = coords || this.relativeMouseCoordinates(e); const colorCoords = coords || this.relativeMouseCoordinates(e);
var data = this.context.getImageData(coords.x, coords.y, 1, 1).data; const data = this.context.getImageData(colorCoords.x, colorCoords.y, 1, 1).data;
this.setColor({r: data[0], g: data[1], b: data[2]}); this.setColor({r: data[0], g: data[1], b: data[2]});
} }
@ -97,7 +97,7 @@ export default Polymer({
this.fire('colorselected', { this.fire('colorselected', {
rgb: this.color.rgb, rgb: this.color.rgb,
hex: this.color.hex hex: this.color.hex,
}); });
}, },
@ -106,17 +106,18 @@ export default Polymer({
* @returns object with x, y values * @returns object with x, y values
*/ */
relativeMouseCoordinates(e) { relativeMouseCoordinates(e) {
var x = 0, y = 0; let x = 0;
let y = 0;
if (this.canvas) { if (this.canvas) {
var rect = this.canvas.getBoundingClientRect(); const rect = this.canvas.getBoundingClientRect();
x = e.clientX - rect.left; x = e.clientX - rect.left;
y = e.clientY - rect.top; y = e.clientY - rect.top;
} }
return { return {
x: x, x: x,
y: y y: y,
}; };
}, },
@ -126,22 +127,22 @@ export default Polymer({
this.canvas = this.children[0]; this.canvas = this.children[0];
this.context = this.canvas.getContext('2d'); this.context = this.canvas.getContext('2d');
var colorGradient = this.context.createLinearGradient(0, 0, this.width, 0); const colorGradient = this.context.createLinearGradient(0, 0, this.width, 0);
colorGradient.addColorStop(0, "rgb(255,0,0)"); colorGradient.addColorStop(0, 'rgb(255,0,0)');
colorGradient.addColorStop(0.16, "rgb(255,0,255)"); colorGradient.addColorStop(0.16, 'rgb(255,0,255)');
colorGradient.addColorStop(0.32, "rgb(0,0,255)"); colorGradient.addColorStop(0.32, 'rgb(0,0,255)');
colorGradient.addColorStop(0.48, "rgb(0,255,255)"); colorGradient.addColorStop(0.48, 'rgb(0,255,255)');
colorGradient.addColorStop(0.64, "rgb(0,255,0)"); colorGradient.addColorStop(0.64, 'rgb(0,255,0)');
colorGradient.addColorStop(0.80, "rgb(255,255,0)"); colorGradient.addColorStop(0.80, 'rgb(255,255,0)');
colorGradient.addColorStop(1, "rgb(255,0,0)"); colorGradient.addColorStop(1, 'rgb(255,0,0)');
this.context.fillStyle = colorGradient; this.context.fillStyle = colorGradient;
this.context.fillRect(0, 0, this.width, this.height); this.context.fillRect(0, 0, this.width, this.height);
var bwGradient = this.context.createLinearGradient(0, 0, 0, this.height); const bwGradient = this.context.createLinearGradient(0, 0, 0, this.height);
bwGradient.addColorStop(0, "rgba(255,255,255,1)"); bwGradient.addColorStop(0, 'rgba(255,255,255,1)');
bwGradient.addColorStop(0.5, "rgba(255,255,255,0)"); bwGradient.addColorStop(0.5, 'rgba(255,255,255,0)');
bwGradient.addColorStop(0.5, "rgba(0,0,0,0)"); bwGradient.addColorStop(0.5, 'rgba(0,0,0,0)');
bwGradient.addColorStop(1, "rgba(0,0,0,1)"); bwGradient.addColorStop(1, 'rgba(0,0,0,1)');
this.context.fillStyle = bwGradient; this.context.fillStyle = bwGradient;
this.context.fillRect(0, 0, this.width, this.height); this.context.fillRect(0, 0, this.width, this.height);

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
require('./logbook-entry'); require('./logbook-entry');
Polymer({ export default new Polymer({
is: 'ha-logbook', is: 'ha-logbook',
properties: { properties: {
@ -14,5 +14,5 @@ Polymer({
noEntries(entries) { noEntries(entries) {
return !entries.length; return !entries.length;
} },
}); });

View File

@ -14,7 +14,7 @@ require('./stream-status');
const { entityDomainFilters } = util; const { entityDomainFilters } = util;
Polymer({ export default new Polymer({
is: 'ha-sidebar', is: 'ha-sidebar',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -36,7 +36,7 @@ Polymer({
value: [], value: [],
bindNuclear: [ bindNuclear: [
navigationGetters.possibleEntityDomainFilters, navigationGetters.possibleEntityDomainFilters,
(domains) => domains.toArray() (domains) => domains.toArray(),
], ],
}, },
@ -61,9 +61,9 @@ Polymer({
// if (this.menuSelected !== newVal) { // if (this.menuSelected !== newVal) {
// this.menuSelected = newVal; // this.menuSelected = newVal;
// } // }
var menuItems = this.querySelectorAll('.menu [data-panel]'); const menuItems = this.querySelectorAll('.menu [data-panel]');
for (var i = 0; i < menuItems.length; i++) { for (let i = 0; i < menuItems.length; i++) {
if (menuItems[i].getAttribute('data-panel') === newVal) { if (menuItems[i].getAttribute('data-panel') === newVal) {
menuItems[i].classList.add('selected'); menuItems[i].classList.add('selected');
} else { } else {
@ -73,8 +73,8 @@ Polymer({
}, },
menuClicked(ev) { menuClicked(ev) {
var target = ev.target; let target = ev.target;
var checks = 5; let checks = 5;
// find panel to select // find panel to select
while (checks && !target.getAttribute('data-panel')) { while (checks && !target.getAttribute('data-panel')) {
@ -96,7 +96,7 @@ Polymer({
selectPanel(newChoice) { selectPanel(newChoice) {
if (newChoice === this.selected) { if (newChoice === this.selected) {
return; return;
} else if (newChoice == 'logout') { } else if (newChoice === 'logout') {
this.handleLogOut(); this.handleLogOut();
return; return;
} }

View File

@ -3,7 +3,7 @@ import { voiceGetters } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
export default Polymer({ export default new Polymer({
is: 'ha-voice-command-progress', is: 'ha-voice-command-progress',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],

View File

@ -1,5 +1,5 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'loading-box', is: 'loading-box',
}); });

View File

@ -6,11 +6,11 @@ require('./domain-icon');
require('./display-time'); require('./display-time');
require('./relative-ha-datetime'); require('./relative-ha-datetime');
export default Polymer({ export default new Polymer({
is: 'logbook-entry', is: 'logbook-entry',
entityClicked: function(ev) { entityClicked(ev) {
ev.preventDefault(); ev.preventDefault();
moreInfoActions.selectEntity(this.entryObj.entityId); moreInfoActions.selectEntity(this.entryObj.entityId);
} },
}); });

View File

@ -6,7 +6,7 @@ const UPDATE_INTERVAL = 60000; // 60 seconds
const { parseDateTime } = util; const { parseDateTime } = util;
export default Polymer({ export default new Polymer({
is: 'relative-ha-datetime', is: 'relative-ha-datetime',
properties: { properties: {
@ -56,6 +56,6 @@ export default Polymer({
updateRelative() { updateRelative() {
this.relativeTime = this.parsedDateTime ? this.relativeTime = this.parsedDateTime ?
moment(this.parsedDateTime).fromNow() : ""; moment(this.parsedDateTime).fromNow() : '';
}, },
}); });

View File

@ -5,7 +5,7 @@ import nuclearObserver from '../util/bound-nuclear-behavior';
require('./domain-icon'); require('./domain-icon');
export default Polymer({ export default new Polymer({
is: 'services-list', is: 'services-list',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -15,7 +15,7 @@ export default Polymer({
type: Array, type: Array,
bindNuclear: [ bindNuclear: [
serviceGetters.entityMap, serviceGetters.entityMap,
(map) => map.valueSeq().sortBy((domain) => domain.domain).toJS() (map) => map.valueSeq().sortBy((domain) => domain.domain).toJS(),
], ],
}, },
}, },

View File

@ -4,7 +4,7 @@ import xyBriToRgb from '../util/xybri-to-rgb';
require('./domain-icon'); require('./domain-icon');
export default Polymer({ export default new Polymer({
is: 'state-badge', is: 'state-badge',
properties: { properties: {
@ -19,13 +19,12 @@ export default Polymer({
*/ */
updateIconColor(newVal) { updateIconColor(newVal) {
// for domain light, set color of icon to light color if available // for domain light, set color of icon to light color if available
if(newVal.domain == "light" && newVal.state == "on" && if (newVal.domain === 'light' && newVal.state === 'on' &&
newVal.attributes.brightness && newVal.attributes.xy_color) { newVal.attributes.brightness && newVal.attributes.xy_color) {
const rgb = xyBriToRgb(newVal.attributes.xy_color[0],
var rgb = xyBriToRgb(newVal.attributes.xy_color[0],
newVal.attributes.xy_color[1], newVal.attributes.xy_color[1],
newVal.attributes.brightness); newVal.attributes.brightness);
this.$.icon.style.color = "rgb(" + rgb.map(Math.floor).join(",") + ")"; this.$.icon.style.color = 'rgb(' + rgb.map(Math.floor).join(',') + ')';
} else { } else {
this.$.icon.style.color = null; this.$.icon.style.color = null;
} }

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
require('../cards/state-card'); require('../cards/state-card');
Polymer({ export default new Polymer({
is: 'state-cards', is: 'state-cards',
properties: { properties: {

View File

@ -5,7 +5,7 @@ import sortBy from 'lodash/collection/sortBy';
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'state-history-chart-line', is: 'state-history-chart-line',
properties: { properties: {
@ -66,9 +66,9 @@ export default Polymer({
return; return;
} }
var root = Polymer.dom(this); const root = Polymer.dom(this);
var unit = this.unit; const unit = this.unit;
var deviceStates = this.data; const deviceStates = this.data;
while (root.lastChild) { while (root.lastChild) {
root.removeChild(root.lastChild); root.removeChild(root.lastChild);
@ -78,29 +78,29 @@ export default Polymer({
return; return;
} }
var chart = new google.visualization.LineChart(this); const chart = new google.visualization.LineChart(this);
var dataTable = new google.visualization.DataTable(); const dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'datetime', id: 'Time' }); dataTable.addColumn({ type: 'datetime', id: 'Time' });
var options = { const options = {
legend: { position: 'top' }, legend: { position: 'top' },
titlePosition: 'none', titlePosition: 'none',
vAxes: { vAxes: {
// Adds units to the left hand side of the graph // Adds units to the left hand side of the graph
0: {title: unit} 0: {title: unit},
}, },
hAxis: { hAxis: {
format: 'H:mm' format: 'H:mm',
}, },
lineWidth: 1, lineWidth: 1,
chartArea:{left:'60',width:"95%"}, chartArea: { left: '60', width: '95%'},
explorer: { explorer: {
actions: ['dragToZoom', 'rightClickToReset', 'dragToPan'], actions: ['dragToZoom', 'rightClickToReset', 'dragToPan'],
keepInBounds: true, keepInBounds: true,
axis: 'horizontal', axis: 'horizontal',
maxZoomIn: 0.1 maxZoomIn: 0.1,
} },
}; };
if (this.isSingleDevice) { if (this.isSingleDevice) {
@ -114,54 +114,51 @@ export default Polymer({
// Get a unique list of times of state changes for all the device // Get a unique list of times of state changes for all the device
// for a particular unit of measureent. // for a particular unit of measureent.
var times = pluck(flatten(deviceStates), "lastChangedAsDate"); let times = pluck(flatten(deviceStates), 'lastChangedAsDate');
times = sortBy(uniq(times, (e) => e.getTime())); times = sortBy(uniq(times, (e) => e.getTime()));
var data = []; const data = [];
var empty = new Array(deviceStates.length); const empty = new Array(deviceStates.length);
for(var i = 0; i < empty.length; i++) { for (let i = 0; i < empty.length; i++) {
empty[i] = 0; empty[i] = 0;
} }
var timeIndex = 1; let timeIndex = 1;
var endDate = new Date(); const endDate = new Date();
var prevDate = times[0];
for (i = 0; i < times.length; i++) { for (i = 0; i < times.length; i++) {
// because we only have state changes we add an extra point at the same time // because we only have state changes we add an extra point at the same time
// that holds the previous state which makes the line display correctly // that holds the previous state which makes the line display correctly
var beforePoint = new Date(times[i]); const beforePoint = new Date(times[i]);
data.push([beforePoint].concat(empty)); data.push([beforePoint].concat(empty));
data.push([times[i]].concat(empty)); data.push([times[i]].concat(empty));
prevDate = times[i];
timeIndex++; timeIndex++;
} }
data.push([endDate].concat(empty)); data.push([endDate].concat(empty));
var deviceCount = 0; let deviceCount = 0;
deviceStates.forEach((device) => { deviceStates.forEach((device) => {
var attributes = device[device.length - 1].attributes; const attributes = device[device.length - 1].attributes;
dataTable.addColumn('number', attributes.friendly_name); dataTable.addColumn('number', attributes.friendly_name);
var currentState = 0; let currentState = 0;
var previousState = 0; let previousState = 0;
var lastIndex = 0; let lastIndex = 0;
var count = 0; let count = 0;
var prevTime = data[0][0]; let prevTime = data[0][0];
device.forEach((state) => { device.forEach((state) => {
currentState = state.state; currentState = state.state;
var start = state.lastChangedAsDate; const start = state.lastChangedAsDate;
if(state.state == 'None') { if (state.state === 'None') {
currentState = previousState; currentState = previousState;
} }
for(var i = lastIndex; i < data.length; i++) { for (let i = lastIndex; i < data.length; i++) {
data[i][1 + deviceCount] = parseFloat(previousState); data[i][1 + deviceCount] = parseFloat(previousState);
// this is where data gets filled in for each time for the particular device // this is where data gets filled in for each time for the particular device
// because for each time two entries were create we fill the first one with the // because for each time two entries were create we fill the first one with the
// previous value and the second one with the new value // previous value and the second one with the new value
if(prevTime.getTime() == data[i][0].getTime() && data[i][0].getTime() == start.getTime()) { if (prevTime.getTime() === data[i][0].getTime() && data[i][0].getTime() === start.getTime()) {
data[i][1 + deviceCount] = parseFloat(currentState); data[i][1 + deviceCount] = parseFloat(currentState);
lastIndex = i; lastIndex = i;
prevTime = data[i][0]; prevTime = data[i][0];
@ -176,7 +173,7 @@ export default Polymer({
}); });
// fill in the rest of the Array // fill in the rest of the Array
for(var i = lastIndex; i < data.length; i++) { for (let i = lastIndex; i < data.length; i++) {
data[i][1 + deviceCount] = parseFloat(previousState); data[i][1 + deviceCount] = parseFloat(previousState);
} }

View File

@ -1,6 +1,6 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'state-history-chart-timeline', is: 'state-history-chart-timeline',
properties: { properties: {
@ -28,8 +28,8 @@ export default Polymer({
if (!this.isAttached) { if (!this.isAttached) {
return; return;
} }
var root = Polymer.dom(this); const root = Polymer.dom(this);
var stateHistory = this.data; const stateHistory = this.data;
while (root.node.lastChild) { while (root.node.lastChild) {
root.node.removeChild(root.node.lastChild); root.node.removeChild(root.node.lastChild);
@ -39,38 +39,40 @@ export default Polymer({
return; return;
} }
var chart = new google.visualization.Timeline(this); const chart = new google.visualization.Timeline(this);
var dataTable = new google.visualization.DataTable(); const dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Entity' }); dataTable.addColumn({ type: 'string', id: 'Entity' });
dataTable.addColumn({ type: 'string', id: 'State' }); dataTable.addColumn({ type: 'string', id: 'State' });
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 addRow = function(entityDisplay, stateStr, start, end) { function addRow(entityDisplay, stateStr, start, end) {
stateStr = stateStr.replace(/_/g, ' '); const stateDisplay = stateStr.replace(/_/g, ' ');
dataTable.addRow([entityDisplay, stateStr, start, end]); dataTable.addRow([entityDisplay, stateDisplay, start, end]);
}; }
var startTime = new Date( const startTime = new Date(
stateHistory.reduce((minTime, stateInfo) => Math.min( stateHistory.reduce((minTime, stateInfo) => Math.min(
minTime, stateInfo[0].lastChangedAsDate), new Date()) minTime, stateInfo[0].lastChangedAsDate), new Date())
); );
// end time is Math.min(curTime, start time + 1 day) // end time is Math.min(curTime, start time + 1 day)
var endTime = new Date(startTime); let endTime = new Date(startTime);
endTime.setDate(endTime.getDate() + 1); endTime.setDate(endTime.getDate() + 1);
if (endTime > new Date()) { if (endTime > new Date()) {
endTime = new Date(); endTime = new Date();
} }
var numTimelines = 0; let numTimelines = 0;
// stateHistory is a list of lists of sorted state objects // stateHistory is a list of lists of sorted state objects
stateHistory.forEach((stateInfo) => { stateHistory.forEach((stateInfo) => {
if (stateInfo.length === 0) return; if (stateInfo.length === 0) return;
var entityDisplay = stateInfo[0].entityDisplay; const entityDisplay = stateInfo[0].entityDisplay;
var newLastChanged, prevState = null, prevLastChanged = null; let newLastChanged;
let prevState = null;
let prevLastChanged = null;
stateInfo.forEach((state) => { stateInfo.forEach((state) => {
if (prevState !== null && state.state !== prevState) { if (prevState !== null && state.state !== prevState) {
@ -94,11 +96,11 @@ export default Polymer({
height: 55 + numTimelines * 42, height: 55 + numTimelines * 42,
timeline: { timeline: {
showRowLabels: stateHistory.length > 1 showRowLabels: stateHistory.length > 1,
}, },
hAxis: { hAxis: {
format: 'H:mm' format: 'H:mm',
}, },
}); });
}, },

View File

@ -4,7 +4,7 @@ require('./loading-box');
require('./state-history-chart-timeline'); require('./state-history-chart-timeline');
require('./state-history-chart-line'); require('./state-history-chart-line');
export default Polymer({ export default new Polymer({
is: 'state-history-charts', is: 'state-history-charts',
properties: { properties: {
@ -39,7 +39,7 @@ export default Polymer({
}, },
computeIsSingleDevice(stateHistory) { computeIsSingleDevice(stateHistory) {
return stateHistory && stateHistory.size == 1; return stateHistory && stateHistory.size === 1;
}, },
computeGroupedStateHistory(isLoading, stateHistory) { computeGroupedStateHistory(isLoading, stateHistory) {
@ -47,18 +47,18 @@ export default Polymer({
return {line: [], timeline: []}; return {line: [], timeline: []};
} }
var lineChartDevices = {}; const lineChartDevices = {};
var timelineDevices = []; let timelineDevices = [];
stateHistory.forEach((stateInfo) => { stateHistory.forEach((stateInfo) => {
if (!stateInfo || stateInfo.size === 0) { if (!stateInfo || stateInfo.size === 0) {
return; return;
} }
var stateWithUnit = stateInfo.find( const stateWithUnit = stateInfo.find(
(state) => 'unit_of_measurement' in state.attributes); (state) => 'unit_of_measurement' in state.attributes);
var unit = stateWithUnit ? const unit = stateWithUnit ?
stateWithUnit.attributes.unit_of_measurement : false; stateWithUnit.attributes.unit_of_measurement : false;
if (!unit) { if (!unit) {
@ -72,16 +72,16 @@ export default Polymer({
timelineDevices = timelineDevices.length > 0 && timelineDevices; timelineDevices = timelineDevices.length > 0 && timelineDevices;
var unitStates = Object.keys(lineChartDevices).map( const unitStates = Object.keys(lineChartDevices).map(
(unit) => [unit, lineChartDevices[unit]]); (unit) => [unit, lineChartDevices[unit]]);
return {line: unitStates, timeline: timelineDevices}; return {line: unitStates, timeline: timelineDevices};
}, },
googleApiLoaded() { googleApiLoaded() {
google.load("visualization", "1", { google.load('visualization', '1', {
packages: ["timeline", "corechart"], packages: ['timeline', 'corechart'],
callback: () => this.apiLoaded = true callback: () => this.apiLoaded = true,
}); });
}, },

View File

@ -3,7 +3,7 @@ import Polymer from '../polymer';
require('./state-badge'); require('./state-badge');
require('./relative-ha-datetime'); require('./relative-ha-datetime');
export default Polymer({ export default new Polymer({
is: 'state-info', is: 'state-info',
properties: { properties: {

View File

@ -3,7 +3,7 @@ import { streamGetters, streamActions } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
export default Polymer({ export default new Polymer({
is: 'stream-status', is: 'stream-status',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -20,7 +20,7 @@ export default Polymer({
}, },
}, },
toggleChanged: function() { toggleChanged() {
if (this.isStreaming) { if (this.isStreaming) {
streamActions.stop(); streamActions.stop();
} else { } else {

View File

@ -16,7 +16,7 @@ require('../more-infos/more-info-content');
// if you don't want the history component to show add the domain to this array // if you don't want the history component to show add the domain to this array
const DOMAINS_WITH_NO_HISTORY = ['camera']; const DOMAINS_WITH_NO_HISTORY = ['camera'];
export default Polymer({ export default new Polymer({
is: 'more-info-dialog', is: 'more-info-dialog',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -32,7 +32,7 @@ export default Polymer({
type: Object, type: Object,
bindNuclear: [ bindNuclear: [
moreInfoGetters.currentEntityHistory, moreInfoGetters.currentEntityHistory,
(history) => history ? [history] : false (history) => history ? [history] : false,
], ],
}, },
@ -88,7 +88,7 @@ export default Polymer({
this.fetchHistoryData(); this.fetchHistoryData();
// allow dialog to render content before showing it so it is // allow dialog to render content before showing it so it is
// positioned correctly. // positioned correctly.
this.dialogOpen = true this.dialogOpen = true;
}, 10); }, 10);
}, },

View File

@ -2,7 +2,8 @@ import Polymer from './polymer';
import { import {
syncGetters, syncGetters,
localStoragePreferences localStoragePreferences,
startLocalStoragePreferencesSync
} from 'home-assistant-js'; } from 'home-assistant-js';
import nuclearObserver from './util/bound-nuclear-behavior'; import nuclearObserver from './util/bound-nuclear-behavior';
@ -11,7 +12,7 @@ import validateAuth from './util/validate-auth';
require('./layouts/login-form'); require('./layouts/login-form');
require('./layouts/home-assistant-main'); require('./layouts/home-assistant-main');
export default Polymer({ export default new Polymer({
is: 'home-assistant', is: 'home-assistant',
hostAttributes: { hostAttributes: {
@ -32,7 +33,7 @@ export default Polymer({
ready() { ready() {
// remove the HTML init message // remove the HTML init message
var initMsg = document.getElementById('init'); const initMsg = document.getElementById('init');
initMsg.parentElement.removeChild(initMsg); initMsg.parentElement.removeChild(initMsg);
// if auth was given, tell the backend // if auth was given, tell the backend
@ -42,6 +43,6 @@ export default Polymer({
validateAuth(localStoragePreferences.authToken, true); validateAuth(localStoragePreferences.authToken, true);
} }
localStoragePreferences.startSync(); startLocalStoragePreferencesSync();
}, },
}); });

View File

@ -1,11 +1,7 @@
import { import {
configGetters,
entityGetters,
navigationGetters, navigationGetters,
authActions, startUrlSync,
navigationActions, stopUrlSync,
urlSync,
util
} from 'home-assistant-js'; } from 'home-assistant-js';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
@ -20,7 +16,7 @@ require('../layouts/partial-dev-set-state');
require('../managers/notification-manager'); require('../managers/notification-manager');
require('../dialogs/more-info-dialog'); require('../dialogs/more-info-dialog');
export default Polymer({ export default new Polymer({
is: 'home-assistant-main', is: 'home-assistant-main',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -71,19 +67,19 @@ export default Polymer({
'open-menu': 'openDrawer', 'open-menu': 'openDrawer',
}, },
openDrawer: function() { openDrawer() {
this.$.drawer.openDrawer(); this.$.drawer.openDrawer();
}, },
activePageChanged: function() { activePageChanged() {
this.$.drawer.closeDrawer(); this.$.drawer.closeDrawer();
}, },
attached: function() { attached() {
urlSync.startSync(); startUrlSync();
}, },
detached: function() { detached() {
urlSync.stopSync(); stopUrlSync();
}, },
}); });

View File

@ -5,7 +5,7 @@ import { authGetters } from 'home-assistant-js';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
import validateAuth from '../util/validate-auth'; import validateAuth from '../util/validate-auth';
export default Polymer({ export default new Polymer({
is: 'login-form', is: 'login-form',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -37,19 +37,19 @@ export default Polymer({
'validatingChanged(isValidating, isInvalid)', 'validatingChanged(isValidating, isInvalid)',
], ],
validatingChanged: function(isValidating, isInvalid) { validatingChanged(isValidating, isInvalid) {
if (!isValidating && !isInvalid) { if (!isValidating && !isInvalid) {
this.$.passwordInput.value = ''; this.$.passwordInput.value = '';
} }
}, },
isValidatingChanged: function(newVal) { isValidatingChanged(newVal) {
if (!newVal) { if (!newVal) {
this.async(() => this.$.passwordInput.focus(), 10); this.async(() => this.$.passwordInput.focus(), 10);
} }
}, },
passwordKeyDown: function(ev) { passwordKeyDown(ev) {
// validate on enter // validate on enter
if (ev.keyCode === 13) { if (ev.keyCode === 13) {
this.validatePassword(); this.validatePassword();
@ -61,7 +61,7 @@ export default Polymer({
} }
}, },
validatePassword: function() { validatePassword() {
this.$.hideKeyboardOnFocus.focus(); this.$.hideKeyboardOnFocus.focus();
validateAuth(this.$.passwordInput.value, this.$.rememberLogin.checked); validateAuth(this.$.passwordInput.value, this.$.rememberLogin.checked);

View File

@ -1,6 +1,6 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'partial-base', is: 'partial-base',
properties: { properties: {
@ -10,7 +10,7 @@ export default Polymer({
}, },
}, },
toggleMenu: function() { toggleMenu() {
this.fire('open-menu'); this.fire('open-menu');
}, },
}); });

View File

@ -5,7 +5,7 @@ import Polymer from '../polymer';
require('./partial-base'); require('./partial-base');
require('../components/services-list'); require('../components/services-list');
export default Polymer({ export default new Polymer({
is: 'partial-dev-call-service', is: 'partial-dev-call-service',
properties: { properties: {
@ -36,12 +36,13 @@ export default Polymer({
}, },
callService() { callService() {
var serviceData; let serviceData;
try { try {
serviceData = this.serviceData ? JSON.parse(this.serviceData) : {}; serviceData = this.serviceData ? JSON.parse(this.serviceData) : {};
} catch (err) { } catch (err) {
alert("Error parsing JSON: " + err); /* eslint-disable no-alert */
alert(`Error parsing JSON: ${err}`);
/* eslint-enable no-alert */
return; return;
} }

View File

@ -5,7 +5,7 @@ import Polymer from '../polymer';
require('./partial-base'); require('./partial-base');
require('../components/events-list'); require('../components/events-list');
export default Polymer({ export default new Polymer({
is: 'partial-dev-fire-event', is: 'partial-dev-fire-event',
properties: { properties: {
@ -25,12 +25,14 @@ export default Polymer({
}, },
fireEvent() { fireEvent() {
var eventData; let eventData;
try { try {
eventData = this.eventData ? JSON.parse(this.eventData) : {}; eventData = this.eventData ? JSON.parse(this.eventData) : {};
} catch (err) { } catch (err) {
alert("Error parsing JSON: " + err); /* eslint-disable no-alert */
alert(`Error parsing JSON: ${err}`);
/* eslint-enable no-alert */
return; return;
} }

View File

@ -5,7 +5,7 @@ import Polymer from '../polymer';
require('./partial-base'); require('./partial-base');
require('../components/entity-list'); require('../components/entity-list');
export default Polymer({ export default new Polymer({
is: 'partial-dev-set-state', is: 'partial-dev-set-state',
properties: { properties: {
@ -26,7 +26,7 @@ export default Polymer({
}, },
setStateData(stateData) { setStateData(stateData) {
var value = stateData ? JSON.stringify(stateData, null, ' ') : ""; const value = stateData ? JSON.stringify(stateData, null, ' ') : '';
this.$.inputData.value = value; this.$.inputData.value = value;
@ -35,7 +35,7 @@ export default Polymer({
}, },
entitySelected(ev) { entitySelected(ev) {
var state = reactor.evaluate(entityGetters.byId(ev.detail.entityId)); const state = reactor.evaluate(entityGetters.byId(ev.detail.entityId));
this.entityId = state.entityId; this.entityId = state.entityId;
this.state = state.state; this.state = state.state;
@ -43,11 +43,13 @@ export default Polymer({
}, },
handleSetState() { handleSetState() {
var attr; let attr;
try { try {
attr = this.stateAttributes ? JSON.parse(this.stateAttributes) : {}; attr = this.stateAttributes ? JSON.parse(this.stateAttributes) : {};
} catch (err) { } catch (err) {
alert("Error parsing JSON: " + err); /* eslint-disable no-alert */
alert(`Error parsing JSON: ${err}`);
/* eslint-enable no-alert */
return; return;
} }

View File

@ -1,5 +1,4 @@
import { import {
uiActions,
entityHistoryGetters, entityHistoryGetters,
entityHistoryActions entityHistoryActions
} from 'home-assistant-js'; } from 'home-assistant-js';
@ -10,7 +9,7 @@ import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base'); require('./partial-base');
require('../components/state-history-charts'); require('../components/state-history-charts');
export default Polymer({ export default new Polymer({
is: 'partial-history', is: 'partial-history',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -45,7 +44,7 @@ export default Polymer({
isDataLoadedChanged(newVal) { isDataLoadedChanged(newVal) {
if (!newVal) { if (!newVal) {
entityHistoryActions.fetchSelectedDate(); this.async(() => entityHistoryActions.fetchSelectedDate(), 1);
} }
}, },
@ -55,7 +54,6 @@ export default Polymer({
datepickerFocus() { datepickerFocus() {
this.datePicker.adjustPosition(); this.datePicker.adjustPosition();
this.datePicker.gotoDate(moment('2015-06-30').toDate());
}, },
attached() { attached() {

View File

@ -1,4 +1,3 @@
import moment from 'moment';
import { logbookGetters, logbookActions } from 'home-assistant-js'; import { logbookGetters, logbookActions } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
@ -8,7 +7,7 @@ require('./partial-base');
require('../components/ha-logbook'); require('../components/ha-logbook');
require('../components/loading-box'); require('../components/loading-box');
export default Polymer({ export default new Polymer({
is: 'partial-logbook', is: 'partial-logbook',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -50,8 +49,7 @@ export default Polymer({
isStaleChanged(newVal) { isStaleChanged(newVal) {
if (newVal) { if (newVal) {
// isLoading wouldn't update without async <_< this.async(() => logbookActions.fetchDate(this.selectedDate), 1);
this.async(() => logbookActions.fetchDate(this.selectedDate), 10);
} }
}, },
@ -61,7 +59,6 @@ export default Polymer({
datepickerFocus() { datepickerFocus() {
this.datePicker.adjustPosition(); this.datePicker.adjustPosition();
this.datePicker.gotoDate(moment('2015-06-30').toDate());
}, },
attached() { attached() {

View File

@ -19,7 +19,7 @@ require('./partial-base');
require('../components/state-cards'); require('../components/state-cards');
require('../components/ha-voice-command-progress'); require('../components/ha-voice-command-progress');
export default Polymer({ export default new Polymer({
is: 'partial-states', is: 'partial-states',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -50,8 +50,8 @@ export default Polymer({
bindNuclear: [ bindNuclear: [
voiceGetters.isVoiceSupported, voiceGetters.isVoiceSupported,
configGetters.isComponentLoaded('conversation'), configGetters.isComponentLoaded('conversation'),
(isVoiceSupported, componentLoaded) => isVoiceSupported && componentLoaded (isVoiceSupported, componentLoaded) => isVoiceSupported && componentLoaded,
] ],
}, },
isListening: { isListening: {
@ -64,7 +64,7 @@ export default Polymer({
bindNuclear: [ bindNuclear: [
voiceGetters.isListening, voiceGetters.isListening,
voiceGetters.isTransmitting, voiceGetters.isTransmitting,
(isListening, isTransmitting) => isListening || isTransmitting (isListening, isTransmitting) => isListening || isTransmitting,
], ],
}, },

View File

@ -3,7 +3,7 @@ import { notificationGetters } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import nuclearObserver from '../util/bound-nuclear-behavior'; import nuclearObserver from '../util/bound-nuclear-behavior';
export default Polymer({ export default new Polymer({
is: 'notification-manager', is: 'notification-manager',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -20,5 +20,5 @@ export default Polymer({
if (newText) { if (newText) {
this.$.toast.show(); this.$.toast.show();
} }
} },
}); });

View File

@ -1,6 +1,6 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'more-info-camera', is: 'more-info-camera',
properties: { properties: {
@ -21,9 +21,8 @@ export default Polymer({
return 'http://194.218.96.92/jpg/image.jpg'; return 'http://194.218.96.92/jpg/image.jpg';
} else if (dialogOpen) { } else if (dialogOpen) {
return '/api/camera_proxy_stream/' + this.stateObj.entityId; return '/api/camera_proxy_stream/' + this.stateObj.entityId;
} else { }
// Return an empty image if dialog is not open // Return an empty image if dialog is not open
return 'data:image/gif;base64,R0lGODlhAQABAAAAACw='; return 'data:image/gif;base64,R0lGODlhAQABAAAAACw=';
}
}, },
}); });

View File

@ -9,7 +9,7 @@ import nuclearObserver from '../util/bound-nuclear-behavior';
require('../components/loading-box'); require('../components/loading-box');
export default Polymer({ export default new Polymer({
is: 'more-info-configurator', is: 'more-info-configurator',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -46,7 +46,7 @@ export default Polymer({
}, },
computeIsConfigurable(stateObj) { computeIsConfigurable(stateObj) {
return stateObj.state == 'configure'; return stateObj.state === 'configure';
}, },
computeSubmitCaption(stateObj) { computeSubmitCaption(stateObj) {
@ -56,8 +56,8 @@ export default Polymer({
submitClicked() { submitClicked() {
this.isConfiguring = true; this.isConfiguring = true;
var data = { const data = {
configure_id: this.stateObj.attributes.configure_id configure_id: this.stateObj.attributes.configure_id,
}; };
serviceActions.callService('configurator', 'configure', data).then( serviceActions.callService('configurator', 'configure', data).then(

View File

@ -12,7 +12,7 @@ require('./more-info-media_player');
require('./more-info-camera'); require('./more-info-camera');
require('./more-info-updater'); require('./more-info-updater');
export default Polymer({ export default new Polymer({
is: 'more-info-content', is: 'more-info-content',
properties: { properties: {
@ -28,8 +28,8 @@ export default Polymer({
}, },
}, },
dialogOpenChanged(newVal, oldVal) { dialogOpenChanged(newVal) {
var root = Polymer.dom(this); const root = Polymer.dom(this);
if (root.lastChild) { if (root.lastChild) {
root.lastChild.dialogOpen = newVal; root.lastChild.dialogOpen = newVal;
@ -37,7 +37,7 @@ export default Polymer({
}, },
stateObjChanged(newVal, oldVal) { stateObjChanged(newVal, oldVal) {
var root = Polymer.dom(this); const root = Polymer.dom(this);
if (!newVal) { if (!newVal) {
if (root.lastChild) { if (root.lastChild) {
@ -46,24 +46,20 @@ export default Polymer({
return; return;
} }
var newMoreInfoType = stateMoreInfoType(newVal); const newMoreInfoType = stateMoreInfoType(newVal);
if (!oldVal || stateMoreInfoType(oldVal) != newMoreInfoType) {
if (!oldVal || stateMoreInfoType(oldVal) !== newMoreInfoType) {
if (root.lastChild) { if (root.lastChild) {
root.removeChild(root.lastChild); root.removeChild(root.lastChild);
} }
var moreInfo = document.createElement('more-info-' + newMoreInfoType); const moreInfo = document.createElement('more-info-' + newMoreInfoType);
moreInfo.stateObj = newVal; moreInfo.stateObj = newVal;
moreInfo.dialogOpen = this.dialogOpen; moreInfo.dialogOpen = this.dialogOpen;
root.appendChild(moreInfo); root.appendChild(moreInfo);
} else { } else {
root.lastChild.dialogOpen = this.dialogOpen; root.lastChild.dialogOpen = this.dialogOpen;
root.lastChild.stateObj = newVal; root.lastChild.stateObj = newVal;
} }
}, },
}); });

View File

@ -2,7 +2,7 @@ import Polymer from '../polymer';
const FILTER_KEYS = ['entity_picture', 'friendly_name', 'unit_of_measurement']; const FILTER_KEYS = ['entity_picture', 'friendly_name', 'unit_of_measurement'];
export default Polymer({ export default new Polymer({
is: 'more-info-default', is: 'more-info-default',
properties: { properties: {

View File

@ -8,7 +8,7 @@ import nuclearObserver from '../util/bound-nuclear-behavior';
require('../cards/state-card-content'); require('../cards/state-card-content');
export default Polymer({ export default new Polymer({
is: 'more-info-group', is: 'more-info-group',
behaviors: [nuclearObserver], behaviors: [nuclearObserver],
@ -26,7 +26,7 @@ export default Polymer({
(currentEntity, entities) => { (currentEntity, entities) => {
// weird bug?? // weird bug??
if (!currentEntity) { if (!currentEntity) {
return; return [];
} }
return currentEntity.attributes.entity_id.map( return currentEntity.attributes.entity_id.map(
entities.get.bind(entities)); entities.get.bind(entities));

View File

@ -7,7 +7,7 @@ require('../components/ha-color-picker');
const ATTRIBUTE_CLASSES = ['brightness', 'xy_color']; const ATTRIBUTE_CLASSES = ['brightness', 'xy_color'];
export default Polymer({ export default new Polymer({
is: 'more-info-light', is: 'more-info-light',
properties: { properties: {
@ -19,10 +19,10 @@ export default Polymer({
brightnessSliderValue: { brightnessSliderValue: {
type: Number, type: Number,
value: 0, value: 0,
} },
}, },
stateObjChanged(newVal, oldVal) { stateObjChanged(newVal) {
if (newVal && newVal.state === 'on') { if (newVal && newVal.state === 'on') {
this.brightnessSliderValue = newVal.attributes.brightness; this.brightnessSliderValue = newVal.attributes.brightness;
} }
@ -35,7 +35,7 @@ export default Polymer({
}, },
brightnessSliderChanged(ev) { brightnessSliderChanged(ev) {
var bri = parseInt(ev.target.value); const bri = parseInt(ev.target.value, 10);
if (isNaN(bri)) return; if (isNaN(bri)) return;
@ -44,18 +44,18 @@ export default Polymer({
} else { } else {
serviceActions.callService('light', 'turn_on', { serviceActions.callService('light', 'turn_on', {
entity_id: this.stateObj.entityId, entity_id: this.stateObj.entityId,
brightness: bri brightness: bri,
}); });
} }
}, },
colorPicked(ev) { colorPicked(ev) {
var color = ev.detail.rgb; const color = ev.detail.rgb;
serviceActions.callService('light', 'turn_on', { serviceActions.callService('light', 'turn_on', {
entity_id: this.stateObj.entityId, entity_id: this.stateObj.entityId,
rgb_color: [color.r, color.g, color.b] rgb_color: [color.r, color.g, color.b],
}); });
} },
}); });

View File

@ -5,7 +5,7 @@ import attributeClassNames from '../util/attribute-class-names';
const ATTRIBUTE_CLASSES = ['volume_level']; const ATTRIBUTE_CLASSES = ['volume_level'];
export default Polymer({ export default new Polymer({
is: 'more-info-media_player', is: 'more-info-media_player',
properties: { properties: {
@ -26,7 +26,7 @@ export default Polymer({
isMuted: { isMuted: {
type: Boolean, type: Boolean,
value: false value: false,
}, },
volumeSliderValue: { volumeSliderValue: {
@ -73,8 +73,8 @@ export default Polymer({
stateObjChanged(newVal) { stateObjChanged(newVal) {
if (newVal) { if (newVal) {
this.isOff = newVal.state == 'off'; this.isOff = newVal.state === 'off';
this.isPlaying = newVal.state == 'playing'; this.isPlaying = newVal.state === 'playing';
this.volumeSliderValue = newVal.attributes.volume_level * 100; this.volumeSliderValue = newVal.attributes.volume_level * 100;
this.isMuted = newVal.attributes.is_volume_muted; this.isMuted = newVal.attributes.is_volume_muted;
this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0; this.supportsPause = (newVal.attributes.supported_media_commands & 1) !== 0;
@ -94,14 +94,14 @@ export default Polymer({
}, },
computeIsOff(stateObj) { computeIsOff(stateObj) {
return stateObj.state == 'off'; return stateObj.state === 'off';
}, },
computeMuteVolumeIcon(isMuted) { computeMuteVolumeIcon(isMuted) {
return isMuted ? 'av:volume-off' : 'av:volume-up'; return isMuted ? 'av:volume-off' : 'av:volume-up';
}, },
computePlaybackControlIcon(stateObj) { computePlaybackControlIcon() {
if (this.isPlaying) { if (this.isPlaying) {
return this.supportsPause ? 'av:pause' : 'av:stop'; return this.supportsPause ? 'av:pause' : 'av:stop';
} }
@ -121,9 +121,6 @@ export default Polymer({
}, },
handlePlaybackControl() { handlePlaybackControl() {
if (this.isPlaying && !this.supportsPause) {
alert('This case is not supported yet');
}
this.callService('media_play_pause'); this.callService('media_play_pause');
}, },
@ -139,14 +136,14 @@ export default Polymer({
}, },
volumeSliderChanged(ev) { volumeSliderChanged(ev) {
var volPercentage = parseFloat(ev.target.value); const volPercentage = parseFloat(ev.target.value);
var vol = volPercentage > 0 ? volPercentage / 100 : 0; const vol = volPercentage > 0 ? volPercentage / 100 : 0;
this.callService('volume_set', { volume_level: vol }); this.callService('volume_set', { volume_level: vol });
}, },
callService(service, data) { callService(service, data) {
data = data || {}; const serviceData = data || {};
data.entity_id = this.stateObj.entityId; serviceData.entity_id = this.stateObj.entityId;
serviceActions.callService('media_player', service, data); serviceActions.callService('media_player', service, serviceData);
}, },
}); });

View File

@ -1,6 +1,6 @@
import Polymer from '../polymer'; import Polymer from '../polymer';
export default Polymer({ export default new Polymer({
is: 'more-info-script', is: 'more-info-script',
properties: { properties: {

View File

@ -4,7 +4,7 @@ import formatTime from '../util/format-time';
const { parseDateTime } = util; const { parseDateTime } = util;
export default Polymer({ export default new Polymer({
is: 'more-info-sun', is: 'more-info-sun',
properties: { properties: {
@ -37,12 +37,12 @@ export default Polymer({
this.settingDate = parseDateTime(this.stateObj.attributes.next_setting); this.settingDate = parseDateTime(this.stateObj.attributes.next_setting);
this.settingTime = formatTime(this.settingDate); this.settingTime = formatTime(this.settingDate);
var root = Polymer.dom(this); const root = Polymer.dom(this);
if (self.risingDate > self.settingDate) { if (self.risingDate > self.settingDate) {
root.appendChild(this.$.rising); root.appendChild(this.$.rising);
} else { } else {
root.appendChild(this.$.setting); root.appendChild(this.$.setting);
} }
} },
}); });

View File

@ -1,12 +1,11 @@
import { util, serviceActions } from 'home-assistant-js'; import { serviceActions } from 'home-assistant-js';
import Polymer from '../polymer'; import Polymer from '../polymer';
import attributeClassNames from '../util/attribute-class-names'; import attributeClassNames from '../util/attribute-class-names';
const { temperatureUnits } = util;
const ATTRIBUTE_CLASSES = ['away_mode']; const ATTRIBUTE_CLASSES = ['away_mode'];
export default Polymer({ export default new Polymer({
is: 'more-info-thermostat', is: 'more-info-thermostat',
properties: { properties: {
@ -32,12 +31,12 @@ export default Polymer({
}, },
}, },
stateObjChanged(newVal, oldVal) { stateObjChanged(newVal) {
this.targetTemperatureSliderValue = this.stateObj.state; this.targetTemperatureSliderValue = newVal.state;
this.awayToggleChecked = this.stateObj.attributes.away_mode == 'on'; this.awayToggleChecked = newVal.attributes.away_mode === 'on';
this.tempMin = this.stateObj.attributes.min_temp; this.tempMin = newVal.attributes.min_temp;
this.tempMax = this.stateObj.attributes.max_temp; this.tempMax = newVal.attributes.max_temp;
}, },
computeClassNames(stateObj) { computeClassNames(stateObj) {
@ -45,18 +44,18 @@ export default Polymer({
}, },
targetTemperatureSliderChanged(ev) { targetTemperatureSliderChanged(ev) {
var temp = parseInt(ev.target.value); const temp = parseInt(ev.target.value, 10);
if (isNaN(temp)) return; if (isNaN(temp)) return;
serviceActions.callService('thermostat', 'set_temperature', { serviceActions.callService('thermostat', 'set_temperature', {
entity_id: this.stateObj.entityId, entity_id: this.stateObj.entityId,
temperature: temp temperature: temp,
}); });
}, },
toggleChanged(ev) { toggleChanged(ev) {
var newVal = ev.target.checked; const newVal = ev.target.checked;
if (newVal && this.stateObj.attributes.away_mode === 'off') { if (newVal && this.stateObj.attributes.away_mode === 'off') {
this.service_set_away(true); this.service_set_away(true);
@ -65,14 +64,14 @@ export default Polymer({
} }
}, },
service_set_away(away_mode) { service_set_away(awayMode) {
// We call stateChanged after a successful call to re-sync the toggle // We call stateChanged after a successful call to re-sync the toggle
// with the state. It will be out of sync if our service call did not // with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing, // result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic. // the resync is not called automatic.
serviceActions.callService( serviceActions.callService(
'thermostat', 'set_away_mode', 'thermostat', 'set_away_mode',
{ away_mode, entity_id: this.stateObj.entityId }) { away_mode: awayMode, entity_id: this.stateObj.entityId })
.then(() => this.stateObjChanged(this.stateObj)); .then(() => this.stateObjChanged(this.stateObj));
}, },

View File

@ -1,7 +1,6 @@
import { util } from 'home-assistant-js';
import { serviceActions } from 'home-assistant-js'; import { serviceActions } from 'home-assistant-js';
export default Polymer({ export default new Polymer({
is: 'more-info-updater', is: 'more-info-updater',
properties: { properties: {
@ -10,11 +9,11 @@ export default Polymer({
}, },
}, },
updateTapped(stateObj) { updateTapped() {
serviceActions.callService('updater', 'update', {}) serviceActions.callService('updater', 'update', {});
}, },
linkTapped(stateObj) { linkTapped() {
window.open(this.stateObj.attributes.link, '_blank'); window.open(this.stateObj.attributes.link, '_blank');
}, },
}); });

View File

@ -1,5 +1,5 @@
import { reactor } from 'home-assistant-js'; import { reactor } from 'home-assistant-js';
import NuclearObserver from './nuclear-behavior'; import nuclearObserver from './nuclear-behavior';
export default NuclearObserver(reactor); export default nuclearObserver(reactor);

View File

@ -1,64 +1,61 @@
export default function domainIcon(domain, state) { export default function domainIcon(domain, state) {
switch (domain) { switch (domain) {
case "homeassistant": case 'homeassistant':
return "home"; return 'home';
case "group": case 'group':
return "homeassistant-24:group"; return 'homeassistant-24:group';
case "device_tracker": case 'device_tracker':
return "social:person"; return 'social:person';
case "switch": case 'switch':
return "image:flash-on"; return 'image:flash-on';
case "media_player": case 'media_player':
var icon = "hardware:cast"; let icon = 'hardware:cast';
if (state && state !== "off" && state !== 'idle') { if (state && state !== 'off' && state !== 'idle') {
icon += "-connected"; icon += '-connected';
} }
return icon; return icon;
case "sun": case 'sun':
return "image:wb-sunny"; return 'image:wb-sunny';
case "light": case 'light':
return "image:wb-incandescent"; return 'image:wb-incandescent';
case "simple_alarm": case 'simple_alarm':
return "social:notifications"; return 'social:notifications';
case "notify": case 'notify':
return "announcement"; return 'announcement';
case "thermostat": case 'thermostat':
return "homeassistant-100:thermostat"; return 'homeassistant-100:thermostat';
case "sensor": case 'sensor':
return "visibility"; return 'visibility';
case "configurator": case 'configurator':
return "settings"; return 'settings';
case "conversation": case 'conversation':
return "av:hearing"; return 'av:hearing';
case "script": case 'script':
return "description"; return 'description';
case 'scene': case 'scene':
return 'social:pages'; return 'social:pages';
case 'updater': case 'updater':
if(state == "update_available") { return state === 'update_available' ?
return 'icons:cloud-download'; 'icons:cloud-download' : 'icons:cloud-done';
} else {
return 'icons:cloud-done';
}
default: default:
return "bookmark"; return 'bookmark';
}
} }
};

View File

@ -2,4 +2,4 @@ import moment from 'moment';
export default function formatDateTime(dateObj) { export default function formatDateTime(dateObj) {
return moment(dateObj).format('lll'); return moment(dateObj).format('lll');
}; }

View File

@ -2,4 +2,4 @@ import moment from 'moment';
export default function formatDate(dateObj) { export default function formatDate(dateObj) {
return moment(dateObj).format('ll'); return moment(dateObj).format('ll');
}; }

View File

@ -2,4 +2,4 @@ import moment from 'moment';
export default function formatTime(dateObj) { export default function formatTime(dateObj) {
return moment(dateObj).format('LT'); return moment(dateObj).format('LT');
}; }

View File

@ -1,34 +1,34 @@
export default function NuclearObserver(reactor) { export default function NuclearObserver(reactor) {
return { return {
attached: function() { attached() {
this.__unwatchFns = Object.keys(this.properties).reduce( this.__unwatchFns = Object.keys(this.properties).reduce(
(unwatchFns, key) => { (unwatchFns, key) => {
if (!('bindNuclear' in this.properties[key])) { if (!('bindNuclear' in this.properties[key])) {
return unwatchFns; return unwatchFns;
} }
var getter = this.properties[key].bindNuclear; const getter = this.properties[key].bindNuclear;
if (!getter) { if (!getter) {
throw 'Undefined getter specified for key ' + key; throw new Error(`Undefined getter specified for key ${key}`);
} }
this[key] = reactor.evaluate(getter); this[key] = reactor.evaluate(getter);
return unwatchFns.concat(reactor.observe(getter, (val) => { return unwatchFns.concat(reactor.observe(getter, (val) => {
if (__DEV__) { if (__DEV__) {
/* eslint-disable no-console */
console.log(this, key, val); console.log(this, key, val);
/* eslint-enable no-console */
} }
this[key] = val; this[key] = val;
})); }));
}, []); }, []);
}, },
detached: function() { detached() {
while (this.__unwatchFns.length) { while (this.__unwatchFns.length) {
this.__unwatchFns.shift()(); this.__unwatchFns.shift()();
} }
}, },
}; };
}; }

View File

@ -7,8 +7,7 @@ export default function stateCardType(state) {
if (DOMAINS_WITH_CARD.indexOf(state.domain) !== -1) { if (DOMAINS_WITH_CARD.indexOf(state.domain) !== -1) {
return state.domain; return state.domain;
} else if (reactor.evaluate(serviceGetters.canToggle(state.entityId))) { } else if (reactor.evaluate(serviceGetters.canToggle(state.entityId))) {
return "toggle"; return 'toggle';
} else {
return "display";
} }
return 'display';
} }

View File

@ -1,12 +1,11 @@
const DOMAINS_WITH_MORE_INFO = [ const DOMAINS_WITH_MORE_INFO = [
'light', 'group', 'sun', 'configurator', 'thermostat', 'script', 'light', 'group', 'sun', 'configurator', 'thermostat', 'script',
'media_player', 'camera', 'updater' 'media_player', 'camera', 'updater',
]; ];
export default function stateMoreInfoType(state) { export default function stateMoreInfoType(state) {
if (DOMAINS_WITH_MORE_INFO.indexOf(state.domain) !== -1) { if (DOMAINS_WITH_MORE_INFO.indexOf(state.domain) !== -1) {
return state.domain; return state.domain;
} else { }
return 'default'; return 'default';
} }
}