mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 09:16:38 +00:00
Fix header toggle for entity objects (#1514)
* Fix header toggle for entity objects * Finish * Lint
This commit is contained in:
parent
b32a6d58f3
commit
7b579c8e7a
@ -69,6 +69,14 @@ export const STATES_OFF = [
|
||||
'off'
|
||||
];
|
||||
|
||||
/** Domains where we allow toggle in Lovelace. */
|
||||
export const DOMAINS_TOGGLE = new Set([
|
||||
'fan',
|
||||
'input_boolean',
|
||||
'light',
|
||||
'switch'
|
||||
]);
|
||||
|
||||
/** Temperature units. */
|
||||
export const UNIT_C = '°C';
|
||||
export const UNIT_F = '°F';
|
||||
|
@ -53,7 +53,7 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) {
|
||||
<div class='header'>
|
||||
<div class="name">[[_config.title]]</div>
|
||||
<template is="dom-if" if="[[_showHeaderToggle(_config.show_header_toggle)]]">
|
||||
<hui-entities-toggle hass="[[hass]]" entities="[[_config.entities]]"></hui-entities-toggle>
|
||||
<hui-entities-toggle hass="[[hass]]" entities="[[_filterEntities(_config.entities)]]"></hui-entities-toggle>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@ -132,6 +132,11 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) {
|
||||
element.hass = hass;
|
||||
});
|
||||
}
|
||||
|
||||
_filterEntities(items) {
|
||||
return items.filter(item => (typeof item === 'string' || item.entity)).map(item =>
|
||||
(typeof item === 'string' ? item : item.entity));
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('hui-entities-card', HuiEntitiesCard);
|
||||
|
@ -7,6 +7,7 @@ import '../components/hui-image.js';
|
||||
|
||||
import computeStateDisplay from '../../../common/entity/compute_state_display.js';
|
||||
import computeStateName from '../../../common/entity/compute_state_name.js';
|
||||
import { DOMAINS_TOGGLE } from '../../../common/const.js';
|
||||
import stateIcon from '../../../common/entity/state_icon.js';
|
||||
import toggleEntity from '../common/entity/toggle-entity.js';
|
||||
import processConfigEntities from '../common/process-config-entities';
|
||||
@ -16,12 +17,6 @@ import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
||||
import NavigateMixin from '../../../mixins/navigate-mixin.js';
|
||||
import computeDomain from '../../../common/entity/compute_domain';
|
||||
|
||||
const DOMAINS_TOGGLE = new Set([
|
||||
'input_boolean',
|
||||
'light',
|
||||
'switch'
|
||||
]);
|
||||
|
||||
const STATES_OFF = new Set([
|
||||
'closed',
|
||||
'locked',
|
||||
|
@ -2,11 +2,8 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||
import '@polymer/paper-toggle-button/paper-toggle-button.js';
|
||||
|
||||
import canToggleState from '../../../common/entity/can_toggle_state.js';
|
||||
import { DOMAINS_TOGGLE } from '../../../common/const.js';
|
||||
import turnOnOffEntities from '../common/entity/turn-on-off-entities.js';
|
||||
import { STATES_OFF } from '../../../common/const.js';
|
||||
|
||||
const EXCLUDED_DOMAINS = ['cover', 'lock'];
|
||||
|
||||
class HuiEntitiesToggle extends PolymerElement {
|
||||
static get template() {
|
||||
@ -41,12 +38,12 @@ class HuiEntitiesToggle extends PolymerElement {
|
||||
}
|
||||
|
||||
_computeToggleEntities(hass, entityIds) {
|
||||
return entityIds.filter(entityId => (entityId in hass.states ?
|
||||
!EXCLUDED_DOMAINS.includes(entityId.split('.', 1)[0]) && canToggleState(hass, hass.states[entityId]) : false));
|
||||
return entityIds.filter(entityId => (entityId in hass.states &&
|
||||
DOMAINS_TOGGLE.has(entityId.split('.', 1)[0])));
|
||||
}
|
||||
|
||||
_computeIsChecked(hass, entityIds) {
|
||||
return entityIds.some(entityId => !STATES_OFF.includes(hass.states[entityId].state));
|
||||
return entityIds.some(entityId => hass.states[entityId].state === 'on');
|
||||
}
|
||||
|
||||
_callService(ev) {
|
||||
|
@ -5,15 +5,9 @@ import '../components/hui-generic-entity-row.js';
|
||||
import '../../../components/entity/ha-entity-toggle.js';
|
||||
|
||||
import computeStateDisplay from '../../../common/entity/compute_state_display.js';
|
||||
import { DOMAINS_TOGGLE } from '../../../common/const.js';
|
||||
import LocalizeMixin from '../../../mixins/localize-mixin.js';
|
||||
|
||||
const DOMAINS_TOGGLE = new Set([
|
||||
'fan',
|
||||
'input_boolean',
|
||||
'light',
|
||||
'switch'
|
||||
]);
|
||||
|
||||
/*
|
||||
* @appliesMixin LocalizeMixin
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user