Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
add more fan modes
Browse files Browse the repository at this point in the history
  • Loading branch information
georgezhao2010 authored Jul 15, 2021
1 parent dc0d72b commit 602dfb4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
28 changes: 19 additions & 9 deletions custom_components/climate_ewelink/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"]
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions custom_components/climate_ewelink/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
CLIMATE_DEVICES = "climate_devices"
ACCOUNTS = "accounts"

FAN_VERY_LOW = "very low"
FAN_VERY_HIGH = "very high"

APPSECRET = "oKvCM06gvwkRbfetd6qWRrbC3rFrbIpV"
APPID = "4s1FXKC9FaGfoqXhmXSJneb3qcm1gOak"

Expand Down
2 changes: 1 addition & 1 deletion custom_components/climate_ewelink/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 9 additions & 15 deletions custom_components/climate_ewelink/statemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import websocket
import json
import logging

from .const import APPID
from .ewelinkcloud import EWeLinkCloud

Expand All @@ -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__()
Expand All @@ -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):
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 602dfb4

Please sign in to comment.