Initial getting rid of HA-JS (#180)

Getting rid of HA-JS
This commit is contained in:
Paulus Schoutsen
2017-01-29 18:34:45 -08:00
committed by GitHub
parent 2f71369dae
commit a1057681f1
70 changed files with 1965 additions and 1085 deletions

View File

@@ -110,24 +110,26 @@ Polymer({
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
callService: function (turnOn) {
var domain;
var stateDomain = window.hassUtil.computeDomain(this.stateObj);
var serviceDomain;
var service;
var currentState;
if (this.stateObj.domain === 'lock') {
domain = 'lock';
if (stateDomain === 'lock') {
serviceDomain = 'lock';
service = turnOn ? 'lock' : 'unlock';
} else if (this.stateObj.domain === 'garage_door') {
domain = 'garage_door';
} else if (stateDomain === 'cover') {
serviceDomain = 'cover';
service = turnOn ? 'open' : 'close';
} else {
domain = 'homeassistant';
serviceDomain = 'homeassistant';
service = turnOn ? 'turn_on' : 'turn_off';
}
currentState = this.stateObj;
this.hass.serviceActions.callService(domain, service,
{ entity_id: this.stateObj.entityId })
this.hass.callService(
serviceDomain, service,
{ entity_id: this.stateObj.entity_id })
.then(function () {
setTimeout(function () {
// If after 2 seconds we have not received a state update

View File

@@ -57,13 +57,11 @@ Polymer({
badgeTap: function (ev) {
ev.stopPropagation();
this.async(function () {
this.hass.moreInfoActions.selectEntity(this.state.entityId);
}, 1);
this.fire('hass-more-info', { entityId: this.state.entity_id });
},
computeClasses: function (state) {
switch (state.domain) {
switch (window.hassUtil.computeDomain(state)) {
case 'binary_sensor':
case 'updater':
return 'blue';
@@ -73,7 +71,7 @@ Polymer({
},
computeValue: function (state) {
switch (state.domain) {
switch (window.hassUtil.computeDomain(state)) {
case 'binary_sensor':
case 'device_tracker':
case 'updater':
@@ -90,7 +88,7 @@ Polymer({
if (state.state === 'unavailable') {
return null;
}
switch (state.domain) {
switch (window.hassUtil.computeDomain(state)) {
case 'alarm_control_panel':
if (state.state === 'pending') {
return 'mdi:clock-fast';
@@ -123,7 +121,7 @@ Polymer({
if (state.state === 'unavailable') {
return 'unavai';
}
switch (state.domain) {
switch (window.hassUtil.computeDomain(state)) {
case 'device_tracker':
return state.state === 'not_home' ? 'Away' : state.state;
case 'alarm_control_panel':
@@ -142,7 +140,7 @@ Polymer({
},
computeDescription: function (state) {
return state.entityDisplay;
return window.hassUtil.computeStateName(state);
},
stateChanged: function () {

View File

@@ -38,7 +38,7 @@
<ha-state-icon
id='icon'
state-obj='[[stateObj]]'
data-domain$='[[stateObj.domain]]'
data-domain$='[[computeDomain(stateObj)]]'
data-state$='[[stateObj.state]]'
></ha-state-icon>
</template>
@@ -55,6 +55,10 @@ Polymer({
},
},
computeDomain: function (stateObj) {
return window.hassUtil.computeDomain(stateObj);
},
/**
* Called when an attribute changes that influences the color of the icon.
*/
@@ -71,9 +75,10 @@ Polymer({
// for domain light, set color of icon to light color if available and it is
// not very white (sum rgb colors < 730)
if (newVal.domain === 'light' && newVal.state === 'on' &&
newVal.attributes.rgb_color &&
newVal.attributes.rgb_color.reduce(function (cur, tot) { return cur + tot; }, 0) < 730) {
if (window.hassUtil.computeDomain(newVal) === 'light' &&
newVal.state === 'on' &&
newVal.attributes.rgb_color &&
newVal.attributes.rgb_color.reduce(function (cur, tot) { return cur + tot; }, 0) < 730) {
this.$.icon.style.color = 'rgb(' + newVal.attributes.rgb_color.join(',') + ')';
} else {
this.$.icon.style.color = null;

View File

@@ -40,7 +40,7 @@
<state-badge state-obj='[[stateObj]]'></state-badge>
<div class='info'>
<div class='name' in-dialog$='[[inDialog]]'>[[stateObj.entityDisplay]]</div>
<div class='name' in-dialog$='[[inDialog]]'>[[computeStateName(stateObj)]]</div>
<template is='dom-if' if='[[inDialog]]'>
<div class='time-ago'>
@@ -71,5 +71,9 @@ Polymer({
type: Boolean,
},
},
computeStateName: function (stateObj) {
return window.hassUtil.computeStateName(stateObj);
}
});
</script>