Просмотр исходного кода

CI: change from black and isort to ruff.

Changes to black today broke CI, so this is a catalyst to make the
move to ruff, as Home Assistant already has.

A few issues picked up, and apparently isort has not been working
(or maybe was reporting its findings without flagging an error).

Also should do general linting, but there will be quite a bit of
cleanup for that.
Jason Rumney 2 лет назад
Родитель
Сommit
e72678b274

+ 2 - 2
.github/workflows/linting.yml

@@ -18,6 +18,6 @@ jobs:
           python -m pip install --upgrade pip
           pip install -r requirements-dev.txt
       - name: isort
-        run: isort --recursive --diff .
+        run: ruff check --select I diff .
       - name: Black
-        run: black --check --diff .
+        run: ruff format --check --diff .

+ 2 - 2
custom_components/tuya_local/lawn_mower.py

@@ -3,11 +3,11 @@ Setup for different kinds of Tuya lawn mowers
 """
 from homeassistant.components.lawn_mower import LawnMowerEntity
 from homeassistant.components.lawn_mower.const import (
-    LawnMowerActivity,
-    LawnMowerEntityFeature,
     SERVICE_DOCK,
     SERVICE_PAUSE,
     SERVICE_START_MOWING,
+    LawnMowerActivity,
+    LawnMowerEntityFeature,
 )
 
 from .device import TuyaLocalDevice

+ 17 - 6
custom_components/tuya_local/remote.py

@@ -3,15 +3,15 @@ Implementation of Tuya remote control devices
 Based on broadlink integration for code saving under HA storage
 """
 import asyncio
+import json
+import logging
 from collections import defaultdict
 from collections.abc import Iterable
 from datetime import timedelta
 from itertools import product
-import json
-import logging
 from typing import Any
-import voluptuous as vol
 
+import voluptuous as vol
 from homeassistant.components import persistent_notification
 from homeassistant.components.remote import (
     ATTR_ALTERNATIVE,
@@ -19,17 +19,24 @@ from homeassistant.components.remote import (
     ATTR_DEVICE,
     ATTR_NUM_REPEATS,
     DEFAULT_DELAY_SECS,
-    DOMAIN as RM_DOMAIN,
-    RemoteEntity,
-    RemoteEntityFeature,
     SERVICE_DELETE_COMMAND,
     SERVICE_LEARN_COMMAND,
     SERVICE_SEND_COMMAND,
+    RemoteEntity,
+    RemoteEntityFeature,
+)
+from homeassistant.components.remote import (
+    DOMAIN as RM_DOMAIN,
 )
 from homeassistant.const import ATTR_COMMAND
 from homeassistant.helpers import config_validation as cv
 from homeassistant.helpers.storage import Store
 from homeassistant.util import dt as dt_util
+# from tinytuya.Contrib.IRRemoteControlDevice import (
+#     base64_to_pulses,
+#     pulses_to_pronto,
+#     pulses_to_width_encoded,
+# )
 
 from .device import TuyaLocalDevice
 from .helpers.config import async_tuya_setup_platform
@@ -259,6 +266,10 @@ class TuyaLocalRemote(TuyaLocalEntity, RemoteEntity):
 
             for command in commands:
                 code = await self._async_learn_command(command)
+                _LOGGER.info("Learning %s for %s: %s", command, subdevice, code)
+                # pulses = base64_to_pulses(code)
+                # _LOGGER.debug("= pronto code: %s", pulses_to_pronto(pulses))
+                # _LOGGER.debug("= width encoded: %s", pulses_to_width_encoded(pulses))
                 if toggle:
                     code = [code, await self._async_learn_command(command)]
                 self._codes.setdefault(subdevice, {}).update({command: code})

+ 1 - 2
requirements-dev.txt

@@ -1,9 +1,8 @@
-black
 fuzzywuzzy
-isort
 levenshtein
 pytest-homeassistant-custom-component~=0.13.88
 pytest
 pytest-asyncio
 pytest-cov
+ruff
 tinytuya~=1.13.1

+ 1 - 1
tests/devices/test_avatto_blinds.py

@@ -54,7 +54,7 @@ class TestAvattoBlinds(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
                 "3": "3 hours",
                 "4": "4 hours",
             },
-        ),
+        )
         self.mark_secondary(["sensor_travel_time", "sensor_timer", "select_timer"])
 
     def test_device_class_is_blind(self):

+ 1 - 1
tests/devices/test_kyvol_e30_vacuum.py

@@ -1,5 +1,5 @@
 from homeassistant.components.button import ButtonDeviceClass
-from homeassistant.components.sensor import SensorDeviceClass, STATE_CLASS_MEASUREMENT
+from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,

+ 1 - 1
tests/devices/test_lefant_m213_vacuum.py

@@ -1,4 +1,4 @@
-from homeassistant.components.sensor import SensorDeviceClass, STATE_CLASS_MEASUREMENT
+from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorDeviceClass
 from homeassistant.components.vacuum import (
     STATE_CLEANING,
     STATE_DOCKED,

+ 1 - 1
tests/devices/test_m027_curtain.py

@@ -50,7 +50,7 @@ class TestM027Curtains(MultiSensorTests, BasicSelectTests, TuyaDeviceTestCase):
                 "morning": "Morning",
                 "night": "Night",
             },
-        ),
+        )
         self.mark_secondary(
             [
                 "binary_sensor_fault",

+ 2 - 1
tests/devices/test_moebot.py

@@ -3,11 +3,12 @@ Test MoeBot S mower.
 Primarily for testing the STOP command which this device is the first to use,
 and the lawn_mower platform.
 """
-from homeassistant.components.vacuum import VacuumEntityFeature
 from homeassistant.components.lawn_mower.const import (
     LawnMowerActivity,
     LawnMowerEntityFeature,
 )
+from homeassistant.components.vacuum import VacuumEntityFeature
+
 from ..const import MOEBOT_PAYLOAD
 from ..helpers import assert_device_properties_set
 from .base_device_tests import TuyaDeviceTestCase

+ 1 - 1
tests/devices/test_qs_c01_curtain.py

@@ -34,7 +34,7 @@ class TestQSC01Curtains(BasicNumberTests, BasicSelectTests, TuyaDeviceTestCase):
                 "forward": "Forward",
                 "back": "Back",
             },
-        ),
+        )
         self.mark_secondary(["number_travel_time", "select_motor_reverse_mode"])
 
     def test_device_class_is_curtain(self):

+ 4 - 4
tests/test_event.py

@@ -4,16 +4,16 @@ from unittest.mock import AsyncMock, Mock
 import pytest
 from pytest_homeassistant_custom_component.common import MockConfigEntry
 
-from custom_components.tuya_local.event import (
-    TuyaLocalEvent,
-    async_setup_entry,
-)
 from custom_components.tuya_local.const import (
     CONF_DEVICE_ID,
     CONF_PROTOCOL_VERSION,
     CONF_TYPE,
     DOMAIN,
 )
+from custom_components.tuya_local.event import (
+    TuyaLocalEvent,
+    async_setup_entry,
+)
 
 
 @pytest.mark.asyncio

+ 1 - 1
util/catalog.py

@@ -8,8 +8,8 @@ modification, then again after to compare the two outputs.
 import sys
 
 from custom_components.tuya_local.helpers.device_config import (
-    available_configs,
     TuyaDeviceConfig,
+    available_configs,
 )