Clean up some imports

This commit is contained in:
Paulus Schoutsen
2016-07-11 23:57:17 -07:00
parent 6b226c02da
commit cf83fe5759
5 changed files with 167 additions and 152 deletions

View File

@@ -36,3 +36,79 @@
</div>
</template>
</dom-module>
<script>
/*
Leaflet clones this element before adding it to the map. This messes up
our Poylmer object and we lose the reference to the `hass` object.
That's why we refer here to window.hass instead of the hass property.
*/
Polymer({
is: 'ha-entity-marker',
properties: {
hass: {
type: Object,
},
entityId: {
type: String,
value: '',
reflectToAttribute: true,
},
state: {
type: Object,
computed: 'computeState(entityId)',
},
icon: {
type: Object,
computed: 'computeIcon(state)',
},
image: {
type: Object,
computed: 'computeImage(state)',
},
value: {
type: String,
computed: 'computeValue(state)',
},
},
listeners: {
tap: 'badgeTap',
},
badgeTap: function (ev) {
ev.stopPropagation();
if (this.entityId) {
this.async(function () {
window.hass.moreInfoActions.selectEntity(this.entityId);
}, 1);
}
},
computeState: function (entityId) {
return entityId && window.hass.reactor.evaluate(window.hass.entityGetters.byId(entityId));
},
computeIcon: function (state) {
return !state && 'home';
},
computeImage: function (state) {
return state && state.attributes.entity_picture;
},
computeValue: function (state) {
return state &&
state.entityDisplay.split(' ').map(function (part) {
return part.substr(0, 1);
}).join('');
},
});
</script>

View File

@@ -1,72 +0,0 @@
import Polymer from '../../polymer';
/*
Leaflet clones this element before adding it to the map. This messes up
our Poylmer object and we lose the reference to the `hass` object.
That's why we refer here to window.hass instead of the hass property.
*/
export default new Polymer({
is: 'ha-entity-marker',
properties: {
hass: {
type: Object,
},
entityId: {
type: String,
value: '',
reflectToAttribute: true,
},
state: {
type: Object,
computed: 'computeState(entityId)',
},
icon: {
type: Object,
computed: 'computeIcon(state)',
},
image: {
type: Object,
computed: 'computeImage(state)',
},
value: {
type: String,
computed: 'computeValue(state)',
},
},
listeners: {
tap: 'badgeTap',
},
badgeTap(ev) {
ev.stopPropagation();
if (this.entityId) {
this.async(() => window.hass.moreInfoActions.selectEntity(this.entityId), 1);
}
},
computeState(entityId) {
return entityId && window.hass.reactor.evaluate(window.hass.entityGetters.byId(entityId));
},
computeIcon(state) {
return !state && 'home';
},
computeImage(state) {
return state && state.attributes.entity_picture;
},
computeValue(state) {
return state &&
state.entityDisplay.split(' ').map(part => part.substr(0, 1)).join('');
},
});