From 0b9bd62251efe406af1be166dbd67e7518d3058b Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 5 Jan 2018 09:57:23 +0200 Subject: [PATCH] Update canToggleState with toggleable climate (#782) --- js/common/util/can_toggle_state.js | 3 +++ test-mocha/common/util/can_toggle_state_test.js | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/js/common/util/can_toggle_state.js b/js/common/util/can_toggle_state.js index c7859cedc5..c26840a7b6 100644 --- a/js/common/util/can_toggle_state.js +++ b/js/common/util/can_toggle_state.js @@ -6,6 +6,9 @@ export default function canToggleState(hass, stateObj) { if (domain === 'group') { return stateObj.state === 'on' || stateObj.state === 'off'; } + if (domain === 'climate') { + return !!((stateObj.attributes || {}).supported_features & 4096); + } return canToggleDomain(hass, domain); } diff --git a/test-mocha/common/util/can_toggle_state_test.js b/test-mocha/common/util/can_toggle_state_test.js index 21e5dd852c..d5159864da 100644 --- a/test-mocha/common/util/can_toggle_state_test.js +++ b/test-mocha/common/util/can_toggle_state_test.js @@ -37,4 +37,21 @@ describe('canToggleState', () => { }; assert.isFalse(canToggleState(hass, stateObj)); }); + + it('Detects climate with toggle', () => { + const stateObj = { + entity_id: 'climate.bla', + attributes: { + supported_features: 4096, + }, + }; + assert.isTrue(canToggleState(hass, stateObj)); + }); + + it('Detects climate without toggle', () => { + const stateObj = { + entity_id: 'climate.bla', + }; + assert.isFalse(canToggleState(hass, stateObj)); + }); });