Adjust the binary_sensor icon according to sensor_class

This makes us call stateIcon() from computeIcon() instead of domainIcon(),
and breaks out the actual icon determination logic into a separate function.

I tested with a sensor in a card and a badge and it looks good.
This commit is contained in:
Dan Smith 2016-02-17 15:56:49 -08:00
parent 4cdefac2fe
commit ae41787f5f
2 changed files with 24 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import Polymer from '../../polymer';
import hass from '../../util/home-assistant-js-instance';
import domainIcon from '../../util/domain-icon';
import canToggle from '../../util/can-toggle';
import stateIcon from '../../util/state-icon';
require('../../components/ha-label-badge');
@ -84,7 +85,7 @@ export default new Polymer({
case 'scene':
case 'updater':
case 'script':
return domainIcon(state.domain, state.state);
return stateIcon(state);
case 'sun':
return state.state === 'above_horizon' ?
domainIcon(state.domain) : 'mdi:brightness-3';

View File

@ -4,6 +4,26 @@ import hass from './home-assistant-js-instance';
const { util: { temperatureUnits } } = hass;
function binarySensorIcon(state) {
const activated = state.state && state.state === 'off';
switch (state.attributes.sensor_class) {
case 'opening':
return activated ? 'mdi:crop-square' : 'mdi:exit-to-app';
case 'moisture':
return activated ? 'mdi:water-off' : 'mdi:water';
case 'safety':
case 'gas':
case 'smoke':
case 'power':
return activated ? 'mdi:verified' : 'mdi:alert';
case 'motion':
return activated ? 'mdi:walk' : 'mdi:run';
case 'digital':
default:
return activated ? 'mdi:radiobox-blank' : 'mdi:checkbox-marked-circle';
}
}
export default function stateIcon(state) {
if (!state) {
return defaultIcon;
@ -20,6 +40,8 @@ export default function stateIcon(state) {
} else if (unit === 'Mice') {
return 'mdi:mouse-variant';
}
} else if (state.domain === 'binary_sensor') {
return binarySensorIcon(state);
}
return domainIcon(state.domain, state.state);