diff --git a/custom_components/climate_ewelink/climate.py b/custom_components/climate_ewelink/climate.py index 1c9146e..ccdfb5b 100644 --- a/custom_components/climate_ewelink/climate.py +++ b/custom_components/climate_ewelink/climate.py @@ -12,7 +12,9 @@ TEMPERATURE_MAX, STATES_MANAGER, CLIMATE_DEVICES, - MODE_OFFLINE + MODE_OFFLINE, + FAN_VERY_LOW, + FAN_VERY_HIGH ) from .ac_entity import AirConditionerEntity @@ -60,7 +62,7 @@ def fan_mode(self): @property def fan_modes(self): - return [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO] + return [FAN_VERY_LOW, FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_VERY_HIGH, FAN_AUTO] @property def swing_mode(self): @@ -122,12 +124,16 @@ def _update_state(self, data: dict = None): self._attr_fan_speed = data['wind_speed'] if self._attr_fan_speed > 100: self._attr_fan_mode = FAN_AUTO - elif self._attr_fan_speed > 70: + elif self._attr_fan_speed > 80: + self._attr_fan_mode = FAN_VERY_HIGH + elif self._attr_fan_speed > 60: self._attr_fan_mode = FAN_HIGH - elif self._attr_fan_speed > 30: + elif self._attr_fan_speed > 40: self._attr_fan_mode = FAN_MEDIUM - else: + elif self._attr_fan_speed > 20: self._attr_fan_mode = FAN_LOW + else: + self._attr_fan_mode = FAN_VERY_LOW result = True if "temperature" in data: self._attr_target_temperature = data["temperature"] @@ -145,12 +151,16 @@ def set_temperature(self, **kwargs) -> None: def set_fan_mode(self, fan_mode: str) -> None: if self.state != MODE_OFFLINE: wind_speed = 102 - if fan_mode == FAN_LOW: - wind_speed = 29 + if fan_mode == FAN_VERY_LOW: + wind_speed = 15 + elif fan_mode == FAN_LOW: + wind_speed = 35 elif fan_mode == FAN_MEDIUM: - wind_speed = 69 + wind_speed = 55 elif fan_mode == FAN_HIGH: - wind_speed = 99 + wind_speed = 75 + elif fan_mode == FAN_VERY_HIGH: + wind_speed = 95 self._state_manager.send_payload(self._device_id, {"power": "on","wind_speed": wind_speed}) def set_hvac_mode(self, hvac_mode: str) -> None: diff --git a/custom_components/climate_ewelink/const.py b/custom_components/climate_ewelink/const.py index 93d1371..813f23e 100644 --- a/custom_components/climate_ewelink/const.py +++ b/custom_components/climate_ewelink/const.py @@ -4,6 +4,9 @@ CLIMATE_DEVICES = "climate_devices" ACCOUNTS = "accounts" +FAN_VERY_LOW = "very low" +FAN_VERY_HIGH = "very high" + APPSECRET = "oKvCM06gvwkRbfetd6qWRrbC3rFrbIpV" APPID = "4s1FXKC9FaGfoqXhmXSJneb3qcm1gOak" diff --git a/custom_components/climate_ewelink/manifest.json b/custom_components/climate_ewelink/manifest.json index d83075c..b5b8e2c 100644 --- a/custom_components/climate_ewelink/manifest.json +++ b/custom_components/climate_ewelink/manifest.json @@ -1,7 +1,7 @@ { "domain": "climate_ewelink", "name": "Midea A/C via eWeLink", - "version": "v0.2.7", + "version": "v0.2.8", "config_flow": true, "documentation": "https://github.com/georgezhao2010/climate_ewelink", "issue_tracker": "https://github.com/georgezhao2010/climate_ewelink/issues", diff --git a/custom_components/climate_ewelink/statemanager.py b/custom_components/climate_ewelink/statemanager.py index d21399e..a325e00 100644 --- a/custom_components/climate_ewelink/statemanager.py +++ b/custom_components/climate_ewelink/statemanager.py @@ -3,7 +3,6 @@ import websocket import json import logging - from .const import APPID from .ewelinkcloud import EWeLinkCloud @@ -14,18 +13,6 @@ class WebsocketNotOnlineException(Exception): pass -_STATE_MANAGER = None - - -def on_open(ws): - _LOGGER.debug(f"WebSocket connection established, send userOnline") - _STATE_MANAGER.send_user_online() - - -def on_message(ws, message): - _STATE_MANAGER.process_message(message) - - class StateManager(threading.Thread): def __init__(self, ewelink_cloud: EWeLinkCloud): super().__init__() @@ -39,8 +26,6 @@ def __init__(self, ewelink_cloud: EWeLinkCloud): self._last_ts = 0 self._device_updates = {} self._keep = True - global _STATE_MANAGER - _STATE_MANAGER = self @property def token(self): @@ -130,6 +115,15 @@ def send_payload(self, deviceid, data): self.send_json(payload) def run(self): + state_manager = self + + def on_open(ws): + _LOGGER.debug(f"WebSocket connection established, send userOnline") + state_manager.send_user_online() + + def on_message(ws, message): + state_manager.process_message(message) + while self._keep: while self._url is None and self._keep: if self._ewelink_cloud.login():