From bc93b78fcb18c21554449bb54dd6ef03e03fb4aa Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Wed, 1 Dec 2021 22:10:55 +0200 Subject: [PATCH] refactor: remove deprecated fan.set_speed service Migrate from fan.set_speed to fan.set_preset_mode and fan.set_percentage BREAKING CHANGE: `speed` option for `shortcuts` is replaced by `preset_mode` and `percentage` --- README.md | 67 ++++++++++++++++++------------------- src/purifier-card.js | 30 ++++++++++------- src/translations/bg.json | 2 +- src/translations/ca.json | 3 +- src/translations/de.json | 3 +- src/translations/en.json | 2 +- src/translations/fr.json | 2 +- src/translations/it.json | 3 +- src/translations/nb.json | 3 +- src/translations/pl.json | 2 +- src/translations/ru.json | 4 +-- src/translations/tr.json | 3 +- src/translations/uk.json | 2 +- src/translations/zh-CN.json | 2 +- src/translations/zh-TW.json | 2 +- 15 files changed, 63 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 0979492..e4a588d 100644 --- a/README.md +++ b/README.md @@ -74,26 +74,22 @@ stats: shortcuts: - name: Silent icon: 'mdi:weather-night' - speed: Silent + preset_mode: Silent - name: 25% icon: 'mdi:circle-slice-2' - speed: Favorite - xiaomi_miio_favorite_level: 3 + percentage: 25 - name: 50% icon: 'mdi:circle-slice-4' - speed: Favorite - xiaomi_miio_favorite_level: 7 + percentage: 50 - name: 75% icon: 'mdi:circle-slice-6' - speed: Favorite - xiaomi_miio_favorite_level: 10 + percentage: 50 - name: 100% icon: 'mdi:circle-slice-8' - speed: Favorite - xiaomi_miio_favorite_level: 14 + percentage: 100 - name: Auto icon: 'mdi:brightness-auto' - speed: Auto + preset_mode: Auto show_name: true show_state: true show_toolbar: true @@ -102,20 +98,19 @@ compact_view: false Here is what every option means: -| Name | Type | Default | Description | -| ------------------ | :-------: | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `type` | `string` | **Required** | `custom:purifier-card` | -| `entity` | `string` | **Required** | An entity_id within the `fan` domain. | -| `show_name` | `boolean` | `true` | Show friendly name of the purifier. | -| `show_status` | `boolean` | `true` | Show status of the purifier. | -| `show_speed` | `boolean` | `false` | Show speed of the purifier in the header. | -| `show_preset_mode` | `boolean` | `true` | Show preset mode of the purifier in the header. | -| `show_toolbar` | `boolean` | `true` | Show toolbar with shortcuts. | -| `compact_view` | `boolean` | `false` | Compact view without image. | -| `aqi` | `object` | Optional | Custom entity or attribute for AQI value. | -| `stats` | `object` | Optional | Custom per state stats for your purifier cleaner | -| `shortcuts` | `object` | Optional | Custom shortcuts for your purifier cleaner. | -| `platform` | `string` | Optional | Default 'xiaomi_miio', for [Xiaomi Mi Air Purifier & Xiaomi Mi Air Humidifier Integration](https://github.com/syssi/xiaomi_airpurifier) you must specify `xiaomi_miio_airpurifier` | +| Name | Type | Default | Description | +| ------------------ | :-------: | ------------ | ------------------------------------------------ | +| `type` | `string` | **Required** | `custom:purifier-card` | +| `entity` | `string` | **Required** | An entity_id within the `fan` domain. | +| `show_name` | `boolean` | `true` | Show friendly name of the purifier. | +| `show_status` | `boolean` | `true` | Show status of the purifier. | +| `show_speed` | `boolean` | `false` | Show speed of the purifier in the header. | +| `show_preset_mode` | `boolean` | `true` | Show preset mode of the purifier in the header. | +| `show_toolbar` | `boolean` | `true` | Show toolbar with shortcuts. | +| `compact_view` | `boolean` | `false` | Compact view without image. | +| `aqi` | `object` | Optional | Custom entity or attribute for AQI value. | +| `stats` | `object` | Optional | Custom per state stats for your purifier cleaner | +| `shortcuts` | `object` | Optional | Custom shortcuts for your purifier cleaner. | ### `aqi` object @@ -138,22 +133,24 @@ You can use any attribute of purifier or even any entity by `entity_id` to displ ### `shortcuts` object -You can define [custom scripts][ha-scripts] for custom actions or add shortcuts for switching modes and speeds via `shortcuts` option. +You can define [custom scripts][ha-scripts] for custom actions or add shortcuts for switching presets and speeds via `shortcuts` option. -| Name | Type | Default | Description | -| ---------------------------- | :------: | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -| `name` | `string` | Optional | Friendly name of the shortcut, i.e. `Switch to Auto`. | -| `icon` | `string` | Optional | Any icon for shortcut button. | -| `service` | `string` | Optional | A service to call, i.e. `script.clean_air`. | -| `service_data` | `object` | Optional | `service_data` for `service` call | -| `speed` | `object` | Optional | A `speed` to switch to, i.e. `Auto`, etc | -| `xiaomi_miio_favorite_level` | `object` | Optional | A [favorite level][xiaomi-miio-favorite-levels] of the operation mode `Favorite` for Xioami Air Purifiers. `speed` is required with this option | +| Name | Type | Default | Description | +| ---------------------------- | :------: | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | +| `name` | `string` | Optional | Friendly name of the shortcut, i.e. `Switch to Auto`. | +| `icon` | `string` | Optional | Any icon for shortcut button. | +| `service` | `string` | Optional | A service to call, i.e. `script.clean_air`. | +| `service_data` | `object` | Optional | `service_data` for `service` call | +| `percentage` | `object` | Optional | A `percentage` to switch to, i.e. `27`, etc. See `entity`'s `percentage_step` for valid values. | +| `preset_mode` | `object` | Optional | A `speed` to switch to, i.e. `Auto`, etc | +| `xiaomi_miio_favorite_level` | `object` | Optional | A [favorite level][xiaomi-miio-favorite-levels] of the operation mode `Favorite` for Xioami Air Purifiers. `preset_mode` is required with this option | The card will automatically try to figure out which one of shortcuts is currently active. The shortcut will be highlighted when: 1. It's a service. -2. `entity`'s `speed` attribute is equal to `shortcut`'s `speed`. -3. `entity`'s `speed` attribute and `favorite_level` is equal to `shortcut`'s `speed` and `xiaomi_miio_favorite_level` correspondingly. +2. `entity`'s `percentage` attribute is equal to `shortcut`'s `percentage`. +3. `entity`'s `preset_mode` attribute is equal to `shortcut`'s `preset_mode`. +4. `entity`'s `preset_mode` attribute and `favorite_level` is equal to `shortcut`'s `preset_mode` and `xiaomi_miio_favorite_level` correspondingly. ## Animations diff --git a/src/purifier-card.js b/src/purifier-card.js index 8a7a127..a92dcfe 100644 --- a/src/purifier-card.js +++ b/src/purifier-card.js @@ -365,8 +365,8 @@ class PurifierCard extends LitElement { icon, service, service_data, - speed, preset_mode, + percentage, xiaomi_miio_favorite_level, }) => { const execute = () => { @@ -378,12 +378,7 @@ class PurifierCard extends LitElement { this.callService('fan.set_preset_mode', { preset_mode }); } - if (speed) { - this.callService('fan.set_speed', { speed }); - } - - if (speed && xiaomi_miio_favorite_level) { - this.callService('fan.set_speed', { speed }); + if (preset_mode && xiaomi_miio_favorite_level) { setTimeout(() => { this.callService(this.platform + '.fan_set_favorite_level', { level: xiaomi_miio_favorite_level, @@ -391,19 +386,28 @@ class PurifierCard extends LitElement { }, 500); } - if (!speed && xiaomi_miio_favorite_level) { - throw new Error(localize('error.xiaomi_miio_level_without_speed')); + if (!preset_mode && xiaomi_miio_favorite_level) { + throw new Error( + localize('error.xiaomi_miio_level_without_preset_mode') + ); + } + + if (percentage) { + this.callService('fan.set_percentage', { percentage }); } }; const isActive = service || + percentage === attributes.percentage || preset_mode === attributes.preset_mode || - // Speed with specific favorite level - (speed === attributes.speed && + // preset_mode with specific favorite level + (preset_mode === attributes.preset_mode && xiaomi_miio_favorite_level === attributes.favorite_level) || - // Specific speed with no specific favorite level - (speed === attributes.speed && !xiaomi_miio_favorite_level); + // specific preset_mode with no specific favorite level + (preset_mode === attributes.preset_mode && + !xiaomi_miio_favorite_level); + const className = isActive ? 'active' : ''; return html` diff --git a/src/translations/bg.json b/src/translations/bg.json index 6734af4..a8f3da7 100644 --- a/src/translations/bg.json +++ b/src/translations/bg.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "Избирането на обект е задължително!", - "xiaomi_miio_level_without_speed": "speed е задължителен параметър, когато се използва xiaomi_miio_favorite_level!" + "xiaomi_miio_level_without_preset_mode": "preset_mode е задължителен параметър, когато се използва xiaomi_miio_favorite_level!" }, "editor": { "entity": "Обект (Задължително)", diff --git a/src/translations/ca.json b/src/translations/ca.json index a88a924..6fff5e3 100644 --- a/src/translations/ca.json +++ b/src/translations/ca.json @@ -16,8 +16,7 @@ "Fan": "Ventilador" }, "error": { - "missing_entity": "Cal especificar una entitat.", - "xiaomi_miio_level_without_speed": "es requereix la velocitat juntament amb la propietat xiaomi_miio_favorite_level." + "missing_entity": "Cal especificar una entitat." }, "editor": { "entity": "Entitat (Requerit)", diff --git a/src/translations/de.json b/src/translations/de.json index bea7826..2ebcf51 100644 --- a/src/translations/de.json +++ b/src/translations/de.json @@ -16,8 +16,7 @@ "Fan": "Lüfter" }, "error": { - "missing_entity": "Es muss eine Entity definiert werden!", - "xiaomi_miio_level_without_speed": "Geschwindigkeit ist zusammen mit der xiaomi_miio_favorite_level Eigenschaft erforderlich!" + "missing_entity": "Es muss eine Entity definiert werden!" }, "editor": { "entity": "Entity (Erforderlich)", diff --git a/src/translations/en.json b/src/translations/en.json index cf92f44..43c4317 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "Specifying entity is required!", - "xiaomi_miio_level_without_speed": "speed is required along with xiaomi_miio_favorite_level property!" + "xiaomi_miio_level_without_preset_mode": "preset_mode is required along with xiaomi_miio_favorite_level property!" }, "warning": { "actions_array": "WARNING: 'actions' is renamed to 'shortcuts'" diff --git a/src/translations/fr.json b/src/translations/fr.json index 0a6808e..c51aa13 100644 --- a/src/translations/fr.json +++ b/src/translations/fr.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "Il est obligatoire de spécifier une entité!", - "xiaomi_miio_level_without_speed": "speed est obligatoire avec la propriété xiaomi_miio_favorite_level!" + "xiaomi_miio_level_without_preset_mode": "preset_mode est obligatoire avec la propriété xiaomi_miio_favorite_level!" }, "editor": { "entity": "Entité (obligatoire)", diff --git a/src/translations/it.json b/src/translations/it.json index 725fc7c..5593d79 100644 --- a/src/translations/it.json +++ b/src/translations/it.json @@ -16,8 +16,7 @@ "Fan": "Ventola" }, "error": { - "missing_entity": "É necessario specificare l'entità", - "xiaomi_miio_level_without_speed": "É richiesto l'inserimento della velocità insieme alla proprietà xiaomi_miio_favorite_level!" + "missing_entity": "É necessario specificare l'entità" }, "editor": { "entity": "Entità (richiesto)", diff --git a/src/translations/nb.json b/src/translations/nb.json index 18f260f..2d52908 100644 --- a/src/translations/nb.json +++ b/src/translations/nb.json @@ -16,8 +16,7 @@ "Fan": "Vifte" }, "error": { - "missing_entity": "Spesifiserende enhet kreves!", - "xiaomi_miio_level_without_speed": "hastighet kreves sammen med eiendommen xiaomi_miio_favorite_level!" + "missing_entity": "Spesifiserende enhet kreves!" }, "editor": { "entity": "Enhet (påkrevd)", diff --git a/src/translations/pl.json b/src/translations/pl.json index 0316e98..30cee02 100644 --- a/src/translations/pl.json +++ b/src/translations/pl.json @@ -18,7 +18,7 @@ }, "error": { "missing_entity": "Wymagane jest zadeklarowanie encji!", - "xiaomi_miio_level_without_speed": "parametr speed jest wymagany w wywołaniu z xiaomi_miio_favorite_level!" + "xiaomi_miio_level_without_preset_mode": "parametr preset_mode jest wymagany w wywołaniu z xiaomi_miio_favorite_level!" }, "editor": { "entity": "Encja (wymagane)", diff --git a/src/translations/ru.json b/src/translations/ru.json index 8b90999..850ba23 100644 --- a/src/translations/ru.json +++ b/src/translations/ru.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "Требуется указать сущность!", - "xiaomi_miio_level_without_speed": "Требуется указать скорость вместе с свойством xiaomi_miio_favorite_level!" + "xiaomi_miio_level_without_preset_mode": "Требуется указать preset_mode вместе с свойством xiaomi_miio_favorite_level!" }, "editor": { "entity": "Сущность (Обязательно!)", @@ -35,4 +35,4 @@ "show_toolbar_aria_label_off": "Скрыть панель инструментов", "code_only_note": "Примечание: Настройки действий и параметров состояний доступны только в редакторе кода." } -} \ No newline at end of file +} diff --git a/src/translations/tr.json b/src/translations/tr.json index cd86de3..3b168f7 100644 --- a/src/translations/tr.json +++ b/src/translations/tr.json @@ -16,8 +16,7 @@ "Fan": "Fan" }, "error": { - "missing_entity": "Varlığı belirtmeniz gereklidir!", - "xiaomi_miio_level_without_speed": "Hız xiaomi_miio_favorite_level için gereklidir!" + "missing_entity": "Varlığı belirtmeniz gereklidir!" }, "editor": { "entity": "Varlık (Gerekli)", diff --git a/src/translations/uk.json b/src/translations/uk.json index 42882f6..66bfaa3 100644 --- a/src/translations/uk.json +++ b/src/translations/uk.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "Сутність є обов’язковим полем!і", - "xiaomi_miio_level_without_speed": "Поле speed є обов’язковим разом з xiaomi_miio_favorite_level!" + "xiaomi_miio_level_without_preset_mode": "Поле preset_mode є обов’язковим разом з xiaomi_miio_favorite_level!" }, "editor": { "entity": "Об’єкт (Required)", diff --git a/src/translations/zh-CN.json b/src/translations/zh-CN.json index 04377f6..168ad24 100644 --- a/src/translations/zh-CN.json +++ b/src/translations/zh-CN.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "必须指定实体", - "xiaomi_miio_level_without_speed": "speed 和 xiaomi_miio_favorite_level 属性是必需的!" + "xiaomi_miio_level_without_preset_mode": "preset_mode 和 xiaomi_miio_favorite_level 属性是必需的!" }, "editor": { "entity": "实体 (必填)", diff --git a/src/translations/zh-TW.json b/src/translations/zh-TW.json index fefc446..b18459b 100644 --- a/src/translations/zh-TW.json +++ b/src/translations/zh-TW.json @@ -17,7 +17,7 @@ }, "error": { "missing_entity": "必須指定實體名稱!", - "xiaomi_miio_level_without_speed": "設定 xiaomi_miio_favorite_level 屬性時必須包含 speed 屬性!" + "xiaomi_miio_level_without_preset_mode": "設定 xiaomi_miio_favorite_level 屬性時必須包含 preset_mode 屬性!" }, "editor": { "entity": "實體名稱(必填)",