mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
More conversion to ES2015
This commit is contained in:
parent
b395e3b4db
commit
7a86b86745
@ -11,4 +11,4 @@ export default Polymer({
|
||||
type: Object,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -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());
|
||||
},
|
||||
});
|
||||
|
@ -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);
|
||||
},
|
||||
});
|
||||
|
@ -11,7 +11,7 @@ export default Polymer({
|
||||
},
|
||||
},
|
||||
|
||||
computeTime: function(dateObj) {
|
||||
computeTime(dateObj) {
|
||||
return dateObj ? formatTime(dateObj) : '';
|
||||
},
|
||||
});
|
||||
|
@ -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});
|
||||
},
|
||||
|
@ -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()
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -12,7 +12,7 @@ Polymer({
|
||||
},
|
||||
},
|
||||
|
||||
noEntries: function(entries) {
|
||||
noEntries(entries) {
|
||||
return !entries.length;
|
||||
}
|
||||
});
|
||||
|
@ -36,7 +36,7 @@ Polymer({
|
||||
value: [],
|
||||
bindNuclear: [
|
||||
navigationGetters.possibleEntityDomainFilters,
|
||||
function(domains) { return domains.toArray(); }
|
||||
(domains) => domains.toArray()
|
||||
],
|
||||
},
|
||||
|
||||
|
@ -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()
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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(),
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -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));
|
||||
}
|
||||
);
|
||||
},
|
||||
});
|
||||
|
@ -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) {
|
||||
|
@ -23,7 +23,7 @@ export default Polymer({
|
||||
bindNuclear: [
|
||||
moreInfoGetters.currentEntity,
|
||||
entityGetters.entityMap,
|
||||
function(currentEntity, entities) {
|
||||
(currentEntity, entities) => {
|
||||
// weird bug??
|
||||
if (!currentEntity) {
|
||||
return;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
},
|
||||
});
|
||||
|
@ -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');
|
||||
},
|
||||
});
|
||||
|
@ -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(' ');
|
||||
}
|
||||
|
@ -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;
|
||||
}));
|
||||
}, []);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user