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

Flake8 yaml markdown linter fix #11

Merged
merged 17 commits into from
May 21, 2024
Merged
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
13 changes: 8 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
name: "CodeQL"

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
# schedule:
# - cron: "42 8 * * 6"
branches: ["master"]
# schedule:
# - cron: "42 8 * * 6"

permissions: {}

jobs:
analyze:
Expand All @@ -20,7 +23,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ python ]
language: [python]

steps:
- name: Checkout
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Lint

on: # yamllint disable-line rule:truthy
push: null
pull_request: null

permissions: {}

jobs:
build:
name: Lint
runs-on: ubuntu-latest

permissions:
contents: read
packages: read
# To report GitHub Actions status checks
statuses: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# super-linter needs the full git history to get the
# list of files that changed across commits
fetch-depth: 0

- name: Super-linter
uses: super-linter/[email protected] # x-release-please-version
env:
# To report GitHub Actions status checks
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_GITLEAKS: false
VALIDATE_JSCPD: false
VALIDATE_PYTHON_PYLINT: false
VALIDATE_PYTHON_MYPY: false
VALIDATE_PYTHON_BLACK: false
VALIDATE_PYTHON_ISORT: false
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/myenum.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")
6 changes: 3 additions & 3 deletions custom_components/midea_ac_lan/midea/core/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def list_appliances(self, home_id) -> dict | None:
"sn": self._security.aes_decrypt(appliance.get("sn")) if appliance.get("sn") else "",
"sn8": appliance.get("sn8", "00000000"),
"model_number": model_number,
"manufacturer_code":appliance.get("enterpriseCode", "0000"),
"manufacturer_code": appliance.get("enterpriseCode", "0000"),
"model": appliance.get("productModel"),
"online": appliance.get("onlineStatus") == "1",
}
Expand Down Expand Up @@ -464,7 +464,7 @@ async def list_appliances(self, home_id) -> dict | None:
"sn": self._security.aes_decrypt(appliance.get("sn")) if appliance.get("sn") else "",
"sn8": "",
"model_number": model_number,
"manufacturer_code":appliance.get("enterpriseCode", "0000"),
"manufacturer_code": appliance.get("enterpriseCode", "0000"),
"model": "",
"online": appliance.get("onlineStatus") == "1",
}
Expand Down Expand Up @@ -624,7 +624,7 @@ async def list_appliances(self, home_id) -> dict | None:
"sn": appliance.get("sn"),
"sn8": "",
"model_number": model_number,
"manufacturer_code":appliance.get("enterpriseCode", "0000"),
"manufacturer_code": appliance.get("enterpriseCode", "0000"),
"model": "",
"online": appliance.get("onlineStatus") == "1",
}
Expand Down
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: {e}, msg = {decrypted.hex()}")
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
2 changes: 2 additions & 0 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 @@ -24,6 +25,7 @@ async def async_device_selector(
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__))
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
5 changes: 2 additions & 3 deletions custom_components/midea_ac_lan/midea/devices/ac/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ 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
1 change: 0 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/b0/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,3 @@ def __init__(self, message):
else:
self.set_body(B0MessageBody(super().body))
self.set_attr()

1 change: 0 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/b1/message.py
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 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,7 @@ 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()

3 changes: 2 additions & 1 deletion custom_components/midea_ac_lan/midea/devices/da/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def process_message(self, msg):
speed = ["-", "Low", "Medium", "High"]
strength = ["-", "Week", "Medium", "Strong"]
detergent = ["No", "Less", "Medium", "More", "4",
"5", "6", "7", "8", "Insufficient"]
"5", "6", "7", "8", "Insufficient"]
softener = ["No", "Intelligent", "Programed", "3", "4",
"5", "6", "7", "8", "Insufficient"]
for status in self._attributes.keys():
Expand Down Expand Up @@ -137,5 +137,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/db/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, protocol_version):

@property
def _body(self):
if self.start: # Pause
if self.start: # Pause
return bytearray([
0xFF, 0x01
]) + self.washing_data
Expand Down
5 changes: 3 additions & 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,9 @@ 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
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/ed/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion custom_components/midea_ac_lan/midea/devices/x13/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def color_temp_range(self):

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)
(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) + \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/x26/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

3 changes: 1 addition & 2 deletions custom_components/midea_ac_lan/midea/devices/x40/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Loading
Loading