diff --git a/README.md b/README.md index eb997ca..4d02065 100644 --- a/README.md +++ b/README.md @@ -56,16 +56,15 @@ type: "custom:fan-xiaomi" platform: xiaomi_miio_airpurifier ``` -| Card attribute | Default | Description | -| -------------------------- | --------- | ---------------------------------------------------------------------------------------------------- | -| `entity_id` | - | `entity_id` of your fan | -| `type` | - | Must be `custom:fan-xiaomi` | -| `name` | - | (Optional) Fan name shown on card title | -| `platform` | `default` | (Optional) If using Xiaomi Mi Smart Pedestal Fan integration, specify `xiaomi_miio_fan`. | -| `disable_animation` | `False` | (Optional) Disable fan image and animation | -| `use_standard_speeds` | `False` | (Optional) Use `low`/`medium`/`high` speeds, if you have issues using this card with your fan model. | -| `force_sleep_mode_support` | `False` | (Optional) Enables Sleep button in UI which sets speed to 1% | -| `hide_led_button` | `False` | (Optional) Hide LED toggle for supported models | +| Card attribute | Default | Description | +| -------------------------- | --------- | ---------------------------------------------------------------------------------------- | +| `entity_id` | - | `entity_id` of your fan | +| `type` | - | Must be `custom:fan-xiaomi` | +| `name` | - | (Optional) Fan name shown on card title | +| `platform` | `default` | (Optional) If using Xiaomi Mi Smart Pedestal Fan integration, specify `xiaomi_miio_fan`. | +| `disable_animation` | `False` | (Optional) Disable fan image and animation | +| `force_sleep_mode_support` | `False` | (Optional) Enables Sleep button in UI which sets speed to 1% | +| `hide_led_button` | `False` | (Optional) Hide LED toggle for supported models | ## Preview diff --git a/src/config.ts b/src/config.ts index 6d2bcd5..8082834 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,7 +7,6 @@ interface FanXiaomiCustomConfig { platform: typeof platforms[number]; entity: string; disable_animation: boolean; - use_standard_speeds: boolean; force_sleep_mode_support: boolean; hide_led_button: boolean; } @@ -19,7 +18,6 @@ export const defaultConfig: FanXiaomiCustomConfig = { platform: platforms[0], entity: "", disable_animation: false, - use_standard_speeds: false, force_sleep_mode_support: false, hide_led_button: false, }; diff --git a/src/xiaomi-fan-card-editor.ts b/src/xiaomi-fan-card-editor.ts index 5c915b2..9513192 100644 --- a/src/xiaomi-fan-card-editor.ts +++ b/src/xiaomi-fan-card-editor.ts @@ -87,14 +87,6 @@ export class FanXiaomiCardEditor extends ScopedRegistryHost(LitElement) implemen return html`${entity}`; })} - - - 0) { - speedLevel = Number(speedRegexpMatch[1]); - } - if (speedLevel === NaN) { - speedLevel = 1; - } - } - - return speedLevel; + const speedCount = this.supportedAttributes.speedLevels; + return Math.ceil((this.getSpeedPercentage() / 100) * speedCount); } private setPresetMode(value) { @@ -395,15 +374,6 @@ export class FanXiaomiCard extends LitElement { } private checkFanFeatures(attributes) { - // TODO: Deprecate as fan.set_speed is deprecated - this.supportedAttributes.speedList = ["low", "medium", "high"]; - if (attributes.speed_list) { - this.supportedAttributes.speedList = attributes.speed_list.filter((s) => { - const speed = s.toLowerCase(); - return speed !== "nature" && speed !== "normal" && speed !== "off"; - }); - } - if ( attributes.preset_mode && attributes.preset_modes && @@ -477,9 +447,6 @@ export class FanXiaomiCard extends LitElement { } //trick to support of 'any' fan - if (this.config.use_standard_speeds) { - this.supportedAttributes.speedList = ["low", "medium", "high"]; - } if (this.config.force_sleep_mode_support) { this.supportedAttributes.sleepMode = true; } @@ -559,7 +526,7 @@ export class FanXiaomiCard extends LitElement { ` : ""}
-
+
@@ -711,26 +678,15 @@ export class FanXiaomiCard extends LitElement { * the fan when animations/fanbox is disabled. */ private toggleSpeedLevel(): void { - const speedLevel = this.getSpeedLevel(); + const currentLevel = this.getSpeedLevel(); - let newSpeed: string | 0; - if (this.config.use_standard_speeds || this.config.platform === "default") { - newSpeed = - speedLevel >= this.supportedAttributes.speedList.length ? 0 : this.supportedAttributes.speedList[speedLevel]; - } else { - newSpeed = speedLevel >= this.supportedAttributes.speedLevels ? 0 : `Level ${speedLevel + 1}`; - } + const newLevel = currentLevel >= this.supportedAttributes.speedLevels ? 0 : currentLevel + 1; + const newPercentage = (newLevel / this.supportedAttributes.speedLevels) * 100; - if (newSpeed === 0) { - this.hass.callService("fan", "turn_off", { - entity_id: this.config.entity, - }); - } else { - this.hass.callService("fan", "set_speed", { - entity_id: this.config.entity, - speed: newSpeed, - }); - } + this.hass.callService("fan", "set_percentage", { + entity_id: this.config.entity, + percentage: newPercentage, + }); } private increaseSpeed() {