Skip to content

Instantly share code, notes, and snippets.

@c727
Created June 22, 2018 17:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save c727/a1f9d84828565c08f32f994288b6347d to your computer and use it in GitHub Desktop.
Save c727/a1f9d84828565c08f32f994288b6347d to your computer and use it in GitHub Desktop.
List entities that are not in Home Assistant Lovelace UI
<!--
panel_custom:
- name: no-love
sidebar_title: No love
sidebar_icon: mdi:heart-off
webcomponent_path: /home/bs/.homeassistant/panels/no-love.html
-->
<dom-module id="ha-panel-no-love">
<style>
.error {
color: red;
}
</style>
<template>
<paper-button raised on-click="_hereWeGo">Refresh</paper-button>
<template is="dom-repeat" items="[[_entities]]" sort="_sortAbc">
<div>[[item]]</div>
</template>
<template is="dom-if" if="[[_error]]">
<div class="error">[[_error]]</div>
</template>
</template>
</dom-module>
<script>
class NoLove extends Polymer.Element {
static get is() { return 'ha-panel-no-love'; }
static get properties() {
return {
hass: Object,
_entities: Array,
_error: String,
};
}
_sortAbc(a, b) {
return a > b ? 1 : -1;
}
_hereWeGo() {
this.hass.connection.sendMessagePromise({ type: 'frontend/lovelace_config' })
.then((conf) => {
const inLove = new Set();
conf.result.views.forEach((view) => {
view.cards.forEach((card) => {
if (card.entity) {
inLove.add(card.entity);
} else if (card.entities) {
card.entities.forEach((entity) => {
inLove.add(entity);
});
}
});
});
const _entities = Object.keys(this.hass.states).filter(entity => !inLove.has(entity));
this.setProperties({
_entities,
_errorMsg: null,
})
},
err => this.setProperties({
_entities: [],
_errorMsg: err.message,
})
);
}
}
customElements.define(NoLove.is, NoLove);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment