From f20fdccc7bee1253cae605ea44d1756507444b6d Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Thu, 2 Dec 2021 00:25:15 +0200 Subject: [PATCH] refactor: drop xiaomi_miio_favorite_level option Remove xiaomi_miio_favorite_level options for shortcuts BREAKING CHANGE: xiaomi_miio_favorite_level is removed --- README.md | 18 ++++++++---------- src/purifier-card.js | 32 ++------------------------------ 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 6bc432e..27ec258 100644 --- a/README.md +++ b/README.md @@ -136,22 +136,20 @@ You can use any attribute of purifier or even any entity by `entity_id` to displ 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 | -| `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 | +| 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 | 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 `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 393e4db..c00d00f 100644 --- a/src/purifier-card.js +++ b/src/purifier-card.js @@ -360,15 +360,7 @@ class PurifierCard extends LitElement { } const buttons = shortcuts.map( - ({ - name, - icon, - service, - service_data, - preset_mode, - percentage, - xiaomi_miio_favorite_level, - }) => { + ({ name, icon, service, service_data, preset_mode, percentage }) => { const execute = () => { if (service) { this.callService(service, service_data); @@ -378,20 +370,6 @@ class PurifierCard extends LitElement { this.callService('fan.set_preset_mode', { preset_mode }); } - if (preset_mode && xiaomi_miio_favorite_level) { - setTimeout(() => { - this.callService(this.platform + '.fan_set_favorite_level', { - level: xiaomi_miio_favorite_level, - }); - }, 500); - } - - 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 }); } @@ -400,13 +378,7 @@ class PurifierCard extends LitElement { const isActive = service || percentage === attributes.percentage || - preset_mode === attributes.preset_mode || - // preset_mode with specific favorite level - (preset_mode === attributes.preset_mode && - xiaomi_miio_favorite_level === attributes.favorite_level) || - // specific preset_mode with no specific favorite level - (preset_mode === attributes.preset_mode && - !xiaomi_miio_favorite_level); + preset_mode === attributes.preset_mode; const className = isActive ? 'active' : '';