Skip to content

Commit

Permalink
update based on super linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwentao committed May 13, 2024
1 parent b5b4998 commit 055ced0
Show file tree
Hide file tree
Showing 38 changed files with 75 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
1 change: 1 addition & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ jobs:
env:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_GITLEAKS: false
23 changes: 11 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
- name: Show Output Directory For Debug Purpose
run: |
apt update && apt install zip || exit 1
echo show runner hostname
echo "show runner hostname"
hostname
echo show runner user
echo "show runner user"
whoami
echo show runner pwd
echo "show runner pwd"
pwd
echo show runner kernel
echo "show runner kernel"
uname -a
echo show runner pwd file list
echo "show runner pwd file list"
ls
ls -alht custom_components/midea_ac_lan/ || exit 1
echo "show manifest.json for debug"
Expand All @@ -60,7 +60,6 @@ jobs:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
steps:

- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -73,18 +72,18 @@ jobs:

- name: Show Working Directory For Debug Purpose
run: |
echo show runner hostname
echo "show runner hostname"
hostname
echo show runner user
echo "show runner user"
whoami
echo show runner pwd
echo "show runner pwd"
pwd
echo show runner kernel”
echo "show runner kernel”
uname -a
echo show runner pwd file list”
echo "show runner pwd file list”
ls
ls -alht
echo show runner artifacts”
echo "show runner artifacts”
ls -alht artifacts || exit 0
echo "github.ref: ${{github.ref}} "
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ Thanks also to [@NeoAcheron](https://github.com/NeoAcheron/midea-ac-py).

## Supported brands

![ariston](brands/ariston.png) ![beverly](brands/beverly.png) ![bugu](brands/bugu.png) ![carrier](brands/carrier.png) ![colmo](brands/colmo.png) ![comfee](brands/comfee.png) ![electrolux](brands/electrolux.png) ![invertor](brands/invertor.png) ![littleswan](brands/littleswan.png) ![midea](brands/midea.png) ![netsu](brands/netsu.png) ![ProBreeze](brands/probreeze.png) ![rotenso](brands/rotenso.png) ![toshiba](brands/toshiba.png) ![vandelo](brands/vandelo.png) ![wahin](brands/wahin.png)
![ariston](brands/ariston.png) ![beverly](brands/beverly.png) ![bugu](brands/bugu.png) \
![carrier](brands/carrier.png) ![colmo](brands/colmo.png) ![comfee](brands/comfee.png) \
![electrolux](brands/electrolux.png) ![invertor](brands/invertor.png) ![littleswan](brands/littleswan.png) \
![midea](brands/midea.png) ![netsu](brands/netsu.png) ![ProBreeze](brands/probreeze.png) \
![rotenso](brands/rotenso.png) ![toshiba](brands/toshiba.png) ![vandelo](brands/vandelo.png) \
![wahin](brands/wahin.png)

And more.

Expand Down Expand Up @@ -126,7 +131,11 @@ Set the IP address of device. You can reset this when your device IP is changed.
### Refresh interval

Set the interval for actively refreshing the status of a single device (the unit is second) (30 by default and 0 means not refresh actively)
Mostly the status update of Midea devices relies on the active information notification of the device, in which condition the status update in HA still works normally even if the refresh interval is set to be “0”. This component will also actively query the device status at regular intervals, and the default time is 30 seconds. Some devices do not have active information notifications when their status changed, so synchronization with the status in HA will be slower. If you are very concerned about the synchronization speed of the status, you can try to set a shorter status refresh interval.
Mostly the status update of Midea devices relies on the active information notification of the device, \
in which condition the status update in HA still works normally even if the refresh interval is set to be "0". \
This component will also actively query the device status at regular intervals, and the default time is 30 seconds. \
Some devices do not have active information notifications when their status changed, so synchronization with the status in HA will be slower. \
If you are very concerned about the synchronization speed of the status, you can try to set a shorter status refresh interval.

***❗Note: shorter refresh interval may mean more power consumption***

Expand Down
6 changes: 5 additions & 1 deletion README_hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

## 已支持的品牌

![beverly](brands/beverly.png) ![bugu](brands/bugu.png) ![carrier](brands/carrier.png) ![colmo](brands/colmo.png) ![comfee](brands/comfee.png) ![electrolux](brands/electrolux.png) ![invertor](brands/invertor.png) ![littleswan](brands/littleswan.png) ![midea](brands/midea.png) ![netsu](brands/netsu.png) ![ProBreeze](brands/probreeze.png) ![rotenso](brands/rotenso.png) ![toshiba](brands/toshiba.png) ![vandelo](brands/vandelo.png) ![wahin](brands/wahin.png)
![beverly](brands/beverly.png) ![bugu](brands/bugu.png) ![carrier](brands/carrier.png) \
![colmo](brands/colmo.png) ![comfee](brands/comfee.png) ![electrolux](brands/electrolux.png) \
![invertor](brands/invertor.png) ![littleswan](brands/littleswan.png) ![midea](brands/midea.png) \
![netsu](brands/netsu.png) ![ProBreeze](brands/probreeze.png) ![rotenso](brands/rotenso.png) \
![toshiba](brands/toshiba.png) ![vandelo](brands/vandelo.png) ![wahin](brands/wahin.png)

以及更多。

Expand Down
2 changes: 0 additions & 2 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
CONF_SUBTYPE,
CONF_REFRESH_INTERVAL,
DEVICES,
EXTRA_SENSOR,
EXTRA_SWITCH,
EXTRA_CONTROL,
ALL_PLATFORM,
)
from .midea_devices import MIDEA_DEVICES
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,4 @@ def set_hvac_mode(self, hvac_mode: str) -> None:
self.turn_on()

def set_preset_mode(self, preset_mode: str) -> None:
self._device.set_attribute(attr=FBAttributes.mode,value=preset_mode)
self._device.set_attribute(attr=FBAttributes.mode, value=preset_mode)
4 changes: 2 additions & 2 deletions custom_components/midea_ac_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def async_step_auto(self, user_input=None, error=None):
self.found_device[CONF_SUBTYPE] = device_info.get("model_number")
if device.get(CONF_PROTOCOL) == 3:
if self.account[CONF_SERVER] == "美的美居":
_LOGGER.debug(f"Try to get the Token and the Key use the preset MSmartHome account")
_LOGGER.debug("Try to get the Token and the Key use the preset MSmartHome account")
self.cloud = get_midea_cloud(
"MSmartHome",
self.session,
Expand Down Expand Up @@ -426,7 +426,7 @@ async def async_step_init(self, user_input=None):
sensors = {}
switches = {}
for attribute, attribute_config in MIDEA_DEVICES.get(self._device_type).get("entities").items():
attribute_name = attribute if type(attribute) is str else attribute.value
attribute_name = attribute if isinstance(attribute, str) else attribute.value
if attribute_config.get("type") in EXTRA_SENSOR:
sensors[attribute_name] = attribute_config.get("name")
elif attribute_config.get("type") in EXTRA_CONTROL and not attribute_config.get("default"):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/backports/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def _generate_next_value_(
We may revisit this when it's very clear that Python 3.11's
`StrEnum.auto()` behavior will no longer change.
"""
raise TypeError("auto() is not supported by this implementation")
raise TypeError("auto() is not supported by this implementation")
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/core/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def parse_message(self, msg):
else:
_LOGGER.debug(f"[{self._device_id}] Unidentified protocol")
except Exception as e:
_LOGGER.error(f"[{self._device_id}] Error in process message, msg = {decrypted.hex()}")
_LOGGER.error(f"[{self._device_id}] Error in process message, msg = {e}")
else:
_LOGGER.warning(
f"[{self._device_id}] Illegal payload, "
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(self):
def aes_decrypt(self, raw):
try:
return unpad(AES.new(self.aes_key, AES.MODE_ECB).decrypt(bytearray(raw)), 16)
except ValueError as e:
except ValueError:
return bytearray(0)

def aes_encrypt(self, raw):
Expand Down
6 changes: 4 additions & 2 deletions custom_components/midea_ac_lan/midea/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from importlib import import_module
from types import ModuleType


async def async_device_selector(
hass: HomeAssistant,
name: str,
Expand All @@ -22,13 +23,14 @@ async def async_device_selector(
device_path = f".{'x%02x' % device_type}.device"
else:
device_path = f".{'%02x' % device_type}.device"

modules: list[ModuleType] = []

def _load_device_module() -> None:
"""Load all service modules."""
modules.append(import_module(device_path, __package__))
await hass.async_add_import_executor_job(_load_device_module)

device = modules[0].MideaAppliance(
name=name,
device_id=device_id,
Expand Down
1 change: 1 addition & 0 deletions custom_components/midea_ac_lan/midea/devices/a1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
NewProtocolMessageBody
)


class NewProtocolTags(IntEnum):
light = 0x005B

Expand Down
6 changes: 2 additions & 4 deletions custom_components/midea_ac_lan/midea/devices/ac/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _subprotocol_body(self):
prompt_tone = 0x01 if self.prompt_tone else 0
timer = 0x04 if (self.sn8_flag and self.timer) else 0
return bytearray([
0x02 | boost_mode | power | dry, aux_heating, sleep_mode, 0x00,
0x02 | boost_mode | power | dry, aux_heating, sleep_mode, 0x00,
0x00, mode, target_temperature, fan_speed,
0x32, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
Expand Down Expand Up @@ -256,9 +256,7 @@ def _body(self):
# Byte 3, fan_speed
fan_speed = self.fan_speed & 0x7f
# Byte 7, swing_mode
swing_mode = 0x30 | \
(0x0c if self.swing_vertical else 0) | \
(0x03 if self.swing_horizontal else 0)
swing_mode = 0x30 | (0x0c if self.swing_vertical else 0) | (0x03 if self.swing_horizontal else 0)
# Byte 8, turbo
boost_mode = 0x20 if self.boost_mode else 0
# Byte 9 aux_heating eco_mode
Expand Down
3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/b0/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class MessageB0Base(MessageRequest):
def __init__(self, protocol_version, message_type, body_type):
def __init__(self, protocol_version, message_type, body_type):
super().__init__(
device_type=0xB0,
protocol_version=protocol_version,
Expand Down Expand Up @@ -82,4 +82,3 @@ def __init__(self, message):
else:
self.set_body(B0MessageBody(super().body))
self.set_attr()

3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/b1/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class MessageB1Base(MessageRequest):
def __init__(self, protocol_version, message_type, body_type):
def __init__(self, protocol_version, message_type, body_type):
super().__init__(
device_type=0xB1,
protocol_version=protocol_version,
Expand Down Expand Up @@ -52,4 +52,3 @@ def __init__(self, message):
if self.message_type in [MessageType.notify1, MessageType.query]:
self.set_body(B1MessageBody(super().body))
self.set_attr()

1 change: 0 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/b3/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ def __init__(self, message):
elif self.message_type == MessageType.set and self.body_type == 0x24:
self.set_body(B3MessageBody21(super().body))
self.set_attr()

3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/b4/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, body):
self.time_remaining = (0 if body[22] == 0xFF else body[22]) * 3600 + \
(0 if body[23] == 0xFF else body[23]) * 60 + \
(0 if body[24] == 0xFF else body[24])
self.current_temperature = (body[25] << 8 ) + body[26]
self.current_temperature = (body[25] << 8) + body[26]
if self.current_temperature == 0:
self.current_temperature = (body[27] << 8) + body[28]
self.status = body[31]
Expand All @@ -55,4 +55,3 @@ def __init__(self, message):
if self.body_type == 0x01:
self.set_body(B4MessageBody(super().body))
self.set_attr()

1 change: 1 addition & 0 deletions custom_components/midea_ac_lan/midea/devices/c2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, protocol_version):
message_type=MessageType.set,
body_type=0x00)
self.power = False

@property
def _body(self):
if self.power:
Expand Down
4 changes: 3 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/c3/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def make_message_set(self):
return message

def set_attribute(self, attr, value):
message= None

message = None

if attr in [
DeviceAttributes.zone1_power,
DeviceAttributes.zone2_power,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/c3/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ def __init__(self, message):
self.set_body(C3MessageBody(super().body, data_offset=1))
elif self.message_type == MessageType.notify1 and self.body_type == 0x04:
self.set_body(C3Notify1MessageBody(super().body, data_offset=1))
self.set_attr()
self.set_attr()
5 changes: 3 additions & 2 deletions custom_components/midea_ac_lan/midea/devices/cd/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _body(self):


class MessageQuery(MessageCDBase):
def __init__(self,protocol_version):
def __init__(self, protocol_version):
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.query,
Expand All @@ -33,7 +33,7 @@ def _body(self):


class MessageSet(MessageCDBase):
def __init__(self,protocol_version):
def __init__(self, protocol_version):
super().__init__(
protocol_version=protocol_version,
message_type=MessageType.set,
Expand Down Expand Up @@ -83,6 +83,7 @@ def __init__(self, body):
if (body[28] & 0x20) > 0:
self.mode = 3


class CD02MessageBody(MessageBody):
def __init__(self, body):
super().__init__(body)
Expand Down
1 change: 0 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/cf/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ def __init__(self, message):
elif self.message_type in [MessageType.notify1, MessageType.notify2]:
self.set_body(CFMessageBody(super().body, data_offset=0))
self.set_attr()

9 changes: 4 additions & 5 deletions custom_components/midea_ac_lan/midea/devices/da/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DeviceAttributes(StrEnum):
wash_strength = "wash_strength"
softener = "softener"
detergent = "detergent"


class MideaDADevice(MiedaDevice):
def __init__(
Expand Down Expand Up @@ -93,10 +93,8 @@ def process_message(self, msg):
"Stir", "Mute", "Bucket Self Clean", "Air Dry"]
speed = ["-", "Low", "Medium", "High"]
strength = ["-", "Week", "Medium", "Strong"]
detergent = ["No", "Less", "Medium", "More", "4",
"5", "6", "7", "8", "Insufficient"]
softener = ["No", "Intelligent", "Programed", "3", "4",
"5", "6", "7", "8", "Insufficient"]
detergent = ["No", "Less", "Medium", "More", "4", "5", "6", "7", "8", "Insufficient"]
softener = ["No", "Intelligent", "Programed", "3", "4", "5", "6", "7", "8", "Insufficient"]
for status in self._attributes.keys():
if hasattr(message, str(status)):
if status == DeviceAttributes.progress:
Expand Down Expand Up @@ -137,5 +135,6 @@ def set_attribute(self, attr, value):
message.washing_data = self._attributes[DeviceAttributes.washing_data]
self.build_send(message)


class MideaAppliance(MideaDADevice):
pass
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/da/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _body(self):
power, 0xFF
])


class MessageStart(MessageDABase):
def __init__(self, protocol_version):
super().__init__(
Expand Down
3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/e3/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def process_message(self, msg):
new_status = {}
for status in self._attributes.keys():
if hasattr(message, str(status)):
if self._precision_halves and status in [DeviceAttributes.current_temperature,
DeviceAttributes.target_temperature]:
if self._precision_halves and status in [DeviceAttributes.current_temperature, DeviceAttributes.target_temperature]:
self._attributes[status] = getattr(message, str(status)) / 2
else:
self._attributes[status] = getattr(message, str(status))
Expand Down
3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/e8/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(self, message):
if len(super().body) > 6:
sub_cmd = super().body[6]
if ((self.message_type == MessageType.set and sub_cmd in [0x02, 0x04, 0x06]) or
self.message_type in [MessageType.query, MessageType.notify1] and sub_cmd ==2):
self.message_type in [MessageType.query, MessageType.notify1] and sub_cmd == 2):
self.set_body(E8MessageBody(super().body))
self.set_attr()

2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/ea/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, message):
elif self.message_type == MessageType.notify1 and super().body[5] == 0x3d: # 463
self.set_body(EABody1(super().body))
else:
if(self.message_type == MessageType.set and super().body[3] == 0x02) or \
if (self.message_type == MessageType.set and super().body[3] == 0x02) or \
(self.message_type == MessageType.query and super().body[3] == 0x03) or \
(self.message_type == MessageType.notify1 and super().body[3] == 0x04): # 351
self.set_body(EABody3(super().body))
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/ec/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, message):
super().__init__(message)
if self.message_type == MessageType.notify1 and super().body[3] == 0x01:
self.set_body(ECBodyNew(super().body))
elif(self.message_type == MessageType.set and super().body[3] == 0x02) or \
elif (self.message_type == MessageType.set and super().body[3] == 0x02) or \
(self.message_type == MessageType.query and super().body[3] == 0x03) or \
(self.message_type == MessageType.notify1 and super().body[3] == 0x04) or \
(self.message_type == MessageType.notify1 and super().body[3] == 0x3d):
Expand Down
Loading

0 comments on commit 055ced0

Please sign in to comment.