Skip to content

Commit

Permalink
Add config option for custom fan speed step size. (#238)
Browse files Browse the repository at this point in the history
* Add config option for change custom fan speed step size
* Use step size as minimum for fan speed
  • Loading branch information
mill1000 committed Sep 11, 2024
1 parent 0487235 commit 9d1c6a7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Name | Default | Description
:--- | :--- | :---
**Beep** | True | Enable beep on setting changes.
**Temperature Step** | 1.0 | Step size for temperature set point.
**Fan Speed Step** | 1 | Step size for custom fan speeds.
**Use Fan-only Workaround** | False | Enable this option if device updates cause the device to turn on and switch to fan-only.
**Show All Presets** | False | Show all presets regardless of device's reported capabilities.
**Additional Operation Modes** | Empty | Additional HVAC modes to make available in case the device's capabilities are incorrect.
Expand Down
6 changes: 5 additions & 1 deletion custom_components/midea_ac/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
from msmart.discover import Discover
from msmart.lan import AuthenticationError

from .const import (CONF_ADDITIONAL_OPERATION_MODES, CONF_BEEP, CONF_KEY,
from .const import (CONF_ADDITIONAL_OPERATION_MODES, CONF_BEEP,
CONF_FAN_SPEED_STEP, CONF_KEY,
CONF_MAX_CONNECTION_LIFETIME, CONF_SHOW_ALL_PRESETS,
CONF_TEMP_STEP, CONF_USE_ALTERNATE_ENERGY_FORMAT,
CONF_USE_FAN_ONLY_WORKAROUND, DOMAIN)

_DEFAULT_OPTIONS = {
CONF_BEEP: True,
CONF_TEMP_STEP: 1.0,
CONF_FAN_SPEED_STEP: 1,
CONF_USE_FAN_ONLY_WORKAROUND: False,
CONF_SHOW_ALL_PRESETS: False,
CONF_ADDITIONAL_OPERATION_MODES: None,
Expand Down Expand Up @@ -232,6 +234,8 @@ async def async_step_init(self, user_input=None) -> FlowResult:
default=options.get(CONF_BEEP, True)): cv.boolean,
vol.Optional(CONF_TEMP_STEP,
default=options.get(CONF_TEMP_STEP, 1.0)): vol.All(vol.Coerce(float), vol.Range(min=0.5, max=5)),
vol.Optional(CONF_FAN_SPEED_STEP,
default=options.get(CONF_FAN_SPEED_STEP, 1)): vol.All(vol.Coerce(float), vol.Range(min=1, max=20)),
vol.Optional(CONF_USE_FAN_ONLY_WORKAROUND,
default=options.get(CONF_USE_FAN_ONLY_WORKAROUND, False)): cv.boolean,
vol.Optional(CONF_SHOW_ALL_PRESETS,
Expand Down
1 change: 1 addition & 0 deletions custom_components/midea_ac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
CONF_KEY = "k1"
CONF_BEEP = "prompt_tone"
CONF_TEMP_STEP = "temp_step"
CONF_FAN_SPEED_STEP = "fan_speed_step"
CONF_USE_FAN_ONLY_WORKAROUND = "use_fan_only_workaround"
CONF_ADDITIONAL_OPERATION_MODES = "additional_operation_modes"
CONF_SHOW_ALL_PRESETS = "show_all_presets"
Expand Down
21 changes: 17 additions & 4 deletions custom_components/midea_ac/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from msmart.device import AirConditioner as AC

from .const import DOMAIN
from .const import CONF_FAN_SPEED_STEP, DOMAIN
from .coordinator import MideaCoordinatorEntity, MideaDeviceUpdateCoordinator

_LOGGER = logging.getLogger(__name__)
Expand All @@ -30,17 +30,25 @@ async def async_setup_entry(

# Create entity if supported
if coordinator.device.supports_custom_fan_speed:
add_entities([MideaFanSpeedNumber(coordinator)])
add_entities([MideaFanSpeedNumber(
coordinator,
config_entry.options.get(CONF_FAN_SPEED_STEP, 1)
)])


class MideaFanSpeedNumber(MideaCoordinatorEntity, NumberEntity):
"""Fan speed number for Midea AC."""

_attr_translation_key = "fan_speed"

def __init__(self, coordinator: MideaDeviceUpdateCoordinator) -> None:
def __init__(self,
coordinator: MideaDeviceUpdateCoordinator,
step_size: float = 1
) -> None:
MideaCoordinatorEntity.__init__(self, coordinator)

self._step_size = step_size

@property
def device_info(self) -> dict:
"""Return info for device registry."""
Expand Down Expand Up @@ -75,7 +83,12 @@ def native_max_value(self) -> float:

@property
def native_min_value(self) -> float:
return 1
# Use step size as minimum to ensure steps are nice and round
return self._step_size

@property
def native_step(self) -> float:
return self._step_size

@property
def native_value(self) -> float:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/midea_ac/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"data": {
"prompt_tone": "Enable Beep",
"temp_step": "Temperature Step",
"fan_speed_step": "Fan Speed Step",
"use_fan_only_workaround": "Use Fan-only Workaround",
"show_all_presets": "Show All Presets",
"additional_operation_modes": "Additional Operation Modes",
Expand All @@ -54,6 +55,7 @@
},
"data_description": {
"temp_step": "Step size for temperature set point",
"fan_speed_step": "Step size for custom fan speeds",
"additional_operation_modes": "Specify additional operational modes",
"max_connection_lifetime": "Maximum time in seconds a connection will be used (30 second minimum)"
}
Expand Down

0 comments on commit 9d1c6a7

Please sign in to comment.