From 055ced0f72f8b956d9283777a4f0f302902237fc Mon Sep 17 00:00:00 2001 From: Wentao Wu Date: Mon, 13 May 2024 15:25:59 +0800 Subject: [PATCH] update based on super linter error --- .flake8 | 2 ++ .github/workflows/linter.yml | 1 + .github/workflows/release.yml | 23 +++++++++---------- README.md | 13 +++++++++-- README_hans.md | 6 ++++- custom_components/midea_ac_lan/__init__.py | 2 -- custom_components/midea_ac_lan/climate.py | 2 +- custom_components/midea_ac_lan/config_flow.py | 4 ++-- .../midea_ac_lan/midea/backports/enum.py | 2 +- .../midea_ac_lan/midea/core/device.py | 2 +- .../midea_ac_lan/midea/core/security.py | 2 +- .../midea_ac_lan/midea/devices/__init__.py | 6 +++-- .../midea_ac_lan/midea/devices/a1/message.py | 1 + .../midea_ac_lan/midea/devices/ac/message.py | 6 ++--- .../midea_ac_lan/midea/devices/b0/message.py | 3 +-- .../midea_ac_lan/midea/devices/b1/message.py | 3 +-- .../midea_ac_lan/midea/devices/b3/message.py | 1 - .../midea_ac_lan/midea/devices/b4/message.py | 3 +-- .../midea_ac_lan/midea/devices/c2/message.py | 1 + .../midea_ac_lan/midea/devices/c3/device.py | 4 +++- .../midea_ac_lan/midea/devices/c3/message.py | 2 +- .../midea_ac_lan/midea/devices/cd/message.py | 5 ++-- .../midea_ac_lan/midea/devices/cf/message.py | 1 - .../midea_ac_lan/midea/devices/da/device.py | 9 ++++---- .../midea_ac_lan/midea/devices/da/message.py | 2 +- .../midea_ac_lan/midea/devices/e3/device.py | 3 +-- .../midea_ac_lan/midea/devices/e8/message.py | 3 +-- .../midea_ac_lan/midea/devices/ea/message.py | 2 +- .../midea_ac_lan/midea/devices/ec/message.py | 2 +- .../midea_ac_lan/midea/devices/ed/device.py | 2 +- .../midea_ac_lan/midea/devices/x13/device.py | 3 +-- .../midea_ac_lan/midea/devices/x13/message.py | 2 +- .../midea_ac_lan/midea/devices/x26/message.py | 3 +-- .../midea_ac_lan/midea/devices/x40/message.py | 3 +-- .../midea_ac_lan/midea_entity.py | 2 +- custom_components/midea_ac_lan/number.py | 6 ++--- custom_components/midea_ac_lan/services.yaml | 2 +- doc/FA.md | 4 ++-- 38 files changed, 75 insertions(+), 68 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..e44b8108 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +ignore = E501 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index d2b00af8..30190df6 100755 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -35,3 +35,4 @@ jobs: env: # To report GitHub Actions status checks GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VALIDATE_GITLEAKS: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d3d74650..155a956e 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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" @@ -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: @@ -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}} " diff --git a/README.md b/README.md index 40b5449a..0539c9ad 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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*** diff --git a/README_hans.md b/README_hans.md index 54b335c6..5e1ae2bd 100644 --- a/README_hans.md +++ b/README_hans.md @@ -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) 以及更多。 diff --git a/custom_components/midea_ac_lan/__init__.py b/custom_components/midea_ac_lan/__init__.py index 330f5e15..31aed7c3 100644 --- a/custom_components/midea_ac_lan/__init__.py +++ b/custom_components/midea_ac_lan/__init__.py @@ -9,9 +9,7 @@ CONF_SUBTYPE, CONF_REFRESH_INTERVAL, DEVICES, - EXTRA_SENSOR, EXTRA_SWITCH, - EXTRA_CONTROL, ALL_PLATFORM, ) from .midea_devices import MIDEA_DEVICES diff --git a/custom_components/midea_ac_lan/climate.py b/custom_components/midea_ac_lan/climate.py index b5a6c9db..4f54f395 100644 --- a/custom_components/midea_ac_lan/climate.py +++ b/custom_components/midea_ac_lan/climate.py @@ -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) diff --git a/custom_components/midea_ac_lan/config_flow.py b/custom_components/midea_ac_lan/config_flow.py index 98c8b53b..fd3432c1 100644 --- a/custom_components/midea_ac_lan/config_flow.py +++ b/custom_components/midea_ac_lan/config_flow.py @@ -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, @@ -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"): diff --git a/custom_components/midea_ac_lan/midea/backports/enum.py b/custom_components/midea_ac_lan/midea/backports/enum.py index 03f626fe..03b359ae 100644 --- a/custom_components/midea_ac_lan/midea/backports/enum.py +++ b/custom_components/midea_ac_lan/midea/backports/enum.py @@ -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") \ No newline at end of file + raise TypeError("auto() is not supported by this implementation") diff --git a/custom_components/midea_ac_lan/midea/core/device.py b/custom_components/midea_ac_lan/midea/core/device.py index dc364673..e9fee776 100644 --- a/custom_components/midea_ac_lan/midea/core/device.py +++ b/custom_components/midea_ac_lan/midea/core/device.py @@ -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, " diff --git a/custom_components/midea_ac_lan/midea/core/security.py b/custom_components/midea_ac_lan/midea/core/security.py index fc31bda2..ccf0e96f 100644 --- a/custom_components/midea_ac_lan/midea/core/security.py +++ b/custom_components/midea_ac_lan/midea/core/security.py @@ -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): diff --git a/custom_components/midea_ac_lan/midea/devices/__init__.py b/custom_components/midea_ac_lan/midea/devices/__init__.py index a8700311..fcc5e119 100644 --- a/custom_components/midea_ac_lan/midea/devices/__init__.py +++ b/custom_components/midea_ac_lan/midea/devices/__init__.py @@ -2,6 +2,7 @@ from importlib import import_module from types import ModuleType + async def async_device_selector( hass: HomeAssistant, name: str, @@ -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, diff --git a/custom_components/midea_ac_lan/midea/devices/a1/message.py b/custom_components/midea_ac_lan/midea/devices/a1/message.py index cf675483..1f5fc0e8 100644 --- a/custom_components/midea_ac_lan/midea/devices/a1/message.py +++ b/custom_components/midea_ac_lan/midea/devices/a1/message.py @@ -8,6 +8,7 @@ NewProtocolMessageBody ) + class NewProtocolTags(IntEnum): light = 0x005B diff --git a/custom_components/midea_ac_lan/midea/devices/ac/message.py b/custom_components/midea_ac_lan/midea/devices/ac/message.py index 37b10b3f..f8118c3d 100644 --- a/custom_components/midea_ac_lan/midea/devices/ac/message.py +++ b/custom_components/midea_ac_lan/midea/devices/ac/message.py @@ -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, @@ -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 diff --git a/custom_components/midea_ac_lan/midea/devices/b0/message.py b/custom_components/midea_ac_lan/midea/devices/b0/message.py index 6503d4cc..1c4a9eb1 100644 --- a/custom_components/midea_ac_lan/midea/devices/b0/message.py +++ b/custom_components/midea_ac_lan/midea/devices/b0/message.py @@ -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, @@ -82,4 +82,3 @@ def __init__(self, message): else: self.set_body(B0MessageBody(super().body)) self.set_attr() - diff --git a/custom_components/midea_ac_lan/midea/devices/b1/message.py b/custom_components/midea_ac_lan/midea/devices/b1/message.py index bbf50abd..8a9a74c7 100644 --- a/custom_components/midea_ac_lan/midea/devices/b1/message.py +++ b/custom_components/midea_ac_lan/midea/devices/b1/message.py @@ -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, @@ -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() - diff --git a/custom_components/midea_ac_lan/midea/devices/b3/message.py b/custom_components/midea_ac_lan/midea/devices/b3/message.py index a4c68ca5..8af1d9e6 100644 --- a/custom_components/midea_ac_lan/midea/devices/b3/message.py +++ b/custom_components/midea_ac_lan/midea/devices/b3/message.py @@ -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() - diff --git a/custom_components/midea_ac_lan/midea/devices/b4/message.py b/custom_components/midea_ac_lan/midea/devices/b4/message.py index 489c0f14..91f55059 100644 --- a/custom_components/midea_ac_lan/midea/devices/b4/message.py +++ b/custom_components/midea_ac_lan/midea/devices/b4/message.py @@ -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] @@ -55,4 +55,3 @@ def __init__(self, message): if self.body_type == 0x01: self.set_body(B4MessageBody(super().body)) self.set_attr() - diff --git a/custom_components/midea_ac_lan/midea/devices/c2/message.py b/custom_components/midea_ac_lan/midea/devices/c2/message.py index 71c608b4..343fa1b3 100644 --- a/custom_components/midea_ac_lan/midea/devices/c2/message.py +++ b/custom_components/midea_ac_lan/midea/devices/c2/message.py @@ -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: diff --git a/custom_components/midea_ac_lan/midea/devices/c3/device.py b/custom_components/midea_ac_lan/midea/devices/c3/device.py index a625866d..cf1679b3 100644 --- a/custom_components/midea_ac_lan/midea/devices/c3/device.py +++ b/custom_components/midea_ac_lan/midea/devices/c3/device.py @@ -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, diff --git a/custom_components/midea_ac_lan/midea/devices/c3/message.py b/custom_components/midea_ac_lan/midea/devices/c3/message.py index ddfb8cc6..577d8c20 100644 --- a/custom_components/midea_ac_lan/midea/devices/c3/message.py +++ b/custom_components/midea_ac_lan/midea/devices/c3/message.py @@ -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() \ No newline at end of file + self.set_attr() diff --git a/custom_components/midea_ac_lan/midea/devices/cd/message.py b/custom_components/midea_ac_lan/midea/devices/cd/message.py index 450345e5..40c4ba0c 100644 --- a/custom_components/midea_ac_lan/midea/devices/cd/message.py +++ b/custom_components/midea_ac_lan/midea/devices/cd/message.py @@ -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, @@ -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, @@ -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) diff --git a/custom_components/midea_ac_lan/midea/devices/cf/message.py b/custom_components/midea_ac_lan/midea/devices/cf/message.py index e05ecf3c..6c7105bd 100644 --- a/custom_components/midea_ac_lan/midea/devices/cf/message.py +++ b/custom_components/midea_ac_lan/midea/devices/cf/message.py @@ -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() - diff --git a/custom_components/midea_ac_lan/midea/devices/da/device.py b/custom_components/midea_ac_lan/midea/devices/da/device.py index 9323bdbd..41b3a624 100644 --- a/custom_components/midea_ac_lan/midea/devices/da/device.py +++ b/custom_components/midea_ac_lan/midea/devices/da/device.py @@ -32,7 +32,7 @@ class DeviceAttributes(StrEnum): wash_strength = "wash_strength" softener = "softener" detergent = "detergent" - + class MideaDADevice(MiedaDevice): def __init__( @@ -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: @@ -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 diff --git a/custom_components/midea_ac_lan/midea/devices/da/message.py b/custom_components/midea_ac_lan/midea/devices/da/message.py index 3dba050f..25b1dd81 100644 --- a/custom_components/midea_ac_lan/midea/devices/da/message.py +++ b/custom_components/midea_ac_lan/midea/devices/da/message.py @@ -47,7 +47,7 @@ def _body(self): power, 0xFF ]) - + class MessageStart(MessageDABase): def __init__(self, protocol_version): super().__init__( diff --git a/custom_components/midea_ac_lan/midea/devices/e3/device.py b/custom_components/midea_ac_lan/midea/devices/e3/device.py index 7340a625..5ad753d2 100644 --- a/custom_components/midea_ac_lan/midea/devices/e3/device.py +++ b/custom_components/midea_ac_lan/midea/devices/e3/device.py @@ -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)) diff --git a/custom_components/midea_ac_lan/midea/devices/e8/message.py b/custom_components/midea_ac_lan/midea/devices/e8/message.py index 7ee345d5..9c45c688 100644 --- a/custom_components/midea_ac_lan/midea/devices/e8/message.py +++ b/custom_components/midea_ac_lan/midea/devices/e8/message.py @@ -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() - diff --git a/custom_components/midea_ac_lan/midea/devices/ea/message.py b/custom_components/midea_ac_lan/midea/devices/ea/message.py index b8e09712..e6f147a1 100644 --- a/custom_components/midea_ac_lan/midea/devices/ea/message.py +++ b/custom_components/midea_ac_lan/midea/devices/ea/message.py @@ -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)) diff --git a/custom_components/midea_ac_lan/midea/devices/ec/message.py b/custom_components/midea_ac_lan/midea/devices/ec/message.py index fb337114..3e0c42f2 100644 --- a/custom_components/midea_ac_lan/midea/devices/ec/message.py +++ b/custom_components/midea_ac_lan/midea/devices/ec/message.py @@ -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): diff --git a/custom_components/midea_ac_lan/midea/devices/ed/device.py b/custom_components/midea_ac_lan/midea/devices/ed/device.py index cd0ca7d7..0af734b1 100644 --- a/custom_components/midea_ac_lan/midea/devices/ed/device.py +++ b/custom_components/midea_ac_lan/midea/devices/ed/device.py @@ -70,7 +70,7 @@ def __init__( self._device_class = 0 def _use_new_set(self): - return True # if (self.sub_type > 342 or self.sub_type == 340) else False + return True # if (self.sub_type > 342 or self.sub_type == 340) else False def build_query(self): return [ diff --git a/custom_components/midea_ac_lan/midea/devices/x13/device.py b/custom_components/midea_ac_lan/midea/devices/x13/device.py index 2a4e1e11..049c6afe 100644 --- a/custom_components/midea_ac_lan/midea/devices/x13/device.py +++ b/custom_components/midea_ac_lan/midea/devices/x13/device.py @@ -69,8 +69,7 @@ def color_temp_range(self): return self._color_temp_range def kelvin_to_midea(self, kelvin): - return round((kelvin - self._color_temp_range[0]) / - (self._color_temp_range[1] - self._color_temp_range[0]) * 255) + return round((kelvin - self._color_temp_range[0]) / (self._color_temp_range[1] - self._color_temp_range[0]) * 255) def midea_to_kelvin(self, midea): return round((self._color_temp_range[1] - self._color_temp_range[0]) / 255 * midea) + \ diff --git a/custom_components/midea_ac_lan/midea/devices/x13/message.py b/custom_components/midea_ac_lan/midea/devices/x13/message.py index bf6bc09a..ce8e3699 100644 --- a/custom_components/midea_ac_lan/midea/devices/x13/message.py +++ b/custom_components/midea_ac_lan/midea/devices/x13/message.py @@ -84,6 +84,7 @@ def __init__(self, body): super().__init__(body) self.control_success = body[1] > 0 + class Message13Response(MessageResponse): def __init__(self, message): super().__init__(message) @@ -92,4 +93,3 @@ def __init__(self, message): elif self.message_type == MessageType.set and self.body_type > 0x80: self.set_body(MessageMainLightResponseBody(super().body)) self.set_attr() - diff --git a/custom_components/midea_ac_lan/midea/devices/x26/message.py b/custom_components/midea_ac_lan/midea/devices/x26/message.py index 268bf96e..f0afd96c 100644 --- a/custom_components/midea_ac_lan/midea/devices/x26/message.py +++ b/custom_components/midea_ac_lan/midea/devices/x26/message.py @@ -107,7 +107,7 @@ def __init__(self, body): self.fields["LIGHT_INTENSITY_THRESHOLD"] = self.read_byte(body, 7) self.fields["RADAR_SENSITIVITY"] = self.read_byte(body, 8) heat_mode = self.read_byte(body, 9) > 0 - heat_temperature = self.read_byte(body, 10) + heat_temperature = self.read_byte(body, 10) self.fields["HEATING_SPEED"] = self.read_byte(body, 11) heat_direction = self.read_byte(body, 12) bath_mode = self.read_byte(body, 13) > 0 @@ -171,4 +171,3 @@ def __init__(self, message): if self.message_type in [MessageType.set, MessageType.notify1, MessageType.query] and self.body_type == 0x01: self.set_body(Message26Body(super().body)) self.set_attr() - diff --git a/custom_components/midea_ac_lan/midea/devices/x40/message.py b/custom_components/midea_ac_lan/midea/devices/x40/message.py index a7afb1be..71baa781 100644 --- a/custom_components/midea_ac_lan/midea/devices/x40/message.py +++ b/custom_components/midea_ac_lan/midea/devices/x40/message.py @@ -114,7 +114,7 @@ def __init__(self, body): self.fields["LIGHT_INTENSITY_THRESHOLD"] = body[7] self.fields["RADAR_SENSITIVITY"] = body[8] self.fields["HEATING_ENABLE"] = body[9] - self.fields["HEATING_TEMPERATURE"]= body[10] + self.fields["HEATING_TEMPERATURE"] = body[10] self.fields["HEATING_SPEED"] = body[11] self.fields["HEATING_DIRECTION"] = body[12] self.fields["BATH_ENABLE"] = body[13] > 0 @@ -160,4 +160,3 @@ def __init__(self, message): if self.message_type in [MessageType.set, MessageType.notify1, MessageType.query] and self.body_type == 0x01: self.set_body(Message40Body(super().body)) self.set_attr() - diff --git a/custom_components/midea_ac_lan/midea_entity.py b/custom_components/midea_ac_lan/midea_entity.py index 9ae901d8..2970811d 100644 --- a/custom_components/midea_ac_lan/midea_entity.py +++ b/custom_components/midea_ac_lan/midea_entity.py @@ -15,7 +15,7 @@ def __init__(self, device, entity_key: str): self._unique_id = f"{DOMAIN}.{self._device.device_id}_{entity_key}" self.entity_id = self._unique_id self._device_name = self._device.name - + @property def device(self): return self._device diff --git a/custom_components/midea_ac_lan/number.py b/custom_components/midea_ac_lan/number.py index 34624507..360e7a5c 100644 --- a/custom_components/midea_ac_lan/number.py +++ b/custom_components/midea_ac_lan/number.py @@ -35,21 +35,21 @@ def __init__(self, device, entity_key: str): @property def native_min_value(self): - return self._min_value if (type(self._min_value) is int) else \ + return self._min_value if isinstance(self._min_value, int) else \ self._device.get_attribute(attr=self._min_value) \ if self._device.get_attribute(attr=self._min_value) else \ getattr(self._device, self._min_value) @property def native_max_value(self): - return self._max_value if (type(self._max_value) is int) else \ + return self._max_value if isinstance(self._max_value, int) else \ self._device.get_attribute(attr=self._max_value) \ if self._device.get_attribute(attr=self._max_value) else \ getattr(self._device, self._max_value) @property def native_step(self): - return self._step_value if (type(self._step_value) is int) else \ + return self._step_value if isinstance(self._step_value, int) else \ self._device.get_attribute(attr=self._step_value) \ if self._device.get_attribute(attr=self._step_value) else \ getattr(self._device, self._step_value) diff --git a/custom_components/midea_ac_lan/services.yaml b/custom_components/midea_ac_lan/services.yaml index 34ef2fc9..bfb99b49 100644 --- a/custom_components/midea_ac_lan/services.yaml +++ b/custom_components/midea_ac_lan/services.yaml @@ -14,4 +14,4 @@ send_command: cmd_type: example: 2 cmd_body: - example: "B0FF01370E0000A500" \ No newline at end of file + example: "B0FF01370E0000A500" diff --git a/doc/FA.md b/doc/FA.md index 93ba2427..a4e08289 100644 --- a/doc/FA.md +++ b/doc/FA.md @@ -68,7 +68,7 @@ Set the attribute of appliance. Service data: Example -``` +```yaml service: midea_ac_lan.set_attribute data: device_id: XXXXXXXXXXXX @@ -76,7 +76,7 @@ data: value: true ``` -``` +```yaml service: midea_ac_lan.set_attribute data: device_id: XXXXXXXXXXXX