Skip to content

Commit

Permalink
sync with CyrielRct forked repo latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed May 11, 2024
1 parent 7c5231c commit 2f32f8c
Show file tree
Hide file tree
Showing 22 changed files with 305 additions and 150 deletions.
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "midea_ac_lan",
"image": "mcr.microsoft.com/devcontainers/python:3.12-bullseye",
"postCreateCommand": "scripts/setup.sh",
"forwardPorts": [
8123
],
"portsAttributes": {
"8123": {
"label": "Home Assistant",
"onAutoForward": "notify"
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"settings": {
"files.eol": "\n",
"editor.tabSize": 4,
"python.pythonPath": "/usr/bin/python3",
"python.analysis.autoSearchPaths": false,
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
}
},
"remoteUser": "vscode",
"features": {
"ghcr.io/devcontainers/features/python:1": {
"version": "3.12"
}
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#Config
config/

#Sensitive files
sensitive/

Expand Down Expand Up @@ -107,6 +110,11 @@ custom_components/midea_ac_lan/venv/
ENV/
env.bak/
venv.bak/
.direnv/
.direnv.nosync/

# # VSCODE
# .vscode/

# Spyder project settings
.spyderproject
Expand Down
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
11 changes: 11 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant on port 8123",
"type": "shell",
"command": "scripts/run.sh",
"problemMatcher": []
}
]
}
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Midea AC LAN
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)
[![Donate](https://img.shields.io/badge/donate-BuyMeCoffee-yellow.svg)](https://www.buymeacoffee.com/georgezhao2010)
[![Stable](https://img.shields.io/github/v/release/georgezhao2010/midea_ac_lan)](https://github.com/georgezhao2010/midea_ac_lan/releases/latest)
[![Stable](https://img.shields.io/github/v/release/CyrielRct/midea_ac_lan)](https://github.com/CyrielRct/midea_ac_lan/releases/latest)

> :warning: **This is a fork of Midea_ac_lan done by Georgezhao **: As the project is in a vegetative state we have done a fork and merged some pending fixes.
I'm trying to get in touch with the maintainer at the moment to find a solution, and at the same time we're looking for people available to maintain the project, which is actively used by the community. please contact me if you can help !

English | [简体中文](README_hans.md)

Expand All @@ -17,7 +20,7 @@ Thanks also to [@NeoAcheron](https://github.com/NeoAcheron/midea-ac-py).

⭐If this component is helpful for you, please star it, it encourages me a lot.

***❗Note: Home Assistant 2022.5 or higher required for this integration***
***❗Note: Home Assistant 2023.1 or higher required for this integration***

# Supported brands

Expand Down Expand Up @@ -146,4 +149,4 @@ logger:
If you like this integration, why do not you support my works by buying me a coffee?
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/georgezhao2010)
[![Buy me a coffee](https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png)](https://www.buymeacoffee.com/georgezhao2010)
4 changes: 2 additions & 2 deletions README_hans.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Midea AC LAN
[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg)](https://github.com/hacs/integration)
[![Donate](https://img.shields.io/badge/donate-BuyMeCoffee-yellow.svg)](https://www.buymeacoffee.com/georgezhao2010)
[![Stable](https://img.shields.io/github/v/release/georgezhao2010/midea_ac_lan)](https://github.com/georgezhao2010/midea_ac_lan/releases/latest)
[![Stable](https://img.shields.io/github/v/release/CyrielRct/midea_ac_lan)](https://github.com/CyrielRct/midea_ac_lan/releases/latest)

[English](README.md) | 简体中文

Expand All @@ -17,7 +17,7 @@

⭐如果本集成对你有所帮助, 请不吝为它点个星, 这将是对我的极大激励。

***❗注意: 本集成需要Home Assistant 2022.5或更高版本***
***❗注意: 本集成需要Home Assistant 2023.1或更高版本***

# 已支持的品牌

Expand Down
5 changes: 3 additions & 2 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
CONF_TYPE,
CONF_CUSTOMIZE,
)
from .midea.devices import device_selector
from .midea.devices import async_device_selector

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -145,7 +145,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry):
if protocol == 3 and (key is None or key is None):
_LOGGER.error("For V3 devices, the key and the token is required.")
return False
device = device_selector(
device = await async_device_selector(
hass=hass,
name=name,
device_id=device_id,
device_type=device_type,
Expand Down
74 changes: 51 additions & 23 deletions custom_components/midea_ac_lan/climate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
from homeassistant.components.climate import *
from homeassistant.components.climate.const import *
from homeassistant.components.climate import (
ATTR_HVAC_MODE,
ClimateEntity,
ClimateEntityFeature,
FAN_AUTO,
FAN_HIGH,
FAN_LOW,
FAN_MEDIUM,
HVACMode,
PRESET_AWAY,
PRESET_BOOST,
PRESET_COMFORT,
PRESET_ECO,
PRESET_NONE,
PRESET_SLEEP,
SWING_BOTH,
SWING_HORIZONTAL,
SWING_OFF,
SWING_ON,
SWING_VERTICAL,
)
from homeassistant.const import (
MAJOR_VERSION,
MINOR_VERSION,
Platform,
TEMP_CELSIUS,
UnitOfTemperature,
PRECISION_WHOLE,
PRECISION_HALVES,
ATTR_TEMPERATURE,
CONF_DEVICE_ID,
CONF_SWITCHES
CONF_SWITCHES,
)

from .const import (
Expand Down Expand Up @@ -56,16 +77,24 @@ async def async_setup_entry(hass, config_entry, async_add_entities):


class MideaClimate(MideaEntity, ClimateEntity):

# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded
_enable_turn_on_off_backwards_compatibility: bool = False # maybe remove after 2025.1

def __init__(self, device, entity_key):
super().__init__(device, entity_key)

@property
def supported_features(self):
return ClimateEntityFeature.TARGET_TEMPERATURE | \
ClimateEntityFeature.FAN_MODE | \
ClimateEntityFeature.PRESET_MODE | \
ClimateEntityFeature.SWING_MODE | \
ClimateEntityFeature.AUX_HEAT
features = (
ClimateEntityFeature.TARGET_TEMPERATURE |
ClimateEntityFeature.FAN_MODE |
ClimateEntityFeature.PRESET_MODE |
ClimateEntityFeature.SWING_MODE
)
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
features |= ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
return features

@property
def min_temp(self):
Expand All @@ -77,7 +106,7 @@ def max_temp(self):

@property
def temperature_unit(self):
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def target_temperature_low(self):
Expand Down Expand Up @@ -114,10 +143,6 @@ def target_temperature(self):
def current_temperature(self):
return self._device.get_attribute("indoor_temperature")

@property
def is_aux_heat(self):
return self._device.get_attribute("aux_heating")

@property
def preset_modes(self):
return self._preset_modes
Expand Down Expand Up @@ -200,12 +225,6 @@ def update_state(self, status):
except Exception as e:
_LOGGER.debug(f"Entity {self.entity_id} update_state {repr(e)}, status = {status}")

def turn_aux_heat_on(self) -> None:
self._device.set_attribute(attr="aux_heating", value=True)

def turn_aux_heat_off(self) -> None:
self._device.set_attribute(attr="aux_heating", value=False)


class MideaACClimate(MideaClimate):
def __init__(self, device, entity_key):
Expand Down Expand Up @@ -316,7 +335,10 @@ def __init__(self, device, entity_key):

@property
def supported_features(self):
return ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.AUX_HEAT
features = ClimateEntityFeature.TARGET_TEMPERATURE
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
features |= ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
return features

@property
def target_temperature_step(self):
Expand Down Expand Up @@ -357,7 +379,10 @@ def __init__(self, device, entity_key, zone):

@property
def supported_features(self):
return ClimateEntityFeature.TARGET_TEMPERATURE
features = ClimateEntityFeature.TARGET_TEMPERATURE
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
features |= ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
return features

@property
def target_temperature_step(self):
Expand Down Expand Up @@ -432,7 +457,10 @@ def __init__(self, device, entity_key):

@property
def supported_features(self):
return ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
features |= ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
return features

@property
def target_temperature_step(self):
Expand Down
14 changes: 8 additions & 6 deletions custom_components/midea_ac_lan/fan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from homeassistant.components.fan import *
from typing import Any

from homeassistant.components.fan import FanEntity, FanEntityFeature
from homeassistant.const import (
Platform,
CONF_DEVICE_ID,
Expand Down Expand Up @@ -115,21 +117,21 @@ def update_state(self, status):
class MideaFAFan(MideaFan):
def __init__(self, device, entity_key):
super().__init__(device, entity_key)
self._attr_supported_features = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE | SUPPORT_PRESET_MODE
self._attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.OSCILLATE | FanEntityFeature.PRESET_MODE
self._attr_speed_count = self._device.speed_count


class MideaB6Fan(MideaFan):
def __init__(self, device, entity_key):
super().__init__(device, entity_key)
self._attr_supported_features = SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE
self._attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
self._attr_speed_count = self._device.speed_count


class MideaACFreshAirFan(MideaFan):
def __init__(self, device, entity_key):
super().__init__(device, entity_key)
self._attr_supported_features = SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE
self._attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
self._attr_speed_count = 100

@property
Expand Down Expand Up @@ -173,7 +175,7 @@ def preset_mode(self):
class MideaCEFan(MideaFan):
def __init__(self, device, entity_key):
super().__init__(device, entity_key)
self._attr_supported_features = SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE
self._attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
self._attr_speed_count = self._device.speed_count

def turn_on(self, percentage, preset_mode, **kwargs):
Expand All @@ -186,7 +188,7 @@ async def async_set_percentage(self, percentage: int):
class Midea40Fan(MideaFan):
def __init__(self, device, entity_key):
super().__init__(device, entity_key)
self._attr_supported_features = SUPPORT_SET_SPEED | SUPPORT_OSCILLATE
self._attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.OSCILLATE
self._attr_speed_count = 2

@property
Expand Down
7 changes: 5 additions & 2 deletions custom_components/midea_ac_lan/humidifier.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from homeassistant.components.humidifier import *
from homeassistant.components.humidifier.const import *
from homeassistant.components.humidifier import (
HumidifierDeviceClass,
HumidifierEntity,
HumidifierEntityFeature,
)
from homeassistant.const import (
Platform,
CONF_DEVICE_ID,
Expand Down
14 changes: 13 additions & 1 deletion custom_components/midea_ac_lan/light.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import logging
from homeassistant.components.light import *
from typing import Any

from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_EFFECT,
LightEntity,
LightEntityFeature,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT,
)
from homeassistant.const import (
Platform,
CONF_DEVICE_ID,
Expand Down
14 changes: 9 additions & 5 deletions custom_components/midea_ac_lan/manifest.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"domain": "midea_ac_lan",
"name": "Midea AC LAN",
"codeowners": ["@georgezhao2010"],
"codeowners": [
"@CyrielRct"
],
"config_flow": true,
"dependencies": [],
"documentation": "https://github.com/georgezhao2010/midea_ac_lan#readme",
"documentation": "https://github.com/CyrielRct/midea_ac_lan#readme",
"integration_type": "device",
"iot_class": "local_push",
"issue_tracker": "https://github.com/georgezhao2010/midea_ac_lan/issues",
"requirements": [],
"version": "v0.3.22"
"issue_tracker": "https://github.com/CyrielRct/midea_ac_lan/issues",
"requirements": [
"pycryptodome"
],
"version": "v0.3.23"
}
Loading

0 comments on commit 2f32f8c

Please sign in to comment.