Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced deprecated constants and wildcard imports (HA >= 2023.1) #420

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
2 changes: 1 addition & 1 deletion README_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

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

# 已支持的品牌

Expand Down
34 changes: 21 additions & 13 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
CONF_DEVICE_ID,
CONF_TYPE,
CONF_CUSTOMIZE,
MAJOR_VERSION,
MINOR_VERSION,
)
from .midea.devices import device_selector

Expand Down Expand Up @@ -145,19 +147,25 @@ 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(
name=name,
device_id=device_id,
device_type=device_type,
ip_address=ip_address,
port=port,
token=token,
key=key,
protocol=protocol,
model=model,
subtype=subtype,
customize=customize,
)

def _device_selector():
return device_selector(
name=name,
device_id=device_id,
device_type=device_type,
ip_address=ip_address,
port=port,
token=token,
key=key,
protocol=protocol,
model=model,
subtype=subtype,
customize=customize,
)
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 3):
device = await hass.async_add_import_executor_job(_device_selector)
else:
device = _device_selector()
if refresh_interval is not None:
device.set_refresh_interval(refresh_interval)
if device:
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
Loading