Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions multiple-entity-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
const html = LitElement.prototype.html;
const css = LitElement.prototype.css;

const UNAVAILABLE = "unavailable";
const UNKNOWN = "unknown";

class MultipleEntityRow extends LitElement {

static get properties() {
Expand Down Expand Up @@ -231,30 +234,33 @@
}

entityStateValue(stateObj, unit) {
let display;
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
return this._hass.localize(`state.default.${stateObj.state}`);
}

if (unit !== false && (unit || stateObj.attributes.unit_of_measurement)) {
return `${stateObj.state} ${unit || stateObj.attributes.unit_of_measurement}`;
}

const domain = stateObj.entity_id.substr(0, stateObj.entity_id.indexOf("."));

if (domain === 'binary_sensor') {
if (stateObj.attributes.device_class) {
display = this._hass.localize(`state.${domain}.${stateObj.attributes.device_class}.${stateObj.state}`);
}
if (!display) {
display = this._hass.localize(`state.${domain}.default.${stateObj.state}`);
}
} else if (unit !== false && (unit || stateObj.attributes.unit_of_measurement) && !['unknown', 'unavailable'].includes(stateObj.state)) {
display = `${stateObj.state} ${unit || stateObj.attributes.unit_of_measurement}`;
} else if (domain === 'zwave') {
display = ['initializing', 'dead'].includes(stateObj.state)
if (domain === 'zwave') {
return ['initializing', 'dead'].includes(stateObj.state)
? this._hass.localize(`state.zwave.query_stage.${stateObj.state}`, 'query_stage', stateObj.attributes.query_stage)
: this._hass.localize(`state.zwave.default.${stateObj.state}`);
} else {
display = this._hass.localize(`state.${domain}.${stateObj.state}`);
}

return display ||
this._hass.localize(`state.default.${stateObj.state}`) ||
this._hass.localize(`component.${domain}.state.${stateObj.state}`) ||
stateObj.state;
return (
// Return device class translation
(stateObj.attributes.device_class &&
this._hass.localize(
`component.${domain}.state.${stateObj.attributes.device_class}.${stateObj.state}`
)) ||
// Return default translation
this._hass.localize(`component.${domain}.state._.${stateObj.state}`) ||
// We don't know! Return the raw state.
stateObj.state
);
}

getAction(config, entityId) {
Expand Down