Skip to content

Commit

Permalink
Localize sensor state names. Fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
nervetattoo committed Jan 16, 2019
1 parent 6f09567 commit 28224a3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions simple-thermostat.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ function renderStyles() {
padding-bottom: 4px;
}
.sensors td.clickable {
text-decoration: underline;
cursor: pointer;
}
</style>
Expand Down Expand Up @@ -258,9 +257,12 @@ class SimpleThermostat extends LitElement {
return UPDATE_PROPS.some(prop => changedProps.has(prop))
}

localize(label, prefix) {
localize(label, prefix = '') {
const lang = this._hass.selectedLanguage || this._hass.language
return this._hass.resources[lang][`${prefix}${label}`] || label
const key = `${prefix}${label}`
const translations = this._hass.resources[lang]

return key in translations ? translations[key] : label
}

render({ _hass, _hide, config, entity, sensors } = this) {
Expand Down Expand Up @@ -404,12 +406,20 @@ class SimpleThermostat extends LitElement {

let valueCell
if (typeof state === 'object') {
let value = state.state
if ('device_class' in state.attributes) {
const [type] = state.entity_id.split('.')
const prefix = ['state', type, state.attributes.device_class, ''].join(
'.'
)
value = this.localize(state.state, prefix)
}
valueCell = html`
<td
class="clickable"
@click="${() => this.openEntityPopover(state.entity_id)}"
>
${state.state} ${state.attributes.unit_of_measurement}
${value} ${state.attributes.unit_of_measurement}
</td>
`
} else {
Expand Down

0 comments on commit 28224a3

Please sign in to comment.