diff --git a/src/cards/state-card-configurator.js b/src/cards/state-card-configurator.js index 3b7194efd3..a41210e080 100644 --- a/src/cards/state-card-configurator.js +++ b/src/cards/state-card-configurator.js @@ -11,4 +11,4 @@ export default Polymer({ type: Object, }, }, -}); \ No newline at end of file +}); diff --git a/src/cards/state-card-toggle.js b/src/cards/state-card-toggle.js index 57bb6b46d9..3943be5a46 100644 --- a/src/cards/state-card-toggle.js +++ b/src/cards/state-card-toggle.js @@ -20,7 +20,6 @@ export default Polymer({ }, ready() { - this.forceStateChange = this.forceStateChange.bind(this); this.forceStateChange(); }, @@ -57,7 +56,7 @@ export default Polymer({ // 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, // the resync is not called automatic. - serviceActions.callTurnOn(this.stateObj.entityId).then(this.forceStateChange); + serviceActions.callTurnOn(this.stateObj.entityId).then(() => this.forceStateChange()); }, turn_off() { @@ -65,6 +64,6 @@ export default Polymer({ // 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, // the resync is not called automatic. - serviceActions.callTurnOff(this.stateObj.entityId).then(this.forceStateChange); + serviceActions.callTurnOff(this.stateObj.entityId).then(() => this.forceStateChange()); }, }); diff --git a/src/cards/state-card.js b/src/cards/state-card.js index 7f99f2c01e..408ebcdb9d 100644 --- a/src/cards/state-card.js +++ b/src/cards/state-card.js @@ -19,7 +19,6 @@ export default Polymer({ cardTapped(ev) { ev.stopPropagation(); - this.async(moreInfoActions.selectEntity.bind( - this, this.stateObj.entityId), 100); + this.async(() => moreInfoActions.selectEntity(this.stateObj.entityId), 100); }, }); diff --git a/src/components/display-time.js b/src/components/display-time.js index 79b9fe0732..53170464ab 100644 --- a/src/components/display-time.js +++ b/src/components/display-time.js @@ -11,7 +11,7 @@ export default Polymer({ }, }, - computeTime: function(dateObj) { + computeTime(dateObj) { return dateObj ? formatTime(dateObj) : ''; }, }); diff --git a/src/components/entity-list.js b/src/components/entity-list.js index ad00894ee9..b6d8831916 100644 --- a/src/components/entity-list.js +++ b/src/components/entity-list.js @@ -13,16 +13,12 @@ export default Polymer({ type: Array, bindNuclear: [ entityGetters.entityMap, - function(map) { - return map.valueSeq(). - sortBy(function(entity) { return entity.entityId; }) - .toArray(); - }, + (map) => map.valueSeq().sortBy((entity) => entity.entityId).toArray() ], }, }, - entitySelected: function(ev) { + entitySelected(ev) { ev.preventDefault(); this.fire('entity-selected', {entityId: ev.model.entity.entityId}); }, diff --git a/src/components/events-list.js b/src/components/events-list.js index b73eb613d7..dcbbec3eea 100644 --- a/src/components/events-list.js +++ b/src/components/events-list.js @@ -13,11 +13,7 @@ export default Polymer({ type: Array, bindNuclear: [ eventGetters.entityMap, - function(map) { - return map.valueSeq() - .sortBy(function(event) { return event.event; }) - .toArray(); - } + (map) => map.valueSeq().sortBy((event) => event.event).toArray() ], }, }, diff --git a/src/components/ha-color-picker.js b/src/components/ha-color-picker.js index ecff57e7c2..c8e65cf88c 100644 --- a/src/components/ha-color-picker.js +++ b/src/components/ha-color-picker.js @@ -78,8 +78,7 @@ export default Polymer({ if (this.mouseMoveIsThrottled) { this.mouseMoveIsThrottled = false; this.onColorSelect(e); - this.async( - function() { this.mouseMoveIsThrottled = true; }.bind(this), 100); + this.async(() => this.mouseMoveIsThrottled = true, 100); } }, diff --git a/src/components/ha-logbook.js b/src/components/ha-logbook.js index 1e4d6c2264..6d7b128b45 100644 --- a/src/components/ha-logbook.js +++ b/src/components/ha-logbook.js @@ -12,7 +12,7 @@ Polymer({ }, }, - noEntries: function(entries) { + noEntries(entries) { return !entries.length; } }); diff --git a/src/components/ha-sidebar.js b/src/components/ha-sidebar.js index 6c21780f12..99809ca76d 100644 --- a/src/components/ha-sidebar.js +++ b/src/components/ha-sidebar.js @@ -36,7 +36,7 @@ Polymer({ value: [], bindNuclear: [ navigationGetters.possibleEntityDomainFilters, - function(domains) { return domains.toArray(); } + (domains) => domains.toArray() ], }, diff --git a/src/components/services-list.js b/src/components/services-list.js index 26f89f8a2e..f7f72e90eb 100644 --- a/src/components/services-list.js +++ b/src/components/services-list.js @@ -15,11 +15,7 @@ export default Polymer({ type: Array, bindNuclear: [ serviceGetters.entityMap, - function(map) { - return map.valueSeq() - .sortBy(function(domain) { return domain.domain; }) - .toJS(); - }, + (map) => map.valueSeq().sortBy((domain) => domain.domain).toJS() ], }, }, diff --git a/src/components/state-history-chart-line.js b/src/components/state-history-chart-line.js index a6e96d88b8..72dcb0f60a 100644 --- a/src/components/state-history-chart-line.js +++ b/src/components/state-history-chart-line.js @@ -30,15 +30,15 @@ export default Polymer({ }, }, - created: function() { + created() { this.style.display = 'block'; }, - attached: function() { + attached() { this.isAttached = true; }, - dataChanged: function() { + dataChanged() { this.drawChart(); }, @@ -115,11 +115,7 @@ export default Polymer({ // Get a unique list of times of state changes for all the device // for a particular unit of measureent. var times = pluck(flatten(deviceStates), "lastChangedAsDate"); - times = uniq(times, function(e) { - return e.getTime(); - }); - - times = sortBy(times, function(o) { return o; }); + times = sortBy(uniq(times, (e) => e.getTime())); var data = []; var empty = new Array(deviceStates.length); @@ -143,9 +139,8 @@ export default Polymer({ } data.push([endDate].concat(empty)); - var deviceCount = 0; - deviceStates.forEach(function(device) { + deviceStates.forEach((device) => { var attributes = device[device.length - 1].attributes; dataTable.addColumn('number', attributes.friendly_name); @@ -154,7 +149,7 @@ export default Polymer({ var lastIndex = 0; var count = 0; var prevTime = data[0][0]; - device.forEach(function(state) { + device.forEach((state) => { currentState = state.state; var start = state.lastChangedAsDate; @@ -178,7 +173,7 @@ export default Polymer({ previousState = currentState; count++; - }.bind(this)); + }); //fill in the rest of the Array for(var i = lastIndex; i < data.length; i++) { @@ -186,7 +181,7 @@ export default Polymer({ } deviceCount++; - }.bind(this)); + }); dataTable.addRows(data); chart.draw(dataTable, options); diff --git a/src/components/state-history-chart-timeline.js b/src/components/state-history-chart-timeline.js index 64cf0031b3..21400075e9 100644 --- a/src/components/state-history-chart-timeline.js +++ b/src/components/state-history-chart-timeline.js @@ -53,10 +53,8 @@ export default Polymer({ }; var startTime = new Date( - stateHistory.reduce(function(minTime, stateInfo) { - return Math.min( - minTime, stateInfo[0].lastChangedAsDate); - }, new Date()) + stateHistory.reduce((minTime, stateInfo) => Math.min( + minTime, stateInfo[0].lastChangedAsDate), new Date()) ); // end time is Math.min(curTime, start time + 1 day) @@ -68,13 +66,13 @@ export default Polymer({ var numTimelines = 0; // stateHistory is a list of lists of sorted state objects - stateHistory.forEach(function(stateInfo) { + stateHistory.forEach((stateInfo) => { if(stateInfo.length === 0) return; var entityDisplay = stateInfo[0].entityDisplay; var newLastChanged, prevState = null, prevLastChanged = null; - stateInfo.forEach(function(state) { + stateInfo.forEach((state) => { if (prevState !== null && state.state !== prevState) { newLastChanged = state.lastChangedAsDate; @@ -90,7 +88,7 @@ export default Polymer({ addRow(entityDisplay, prevState, prevLastChanged, endTime); numTimelines++; - }.bind(this)); + }); chart.draw(dataTable, { height: 55 + numTimelines * 42, diff --git a/src/components/state-history-charts.js b/src/components/state-history-charts.js index 83d9934991..8f5fa9b643 100644 --- a/src/components/state-history-charts.js +++ b/src/components/state-history-charts.js @@ -50,14 +50,13 @@ export default Polymer({ var lineChartDevices = {}; var timelineDevices = []; - stateHistory.forEach(function(stateInfo) { + stateHistory.forEach((stateInfo) => { if (!stateInfo || stateInfo.size === 0) { return; } - var stateWithUnit = stateInfo.find(function(state) { - return 'unit_of_measurement' in state.attributes; - }); + var stateWithUnit = stateInfo.find( + (state) => 'unit_of_measurement' in state.attributes); var unit = stateWithUnit ? stateWithUnit.attributes.unit_of_measurement : false; @@ -73,8 +72,8 @@ export default Polymer({ timelineDevices = timelineDevices.length > 0 && timelineDevices; - var unitStates = Object.keys(lineChartDevices).map(function(unit) { - return [unit, lineChartDevices[unit]]; }); + var unitStates = Object.keys(lineChartDevices).map( + (unit) => [unit, lineChartDevices[unit]]); return {line: unitStates, timeline: timelineDevices}; }, @@ -82,9 +81,7 @@ export default Polymer({ googleApiLoaded() { google.load("visualization", "1", { packages: ["timeline", "corechart"], - callback: function() { - this.apiLoaded = true; - }.bind(this) + callback: () => this.apiLoaded = true }); }, diff --git a/src/dialogs/more-info-dialog.js b/src/dialogs/more-info-dialog.js index bd18aa77f3..2084939381 100644 --- a/src/dialogs/more-info-dialog.js +++ b/src/dialogs/more-info-dialog.js @@ -32,9 +32,7 @@ export default Polymer({ type: Object, bindNuclear: [ moreInfoGetters.currentEntityHistory, - function(history) { - return history ? [history] : false; - }, + (history) => history ? [history] : false ], }, @@ -92,9 +90,7 @@ export default Polymer({ // allow dialog to render content before showing it so it is // positioned correctly. - this.async(function() { - this.dialogOpen = true; - }.bind(this), 10); + this.async(() => this.dialogOpen = true, 10); }, dialogOpenChanged(newVal) { diff --git a/src/layouts/login-form.js b/src/layouts/login-form.js index b8a8e62088..abbeff393b 100644 --- a/src/layouts/login-form.js +++ b/src/layouts/login-form.js @@ -45,7 +45,7 @@ export default Polymer({ isValidatingChanged: function(newVal) { if (!newVal) { - this.async(function() { this.$.passwordInput.focus(); }.bind(this), 10); + this.async(() => this.$.passwordInput.focus(), 10); } }, diff --git a/src/layouts/partial-logbook.js b/src/layouts/partial-logbook.js index eee377c5d4..faae7c47c6 100644 --- a/src/layouts/partial-logbook.js +++ b/src/layouts/partial-logbook.js @@ -39,7 +39,7 @@ export default Polymer({ type: Array, bindNuclear: [ logbookGetters.currentEntries, - function(entries) { return entries.toArray(); }, + (entries) => entries.toArray(), ], }, @@ -51,8 +51,7 @@ export default Polymer({ isStaleChanged(newVal) { if (newVal) { // isLoading wouldn't update without async <_< - this.async( - function() { logbookActions.fetchDate(this.selectedDate); }, 10); + this.async(() => logbookActions.fetchDate(this.selectedDate), 10); } }, diff --git a/src/layouts/partial-states.js b/src/layouts/partial-states.js index 40d66bb52a..1145d2fa5e 100644 --- a/src/layouts/partial-states.js +++ b/src/layouts/partial-states.js @@ -50,9 +50,7 @@ export default Polymer({ bindNuclear: [ voiceGetters.isVoiceSupported, configGetters.isComponentLoaded('conversation'), - function(isVoiceSupported, componentLoaded) { - return isVoiceSupported && componentLoaded; - } + (isVoiceSupported, componentLoaded) => isVoiceSupported && componentLoaded ] }, @@ -66,9 +64,7 @@ export default Polymer({ bindNuclear: [ voiceGetters.isListening, voiceGetters.isTransmitting, - function(isListening, isTransmitting) { - return isListening || isTransmitting; - }, + (isListening, isTransmitting) => isListening || isTransmitting ], }, @@ -79,7 +75,7 @@ export default Polymer({ // are here so a change to services causes a re-render. // we need this to decide if we show toggles for states. serviceGetters.entityMap, - function(states) { return states.toArray(); }, + (states) => states.toArray(), ], }, }, diff --git a/src/more-infos/more-info-configurator.js b/src/more-infos/more-info-configurator.js index ad674b356b..5667b8c246 100644 --- a/src/more-infos/more-info-configurator.js +++ b/src/more-infos/more-info-configurator.js @@ -61,16 +61,16 @@ export default Polymer({ }; serviceActions.callService('configurator', 'configure', data).then( - function() { + () => { this.isConfiguring = false; if (!this.isStreaming) { syncActions.fetchAll(); } - }.bind(this), - - function() { + }, + () => { this.isConfiguring = false; - }.bind(this)); + } + ); }, }); diff --git a/src/more-infos/more-info-default.js b/src/more-infos/more-info-default.js index a2c4ebf086..b06f6e2bf0 100644 --- a/src/more-infos/more-info-default.js +++ b/src/more-infos/more-info-default.js @@ -16,9 +16,7 @@ export default Polymer({ return []; } - return Object.keys(stateObj.attributes).filter(function(key) { - return FILTER_KEYS.indexOf(key) === -1; - }); + return Object.keys(stateObj.attributes).filter((key) => FILTER_KEYS.indexOf(key) === -1); }, getAttributeValue(stateObj, attribute) { diff --git a/src/more-infos/more-info-group.js b/src/more-infos/more-info-group.js index 72cc7f3ce2..70ff0cb7df 100644 --- a/src/more-infos/more-info-group.js +++ b/src/more-infos/more-info-group.js @@ -23,7 +23,7 @@ export default Polymer({ bindNuclear: [ moreInfoGetters.currentEntity, entityGetters.entityMap, - function(currentEntity, entities) { + (currentEntity, entities) => { // weird bug?? if (!currentEntity) { return; diff --git a/src/more-infos/more-info-light.js b/src/more-infos/more-info-light.js index a1aa846d3e..60bed9b2f1 100644 --- a/src/more-infos/more-info-light.js +++ b/src/more-infos/more-info-light.js @@ -27,9 +27,7 @@ export default Polymer({ this.brightnessSliderValue = newVal.attributes.brightness; } - this.async(function() { - this.fire('iron-resize'); - }.bind(this), 500); + this.async(() => this.fire('iron-resize'), 500); }, computeClassNames(stateObj) { diff --git a/src/more-infos/more-info-media_player.js b/src/more-infos/more-info-media_player.js index 0bf5a414cc..66cf823e38 100644 --- a/src/more-infos/more-info-media_player.js +++ b/src/more-infos/more-info-media_player.js @@ -86,7 +86,7 @@ export default Polymer({ this.supportsTurnOff = (newVal.attributes.supported_media_commands & 256) !== 0; } - this.async(function() { this.fire('iron-resize'); }.bind(this), 500); + this.async(() => this.fire('iron-resize'), 500); }, computeClassNames(stateObj) { diff --git a/src/more-infos/more-info-thermostat.js b/src/more-infos/more-info-thermostat.js index 235f84ded0..2bae0acfe6 100644 --- a/src/more-infos/more-info-thermostat.js +++ b/src/more-infos/more-info-thermostat.js @@ -78,10 +78,8 @@ export default Polymer({ // the resync is not called automatic. serviceActions.callService( 'thermostat', 'set_away_mode', - {entity_id: this.stateObj.entityId, away_mode: away_mode}) + { away_mode, entity_id: this.stateObj.entityId }) - .then(function() { - this.stateObjChanged(this.stateObj); - }.bind(this)); + .then(() => this.stateObjChanged(this.stateObj)); }, }); diff --git a/src/more-infos/more-info-updater.js b/src/more-infos/more-info-updater.js index 7c40f78c9a..b474a94cb1 100644 --- a/src/more-infos/more-info-updater.js +++ b/src/more-infos/more-info-updater.js @@ -10,11 +10,11 @@ export default Polymer({ }, }, - updateTapped: function(stateObj) { + updateTapped(stateObj) { serviceActions.callService('updater', 'update', {}) }, - linkTapped: function(stateObj) { + linkTapped(stateObj) { window.open(this.stateObj.attributes.link, '_blank'); }, }); diff --git a/src/util/attribute-class-names.js b/src/util/attribute-class-names.js index ef9456be78..e30c46ad04 100644 --- a/src/util/attribute-class-names.js +++ b/src/util/attribute-class-names.js @@ -1,6 +1,6 @@ export default function attributeClassNames(stateObj, attributes) { if (!stateObj) return ''; - return attributes.map(function(attribute) { - return attribute in stateObj.attributes ? 'has-' + attribute : ''; - }).join(' '); + return attributes.map( + (attribute) => attribute in stateObj.attributes ? 'has-' + attribute : '' + ).join(' '); } diff --git a/src/util/nuclear-behavior.js b/src/util/nuclear-behavior.js index 537cfee8fa..bb9facb54d 100644 --- a/src/util/nuclear-behavior.js +++ b/src/util/nuclear-behavior.js @@ -2,25 +2,24 @@ export default function NuclearObserver(reactor) { return { attached: function() { - var component = this; - this.__unwatchFns = Object.keys(component.properties).reduce( - function(unwatchFns, key) { - if (!('bindNuclear' in component.properties[key])) { + this.__unwatchFns = Object.keys(this.properties).reduce( + (unwatchFns, key) => { + if (!('bindNuclear' in this.properties[key])) { return unwatchFns; } - var getter = component.properties[key].bindNuclear; + var getter = this.properties[key].bindNuclear; if (!getter) { throw 'Undefined getter specified for key ' + key; } - component[key] = reactor.evaluate(getter); + this[key] = reactor.evaluate(getter); - return unwatchFns.concat(reactor.observe(getter, function(val) { + return unwatchFns.concat(reactor.observe(getter, (val) => { if (__DEV__) { - console.log(component, key, val); + console.log(this, key, val); } - component[key] = val; + this[key] = val; })); }, []); },