Guest User

Untitled

a guest
Jun 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <!--
  2. panel_custom:
  3. - name: no-love
  4. sidebar_title: No love
  5. sidebar_icon: mdi:heart-off
  6. webcomponent_path: /home/bs/.homeassistant/panels/no-love.html
  7. -->
  8.  
  9. <dom-module id="ha-panel-no-love">
  10. <style>
  11. .error {
  12. color: red;
  13. }
  14. </style>
  15. <template>
  16. <paper-button raised on-click="_hereWeGo">Refresh</paper-button>
  17. <template is="dom-repeat" items="[[_entities]]" sort="_sortAbc">
  18. <div>[[item]]</div>
  19. </template>
  20. <template is="dom-if" if="[[_error]]">
  21. <div class="error">[[_error]]</div>
  22. </template>
  23. </template>
  24. </dom-module>
  25.  
  26. <script>
  27. class NoLove extends Polymer.Element {
  28. static get is() { return 'ha-panel-no-love'; }
  29. static get properties() {
  30. return {
  31. hass: Object,
  32. _entities: Array,
  33. _error: String,
  34. };
  35. }
  36.  
  37. _sortAbc(a, b) {
  38. return a > b ? 1 : -1;
  39. }
  40.  
  41. _hereWeGo() {
  42. this.hass.connection.sendMessagePromise({ type: 'frontend/lovelace_config' })
  43. .then((conf) => {
  44. const inLove = new Set();
  45.  
  46. conf.result.views.forEach((view) => {
  47. view.cards.forEach((card) => {
  48. if (card.entity) {
  49. inLove.add(card.entity);
  50. } else if (card.entities) {
  51. card.entities.forEach((entity) => {
  52. inLove.add(entity);
  53. });
  54. }
  55. });
  56. });
  57.  
  58. const _entities = Object.keys(this.hass.states).filter(entity => !inLove.has(entity));
  59.  
  60. this.setProperties({
  61. _entities,
  62. _errorMsg: null,
  63. })
  64. },
  65. err => this.setProperties({
  66. _entities: [],
  67. _errorMsg: err.message,
  68. })
  69. );
  70. }
  71. }
  72.  
  73. customElements.define(NoLove.is, NoLove);
  74. </script>
Add Comment
Please, Sign In to add comment