From 6e30534e2dc906d29ce497bf0a2eacb18e36f9c5 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 3 Jul 2017 16:42:55 +0300 Subject: [PATCH] Fold binary_sensor state card into common code (#322) * Fold binary_sensor state card into common code * Check device_class per domain --- .../state-card-binary_sensor.html | 73 ------------------- src/state-summary/state-card-content.html | 1 - src/util/hass-util.html | 29 +++++++- 3 files changed, 28 insertions(+), 75 deletions(-) delete mode 100644 src/state-summary/state-card-binary_sensor.html diff --git a/src/state-summary/state-card-binary_sensor.html b/src/state-summary/state-card-binary_sensor.html deleted file mode 100644 index a349485241..0000000000 --- a/src/state-summary/state-card-binary_sensor.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index 18cee7d2e1..8c011bfcff 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -1,6 +1,5 @@ - diff --git a/src/util/hass-util.html b/src/util/hass-util.html index d14a112e28..b6915ce3bd 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -11,7 +11,6 @@ window.hassUtil.DEFAULT_ICON = 'mdi:bookmark'; window.hassUtil.OFF_STATES = ['off', 'closed', 'unlocked']; window.hassUtil.DOMAINS_WITH_CARD = [ - 'binary_sensor', 'climate', 'cover', 'configurator', @@ -433,6 +432,34 @@ window.hassUtil.computeStateState = function (stateObj) { if (stateObj.attributes.unit_of_measurement) { stateObj._stateDisplay += ' ' + stateObj.attributes.unit_of_measurement; } + if (window.hassUtil.computeDomain(stateObj) === 'binary_sensor') { + switch (stateObj.attributes.device_class) { + case 'moisture': + stateObj._stateDisplay = (stateObj._stateDisplay === 'off') ? 'dry' : 'wet'; + break; + case 'gas': + case 'motion': + case 'occupancy': + case 'smoke': + case 'sound': + case 'vibration': + stateObj._stateDisplay = (stateObj._stateDisplay === 'off') ? 'clear' : 'detected'; + break; + case 'opening': + stateObj._stateDisplay = (stateObj._stateDisplay === 'off') ? 'closed' : 'open'; + break; + case 'safety': + stateObj._stateDisplay = (stateObj._stateDisplay === 'off') ? 'safe' : 'unsafe'; + break; + case 'cold': + case 'connectivity': + case 'heat': + case 'light': + case 'moving': + case 'power': + default: + } + } } return stateObj._stateDisplay;