mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 21:06:34 +00:00
Fold binary_sensor state card into common code (#322)
* Fold binary_sensor state card into common code * Check device_class per domain
This commit is contained in:
parent
bac1142bc6
commit
6e30534e2d
@ -1,73 +0,0 @@
|
||||
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
||||
|
||||
<link rel="import" href="../../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
|
||||
|
||||
<link rel="import" href="../components/entity/state-info.html">
|
||||
|
||||
<dom-module id="state-card-binary_sensor">
|
||||
<template>
|
||||
<style is="custom-style" include="iron-flex iron-flex-alignment"></style>
|
||||
<style>
|
||||
.state {
|
||||
@apply(--paper-font-body1);
|
||||
color: var(--primary-text-color);
|
||||
|
||||
margin-left: 16px;
|
||||
text-align: right;
|
||||
line-height: 40px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class='horizontal justified layout'>
|
||||
<state-info state-obj="[[stateObj]]" in-dialog='[[inDialog]]'></state-info>
|
||||
<div class='state'>[[computeStateDisplay(stateObj)]]</div>
|
||||
</div>
|
||||
</template>
|
||||
</dom-module>
|
||||
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'state-card-binary_sensor',
|
||||
|
||||
properties: {
|
||||
hass: {
|
||||
type: Object,
|
||||
},
|
||||
|
||||
inDialog: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
|
||||
stateObj: {
|
||||
type: Object,
|
||||
},
|
||||
},
|
||||
computeStateDisplay: function (stateObj) {
|
||||
var state = window.hassUtil.computeStateState(stateObj);
|
||||
switch (stateObj.attributes.device_class) {
|
||||
case 'moisture':
|
||||
return (state === 'off') ? 'dry' : 'wet';
|
||||
case 'gas':
|
||||
case 'motion':
|
||||
case 'occupancy':
|
||||
case 'smoke':
|
||||
case 'sound':
|
||||
case 'vibration':
|
||||
return (state === 'off') ? 'clear' : 'detected';
|
||||
case 'opening':
|
||||
return (state === 'off') ? 'closed' : 'open';
|
||||
case 'safety':
|
||||
return (state === 'off') ? 'safe' : 'unsafe';
|
||||
case 'cold':
|
||||
case 'connectivity':
|
||||
case 'heat':
|
||||
case 'light':
|
||||
case 'moving':
|
||||
case 'power':
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
},
|
||||
});
|
||||
</script>
|
@ -1,6 +1,5 @@
|
||||
<link rel="import" href="../../bower_components/polymer/polymer.html">
|
||||
|
||||
<link rel="import" href="state-card-binary_sensor.html">
|
||||
<link rel="import" href="state-card-climate.html">
|
||||
<link rel="import" href="state-card-configurator.html">
|
||||
<link rel="import" href="state-card-cover.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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user