From a3a14080526949c0b104bc0ece810f0441d91f47 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 4 Jul 2016 09:38:30 -0700 Subject: [PATCH] Wait 2 seconds before resetting toggle to current state --- src/components/entity/ha-entity-toggle.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/components/entity/ha-entity-toggle.js b/src/components/entity/ha-entity-toggle.js index c321a41084..86f3c9ef9e 100644 --- a/src/components/entity/ha-entity-toggle.js +++ b/src/components/entity/ha-entity-toggle.js @@ -90,11 +90,15 @@ export default new Polymer({ service = turnOn ? 'turn_on' : 'turn_off'; } - const call = this.hass.serviceActions.callService( - domain, service, { entity_id: this.stateObj.entityId }); - - if (!this.stateObj.attributes.assumed_state) { - call.then(() => this.forceStateChange()); - } + const currentState = this.stateObj; + this.hass.serviceActions.callService(domain, service, + { entity_id: this.stateObj.entityId }) + .then(() => setTimeout(() => { + // If after 2 seconds we have not received a state update + // reset the switch to it's original state. + if (this.stateObj === currentState) { + this.forceStateChange(); + } + }, 2000)); }, });