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

chore: pre-commit tweak #18

Merged
merged 4 commits into from
May 25, 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
8 changes: 5 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp
COPY requirements.txt /tmp/pip-tmp/
RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp

RUN pip3 --disable-pip-version-check --no-cache-dir install pre-commit

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
}
},
"remoteUser": "vscode",
"postAttachCommand": "pip3 install --user -r requirements.txt"
"postAttachCommand": "pre-commit install"
}
27 changes: 11 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,22 @@ repos:
- id: check-xml
- id: check-yaml
- id: detect-private-key
- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
hooks:
- id: poetry-check
args: ["--lock"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
args: ["--tab-width", "2"]
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v4.0.0-alpha.8
# hooks:
# - id: prettier
# args: ["--tab-width", "2"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: []
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.10.0
# hooks:
# - id: mypy
# additional_dependencies: []
46 changes: 22 additions & 24 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Install requirements.txt",
"type": "shell",
"command": "pip3 install --user -r requirements.txt",
"problemMatcher": []
},
{
"label": "Build and install midealocal lib",
"type": "shell",
"command": "rm -rf dist/ && python3 -m build && pip3 install dist/midea_local*.whl",
"problemMatcher": []
},
{
"label": "Generate code coverage report",
"type": "shell",
"command": "python3 -m pytest --rootdir . --cov=midealocal --cov-report term-missing ./tests/",
"problemMatcher": []
}
]
}
"version": "2.0.0",
"tasks": [
{
"label": "Install requirements.txt",
"type": "shell",
"command": "pip3 install --user -r requirements.txt",
"problemMatcher": []
},
{
"label": "Build and install midealocal lib",
"type": "shell",
"command": "rm -rf dist/ && python3 -m build && pip3 install dist/midea_local*.whl",
"problemMatcher": []
},
{
"label": "Generate code coverage report",
"type": "shell",
"command": "python3 -m pytest --rootdir . --cov=midealocal --cov-report term-missing ./tests/",
"problemMatcher": []
}
]
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Midea-local python lib

[![Python build](https://github.com/rokam/midea-local/actions/workflows/python-build.yml/badge.svg)](https://github.com/rokam/midea-local/actions/workflows/python-build.yml)
![Python tests](https://raw.githubusercontent.com/rokam/midea-local/badges/tests.svg)
[![Python coverage](https://raw.githubusercontent.com/rokam/midea-local/badges/coverage.svg)](https://app.codecov.io/github/rokam/midea-local)
![Python fake8](https://raw.githubusercontent.com/rokam/midea-local/badges/flake8.svg)

Control your Midea M-Smart appliances via local area network.

This library is part of https://github.com/georgezhao2010/midea_ac_lan code. It was separated to segregate responsabilities.
This library is part of https://github.com/georgezhao2010/midea_ac_lan code. It was separated to segregate responsibilities.

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

## Getting started

### Finding your device

```python
from midealocal.discover import discover
# Without knowing the ip address
Expand All @@ -24,6 +26,7 @@ type_code = hex(list(discover().values())[0]['type'])[2:]
```

### Getting data from device

```python
from midealocal.discover import discover
from midealocal.devices import device_selector
Expand Down
12 changes: 6 additions & 6 deletions library_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def get_arguments() -> tuple[ArgumentParser, Namespace]:
help="Set Cloud username",
)
parser.add_argument("--password", "-p", type=str, help="Set Cloud password")
parser.add_argument(
"--cloud_name",
"-cn",
type=str,
help="Set Cloud name, options are: " + ", ".join(clouds.keys()),
)
parser.add_argument(
"--cloud_name",
"-cn",
type=str,
help="Set Cloud name, options are: " + ", ".join(clouds.keys()),
)
parser.add_argument(
"--configfile",
"-cf",
Expand Down
6 changes: 3 additions & 3 deletions midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@
"class_name": "MideaAirCloud",
"app_id": "1117",
"app_key": "ff0cf6f5f0c3471de36341cab3f7a9af",
"api_url": "https://mapp.appsmb.com",
"api_url": "https://mapp.appsmb.com", # codespell:ignore
},
"NetHome Plus": {
"class_name": "MideaAirCloud",
"app_id": "1017",
"app_key": "3742e9e5842d4ad59c2db887e12449f9",
"api_url": "https://mapp.appsmb.com",
"api_url": "https://mapp.appsmb.com", # codespell:ignore
},
"Ariston Clima": {
"class_name": "MideaAirCloud",
"app_id": "1005",
"app_key": "434a209a5ce141c3b726de067835d7f0",
"api_url": "https://mapp.appsmb.com",
"api_url": "https://mapp.appsmb.com", # codespell:ignore
},
}

Expand Down
10 changes: 5 additions & 5 deletions midealocal/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def connect(self, refresh_status=True):
return True
except socket.timeout:
_LOGGER.debug(f"[{self._device_id}] Connection timed out")
except socket.error:
except OSError:
_LOGGER.debug(f"[{self._device_id}] Connection error")
except AuthException:
_LOGGER.debug(f"[{self._device_id}] Authentication failed")
Expand Down Expand Up @@ -203,7 +203,7 @@ def refresh_status(self, wait_response=False):
while True:
msg = self._socket.recv(512)
if len(msg) == 0:
raise socket.error
raise OSError
result = self.parse_message(msg)
if result == ParseMessageResult.SUCCESS:
break
Expand Down Expand Up @@ -300,7 +300,7 @@ def send_command(self, cmd_type, cmd_body: bytearray):
)
try:
self.build_send(cmd)
except socket.error as e:
except OSError as e:
_LOGGER.debug(
f"[{self._device_id}] Interface send_command failure, {repr(e)}, "
f"cmd_type: {cmd_type}, cmd_body: {cmd_body.hex()}"
Expand Down Expand Up @@ -374,7 +374,7 @@ def run(self):
msg = self._socket.recv(512)
msg_len = len(msg)
if msg_len == 0:
raise socket.error("Connection closed by peer")
raise OSError("Connection closed by peer")
result = self.parse_message(msg)
if result == ParseMessageResult.ERROR:
_LOGGER.debug(f"[{self._device_id}] Message 'ERROR' received")
Expand All @@ -388,7 +388,7 @@ def run(self):
_LOGGER.debug(f"[{self._device_id}] Heartbeat timed out")
self.close_socket()
break
except socket.error as e:
except OSError as e:
if self._is_run:
_LOGGER.debug(f"[{self._device_id}] Socket error {repr(e)}")
self.close_socket()
Expand Down
2 changes: 1 addition & 1 deletion midealocal/devices/da/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def process_message(self, msg):
softener = [
"No",
"Intelligent",
"Programed",
"Programed", # codespell:ignore
"3",
"4",
"5",
Expand Down
10 changes: 4 additions & 6 deletions midealocal/devices/ed/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,10 @@ def __init__(self, body):
elif attr == 0x011:
self.water_consumption = (
float(
(
body[data_offset + 3]
+ (body[data_offset + 4] << 8)
+ (body[data_offset + 5] << 16)
+ (body[data_offset + 6] << 24)
)
body[data_offset + 3]
+ (body[data_offset + 4] << 8)
+ (body[data_offset + 5] << 16)
+ (body[data_offset + 6] << 24)
)
/ 1000
)
Expand Down
4 changes: 2 additions & 2 deletions midealocal/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def discover(discover_type=None, ip_address=None):
_LOGGER.debug(f"Found a unsupported device: {device}")
except socket.timeout:
break
except socket.error as e:
except OSError as e:
_LOGGER.error(f"Socket error: {repr(e)}")
return found_devices

Expand Down Expand Up @@ -279,7 +279,7 @@ def get_device_info(device_ip, device_port: int):
f"Connect the device {device_ip}:{device_port} timed out for 8s. "
f"Don't care about a small amount of this. if many maybe not support."
)
except socket.error:
except OSError:
_LOGGER.warning(f"Can't connect to Device {device_ip}:{device_port}")
return response

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
with open("README.md", encoding="utf-8") as fh:
long_description = fh.read()

requires = ["aiohttp", "ifaddr", "pycryptodome"]
Expand Down
Loading