diff --git a/src/localize.js b/src/localize.js
index 6342b0b..28f3534 100644
--- a/src/localize.js
+++ b/src/localize.js
@@ -42,25 +42,29 @@ export default function localize(string, search, replace) {
.replace(/['"]+/g, '')
.replace('-', '_');
- let tranlated;
+ let translated;
try {
- tranlated = languages[lang][section][key];
+ translated = languages[lang][section][key];
} catch (e) {
- tranlated = languages[DEFAULT_LANG][section][key];
+ /**/
}
- if (tranlated === undefined) {
- tranlated = languages[DEFAULT_LANG][section][key];
+ if (translated === undefined) {
+ try {
+ translated = languages[DEFAULT_LANG][section][key];
+ } catch (e) {
+ /**/
+ }
}
- if (tranlated === undefined) {
+ if (translated === undefined) {
return;
}
if (search !== '' && replace !== '') {
- tranlated = tranlated.replace(search, replace);
+ translated = translated.replace(search, replace);
}
- return tranlated;
+ return translated;
}
diff --git a/src/purifier-card.js b/src/purifier-card.js
index 02eb1f2..64dbe8a 100644
--- a/src/purifier-card.js
+++ b/src/purifier-card.js
@@ -11,6 +11,9 @@ if (!customElements.get('ha-icon-button')) {
);
}
+const SUPPORT_SET_SPEED = 1;
+const SUPPORT_PRESET_MODE = 8;
+
class PurifierCard extends LitElement {
static get properties() {
return {
@@ -118,6 +121,11 @@ class PurifierCard extends LitElement {
this.callService('fan.set_speed', { speed });
}
+ handlePresetMode(e) {
+ const preset_mode = e.target.getAttribute('value');
+ this.callService('fan.set_preset_mode', { preset_mode });
+ }
+
callService(service, options = {}, isRequest = true) {
const [domain, name] = service.split('.');
this.hass.callService(domain, name, {
@@ -133,10 +141,11 @@ class PurifierCard extends LitElement {
renderSpeed() {
const {
- attributes: { speed, speed_list },
+ attributes: { speed, speed_list, supported_features },
} = this.entity;
- if (!speed_list) {
+ // TODO handle percentages
+ if (!speed_list || !(supported_features & SUPPORT_SET_SPEED)) {
return html``;
}
@@ -171,6 +180,48 @@ class PurifierCard extends LitElement {
`;
}
+ renderPresetMode() {
+ const {
+ attributes: { preset_mode, preset_modes, supported_features },
+ } = this.entity;
+
+ if (!preset_modes || !(supported_features & SUPPORT_PRESET_MODE)) {
+ return html``;
+ }
+
+ const selected = preset_modes.indexOf(preset_mode);
+
+ return html`
+