From 92f70937b9e482757182cd601d5e9aa4b53354bb Mon Sep 17 00:00:00 2001 From: Dmitry Kosenkov <1144095+Junker@users.noreply.github.com> Date: Tue, 21 Sep 2021 22:15:00 +0700 Subject: [PATCH] feat: add 'platform' option (#69) * add 'platform' option * fix typo in README --- README.md | 29 +++++++++++++++-------------- src/purifier-card.js | 10 +++++++++- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 55ebe69..d5a989a 100644 --- a/README.md +++ b/README.md @@ -102,19 +102,20 @@ 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 actions. | -| `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 | -| `actions` | `object` | Optional | Custom actions for your purifier cleaner. | +| 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 actions. | +| `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 | +| `actions` | `object` | Optional | Custom actions 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` | ### `aqi` object @@ -203,7 +204,7 @@ If this card works with your air purifier, please open a PR and your model to th - Coway Airmega 300S/400S ([using IoCare custom component](https://github.com/sarahhenkens/home-assistant-iocare)) - Dyson Pure Humidify+Cool ([using Dyson integration](https://www.home-assistant.io/integrations/dyson/)) - Winix AM90 Wi-Fi Air Purifier -- Philips AirPurifier AC3858/50 (partially) +- Philips AirPurifier AC3858/50 (partially) - [_Your purifier?_][edit-readme] - SmartMI Air Purifier diff --git a/src/purifier-card.js b/src/purifier-card.js index 923e160..764875c 100644 --- a/src/purifier-card.js +++ b/src/purifier-card.js @@ -47,6 +47,14 @@ class PurifierCard extends LitElement { }; } + get platform() { + if (this.config.platform === undefined) { + return 'xiaomi_miio'; + } + + return this.config.platform; + } + get entity() { return this.hass.states[this.config.entity]; } @@ -371,7 +379,7 @@ class PurifierCard extends LitElement { if (speed && xiaomi_miio_favorite_level) { this.callService('fan.set_speed', { speed }); setTimeout(() => { - this.callService('xiaomi_miio.fan_set_favorite_level', { + this.callService(this.platform + '.fan_set_favorite_level', { level: xiaomi_miio_favorite_level, }); }, 500);