mirror of
https://github.com/home-assistant/frontend.git
synced 2025-08-14 11:49:26 +00:00
.github
demo_data
docs
gulp
hassio
js
common
auth
config
datetime
dom
entity
attribute_class_names.js
binary_sensor_icon.js
can_toggle_domain.js
can_toggle_state.js
compute_domain.js
compute_object_id.js
compute_state_display.js
compute_state_domain.js
compute_state_name.js
cover_icon.js
domain_icon.js
feature_class_names.js
has_location.js
input_dateteime_icon.js
sensor_icon.js
state_card_type.js
state_icon.js
state_more_info_type.js
states_sort_by_name.js
timer_time_remaining.js
valid_entity_id.js
preact
util
const.js
panel-config
compatibility.js
core.js
util.js
panels
public
script
src
test
test-mocha
translations
.dockerignore
.eslintrc-hound.json
.eslintrc.json
.gitignore
.gitmodules
.hound.yml
.nvmrc
.travis.yml
CLA.md
CODE_OF_CONDUCT.md
Dockerfile
LICENSE.md
MANIFEST.in
README.md
bower.json
gulpfile.js
index.html
package.json
polymer.json
setup.py
wct.conf.json
webpack.config.js
yarn.lock
36 lines
969 B
JavaScript
36 lines
969 B
JavaScript
/** Return an icon representing a sensor state. */
|
|
import { UNIT_C, UNIT_F } from '../const.js';
|
|
import domainIcon from './domain_icon.js';
|
|
|
|
const fixedDeviceClassIcons = {
|
|
humidity: 'mdi:water-percent',
|
|
illuminance: 'mdi:brightness-5',
|
|
temperature: 'mdi:thermometer',
|
|
};
|
|
|
|
export default function sensorIcon(state) {
|
|
const dclass = state.attributes.device_class;
|
|
|
|
if (dclass in fixedDeviceClassIcons) {
|
|
return fixedDeviceClassIcons[dclass];
|
|
} else if (dclass === 'battery') {
|
|
if (isNaN(state.state)) {
|
|
return 'mdi:battery-unknown';
|
|
}
|
|
const batteryRound = Math.round(state.state / 10) * 10;
|
|
if (batteryRound >= 100) {
|
|
return 'mdi:battery';
|
|
}
|
|
if (batteryRound <= 0) {
|
|
return 'mdi:battery-alert';
|
|
}
|
|
return `mdi:battery-${batteryRound}`;
|
|
}
|
|
|
|
const unit = state.attributes.unit_of_measurement;
|
|
if (unit === UNIT_C || unit === UNIT_F) {
|
|
return 'mdi:thermometer';
|
|
}
|
|
return domainIcon('sensor');
|
|
}
|