Tweak unavailable state

pull/40/head
Paulus Schoutsen 2016-03-12 10:27:24 -08:00
parent 8187b8d964
commit ee54b13153
4 changed files with 12 additions and 13 deletions

View File

@ -1,7 +1,8 @@
import hass from '../../util/home-assistant-js-instance';
import Polymer from '../../polymer'; import Polymer from '../../polymer';
import hass from '../../util/home-assistant-js-instance';
import OFF_STATES from '../../util/off-states';
const { serviceActions } = hass; const { serviceActions } = hass;
export default new Polymer({ export default new Polymer({
@ -58,9 +59,7 @@ export default new Polymer({
}, },
computeIsOn(stateObj) { computeIsOn(stateObj) {
return stateObj && stateObj.state !== 'off' && return stateObj && OFF_STATES.indexOf(stateObj.state) === -1;
stateObj.state !== 'unlocked' && stateObj.state !== 'closed' &&
stateObj.state !== 'unavailable';
}, },
// We call updateToggle after a successful call to re-sync the toggle // We call updateToggle after a successful call to re-sync the toggle
@ -82,8 +81,8 @@ export default new Polymer({
service = turnOn ? 'turn_on' : 'turn_off'; service = turnOn ? 'turn_on' : 'turn_off';
} }
const call = serviceActions.callService(domain, service, const call = serviceActions.callService(
{ entity_id: this.stateObj.entityId }); domain, service, { entity_id: this.stateObj.entityId });
if (!this.stateObj.attributes.assumed_state) { if (!this.stateObj.attributes.assumed_state) {
call.then(() => this.forceStateChange()); call.then(() => this.forceStateChange());

View File

@ -29,11 +29,8 @@
} }
/* Color the icon if unavailable */ /* Color the icon if unavailable */
ha-state-icon[data-domain=light][data-state=unavailable], ha-state-icon[data-state=unavailable] {
ha-state-icon[data-domain=switch][data-state=unavailable], color: var(--disabled-text-color);
ha-state-icon[data-domain=binary_sensor][data-state=unavailable],
ha-state-icon[data-domain=sensor][data-state=unavailable] {
color: #D3D3D3;
} }
</style> </style>

1
src/util/off-states.js Normal file
View File

@ -0,0 +1 @@
export default ['off', 'closed', 'unlocked'];

View File

@ -12,7 +12,9 @@ const DOMAINS_WITH_CARD = [
]; ];
export default function stateCardType(state) { export default function stateCardType(state) {
if (DOMAINS_WITH_CARD.indexOf(state.domain) !== -1) { if (state.state === 'unavailable') {
return 'display';
} else if (DOMAINS_WITH_CARD.indexOf(state.domain) !== -1) {
return state.domain; return state.domain;
} else if (canToggle(state.entityId)) { } else if (canToggle(state.entityId)) {
return 'toggle'; return 'toggle';