mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 14:56:37 +00:00
Be smarter when to show group toggle
This commit is contained in:
parent
7aadd6da9c
commit
be2312de03
@ -30,7 +30,7 @@
|
|||||||
<ha-card>
|
<ha-card>
|
||||||
<div class='header horizontal layout center'>
|
<div class='header horizontal layout center'>
|
||||||
<div class='flex name'>[[computeDomainTitle(domain)]]</div>
|
<div class='flex name'>[[computeDomainTitle(domain)]]</div>
|
||||||
<template is='dom-if' if='[[groupEntity]]'>
|
<template is='dom-if' if='[[showGroupToggle(groupEntity, states)]]'>
|
||||||
<ha-entity-toggle state-obj='[[groupEntity]]'></ha-entity-toggle>
|
<ha-entity-toggle state-obj='[[groupEntity]]'></ha-entity-toggle>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Polymer from '../polymer';
|
import Polymer from '../polymer';
|
||||||
import { moreInfoActions } from '../util/home-assistant-js-instance';
|
import { moreInfoActions } from '../util/home-assistant-js-instance';
|
||||||
|
import canToggle from '../util/can-toggle';
|
||||||
|
|
||||||
require('../components/ha-card');
|
require('../components/ha-card');
|
||||||
require('../components/entity/ha-entity-toggle');
|
require('../components/entity/ha-entity-toggle');
|
||||||
@ -32,4 +33,13 @@ export default new Polymer({
|
|||||||
const entityId = ev.model.item.entityId;
|
const entityId = ev.model.item.entityId;
|
||||||
this.async(() => moreInfoActions.selectEntity(entityId), 1);
|
this.async(() => moreInfoActions.selectEntity(entityId), 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showGroupToggle(groupEntity, states) {
|
||||||
|
if (!groupEntity || groupEntity.state !== 'on' && groupEntity.state !== 'off') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only show if we can toggle 2+ entities in group
|
||||||
|
return states.reduce((sum, state) => sum + canToggle(state.entityId), 0) > 1;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
reactor,
|
reactor,
|
||||||
serviceGetters,
|
serviceGetters,
|
||||||
} from '../util/home-assistant-js-instance';
|
} from './home-assistant-js-instance';
|
||||||
|
|
||||||
// Return boolean if entity can be toggled.
|
// Return boolean if entity can be toggled.
|
||||||
export default function canToggle(entityId) {
|
export default function canToggle(entityId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user