mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 05:46:35 +00:00
Be smarter when to show group toggle
This commit is contained in:
parent
7aadd6da9c
commit
be2312de03
@ -30,7 +30,7 @@
|
||||
<ha-card>
|
||||
<div class='header horizontal layout center'>
|
||||
<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>
|
||||
</template>
|
||||
</div>
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Polymer from '../polymer';
|
||||
import { moreInfoActions } from '../util/home-assistant-js-instance';
|
||||
import canToggle from '../util/can-toggle';
|
||||
|
||||
require('../components/ha-card');
|
||||
require('../components/entity/ha-entity-toggle');
|
||||
@ -32,4 +33,13 @@ export default new Polymer({
|
||||
const entityId = ev.model.item.entityId;
|
||||
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 {
|
||||
reactor,
|
||||
serviceGetters,
|
||||
} from '../util/home-assistant-js-instance';
|
||||
} from './home-assistant-js-instance';
|
||||
|
||||
// Return boolean if entity can be toggled.
|
||||
export default function canToggle(entityId) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user