diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a104aed..4e1d3fb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,16 +1,10 @@ name: Lint -on: [push, pull_request] +on: [push] jobs: - black: + ruff: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: psf/black@stable - - isort: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: isort/isort-action@v1 + - uses: astral-sh/ruff-action@v3 diff --git a/pyproject.toml b/pyproject.toml index 5be3e0a..cdda6fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,5 +34,20 @@ include-package-data = false exclude = ["tests"] namespaces = false -[tool.isort] -profile = "black" +[tool.ruff.lint] +select = [ + # pycodestyle + "E", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # isort + "I",] + + + +[tool.ruff.lint.mccabe] +max-complexity = 25 diff --git a/requirements-dev.txt b/requirements-dev.txt index bafa7ed..8b39f4d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,6 @@ -r requirements.txt -black +aioresponses==0.7.6 pytest>=6.2.0 pytest-asyncio>=0.15.0 pytest-mock>=3.6.0 -aioresponses==0.7.6 +ruff diff --git a/tests/test_auth.py b/tests/test_auth.py index 2a65fd4..357df04 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -75,7 +75,8 @@ async def test_auth_will_check_all_client_creds( expected = [] for i in range(len(client_creds)): - # all but the last one should return 404, as we keep checking until we get a 200 (or run out) + # all but the last one should return 404, as we keep checking until we get a 200 + # (or run out) status = HTTPStatus.NOT_FOUND if i != len(client_creds) else HTTPStatus.OK expected.append({"status": status}) aioresponses_mock.post(AUTH_URL, status=status) @@ -110,7 +111,8 @@ async def test_auth_bad_credentials( # assert that the proper method and url were used assert ("POST", URL(AUTH_URL)) in aioresponses_mock.requests - # get the calls for the method/url and assert length - should be the same as the number of client credentials + # get the calls for the method/url and assert length - should be the same as the + # number of client credentials calls = aioresponses_mock.requests[("POST", URL(AUTH_URL))] assert len(calls) == len(backend_selector_mock.client_credentials) diff --git a/tests/test_oven.py b/tests/test_oven.py index 54da1e1..827b7dd 100644 --- a/tests/test_oven.py +++ b/tests/test_oven.py @@ -35,14 +35,14 @@ async def test_attributes( await oven.connect() assert oven.get_online() is True - assert oven.get_door_opened() == False - assert oven.get_control_locked() == False - assert oven.get_sabbath_mode() == False + assert oven.get_door_opened() is False + assert oven.get_control_locked() is False + assert oven.get_sabbath_mode() is False assert oven.get_display_brightness_percent() == 90 - assert oven.get_oven_cavity_exists(Cavity.Upper) == True - assert oven.get_oven_cavity_exists(Cavity.Lower) == False - assert oven.get_light(Cavity.Upper) == False - assert oven.get_meat_probe_status(Cavity.Upper) == False + assert oven.get_oven_cavity_exists(Cavity.Upper) is True + assert oven.get_oven_cavity_exists(Cavity.Lower) is False + assert oven.get_light(Cavity.Upper) is False + assert oven.get_meat_probe_status(Cavity.Upper) is False assert oven.get_cook_time(Cavity.Upper) == 81 assert oven.get_temp(Cavity.Upper) == 37.7 assert oven.get_target_temp(Cavity.Upper) == 176.6 @@ -56,14 +56,14 @@ async def test_attributes( await oven.connect() assert oven.get_online() is True - assert oven.get_door_opened() == True - assert oven.get_control_locked() == True - assert oven.get_sabbath_mode() == False + assert oven.get_door_opened() is True + assert oven.get_control_locked() is True + assert oven.get_sabbath_mode() is False assert oven.get_display_brightness_percent() == 70 - assert oven.get_oven_cavity_exists(Cavity.Upper) == True - assert oven.get_oven_cavity_exists(Cavity.Lower) == False - assert oven.get_light(Cavity.Upper) == False - assert oven.get_meat_probe_status(Cavity.Upper) == False + assert oven.get_oven_cavity_exists(Cavity.Upper) is True + assert oven.get_oven_cavity_exists(Cavity.Lower) is False + assert oven.get_light(Cavity.Upper) is False + assert oven.get_meat_probe_status(Cavity.Upper) is False assert oven.get_cook_time(Cavity.Upper) == 0 assert oven.get_temp(Cavity.Upper) == 0.0 assert oven.get_target_temp(Cavity.Upper) == 0.0 @@ -77,14 +77,14 @@ async def test_attributes( await oven.connect() assert oven.get_online() is True - assert oven.get_door_opened() == False - assert oven.get_control_locked() == False - assert oven.get_sabbath_mode() == False + assert oven.get_door_opened() is False + assert oven.get_control_locked() is False + assert oven.get_sabbath_mode() is False assert oven.get_display_brightness_percent() == 90 - assert oven.get_oven_cavity_exists(Cavity.Upper) == True - assert oven.get_oven_cavity_exists(Cavity.Lower) == False - assert oven.get_light(Cavity.Upper) == False - assert oven.get_meat_probe_status(Cavity.Upper) == False + assert oven.get_oven_cavity_exists(Cavity.Upper) is True + assert oven.get_oven_cavity_exists(Cavity.Lower) is False + assert oven.get_light(Cavity.Upper) is False + assert oven.get_meat_probe_status(Cavity.Upper) is False assert oven.get_cook_time(Cavity.Upper) == 0 assert oven.get_temp(Cavity.Upper) == 0.0 assert oven.get_target_temp(Cavity.Upper) == 0.0 diff --git a/whirlpool/backendselector.py b/whirlpool/backendselector.py index faf2863..cb54a0f 100644 --- a/whirlpool/backendselector.py +++ b/whirlpool/backendselector.py @@ -8,27 +8,27 @@ Brand.Whirlpool: [ { "client_id": "whirlpool_emea_android_v1", - "client_secret": "h-NBGuG7EY74sSvj9TrJeeTpodJBd4T35bAyV0mfa0YnJ0i4MBue8IiS4iFidkve", + "client_secret": "h-NBGuG7EY74sSvj9TrJeeTpodJBd4T35bAyV0mfa0YnJ0i4MBue8IiS4iFidkve", # noqa: E501 }, { "client_id": "whirlpool_android_v1", - "client_secret": "yH5BcCm4ogWBoyD_NrlE04vmVps2s8T7KaIi4PYrc_fsdphWpG1IwlLSJ-yl7FGV", + "client_secret": "yH5BcCm4ogWBoyD_NrlE04vmVps2s8T7KaIi4PYrc_fsdphWpG1IwlLSJ-yl7FGV", # noqa: E501 }, ], Brand.Maytag: [ { "client_id": "maytag_android_v1", - "client_secret": "f1XfYji_D9KfZGovyp8PMgRzrFKjhjY26TV0hu3Mt1-tCCNPl9s95z7QLUfB9UgB", + "client_secret": "f1XfYji_D9KfZGovyp8PMgRzrFKjhjY26TV0hu3Mt1-tCCNPl9s95z7QLUfB9UgB", # noqa: E501 } ], Brand.KitchenAid: [ { "client_id": "kitchenaid_android_stg", - "client_secret": "Dn-ukFAFoSWOnB9nVm7Y2DDj4Gs9Bocm6aOkhy0mdNGBj5RcoLkRfCXujuxpKrqF2w15sl1tI45JXwK5Zi4saw", + "client_secret": "Dn-ukFAFoSWOnB9nVm7Y2DDj4Gs9Bocm6aOkhy0mdNGBj5RcoLkRfCXujuxpKrqF2w15sl1tI45JXwK5Zi4saw", # noqa: E501 }, { "client_id": "kitchenaid_android_v1", - "client_secret": "T5j9T4ZAMnC6EMVpPAwZyKsRykXGfKOMDqikPHYpCKEMYjssPtJtuJtMYEc30g56", + "client_secret": "T5j9T4ZAMnC6EMVpPAwZyKsRykXGfKOMDqikPHYpCKEMYjssPtJtuJtMYEc30g56", # noqa: E501 }, ], } diff --git a/whirlpool/eventsocket.py b/whirlpool/eventsocket.py index b6acc64..77554bc 100644 --- a/whirlpool/eventsocket.py +++ b/whirlpool/eventsocket.py @@ -49,7 +49,10 @@ def __init__( self._session = session def _create_connect_msg(self): - return f"CONNECT\naccept-version:1.1,1.2\nheart-beat:30000,0\nwcloudtoken:{self._auth.get_access_token()}" + return ( + "CONNECT\naccept-version:1.1,1.2\nheart-beat:30000,0\nwcloudtoken:" + f"{self._auth.get_access_token()}" + ) def _create_subscribe_msg(self): id = uuid.uuid4() @@ -113,7 +116,11 @@ async def _run(self): elif msg.data == WS_STATUS_GOING_AWAY: LOGGER.warning( - f"Received Going Away message: Waiting for {GOING_AWAY_DELAY} seconds" + ( + "Received Going Away message: Waiting for %s" + " seconds" + ), + GOING_AWAY_DELAY, ) # Give server some time to come back up. await asyncio.sleep(GOING_AWAY_DELAY) @@ -158,7 +165,8 @@ async def _run(self): if self._reconnect_tries < 0: self._reconnect_tries = 0 LOGGER.info( - f"Waiting to reconnect long delay {RECONNECT_LONG_DELAY} seconds" + f"Waiting to reconnect long delay {RECONNECT_LONG_DELAY}" + " seconds" ) # Give server some time to come back up. diff --git a/whirlpool/oven.py b/whirlpool/oven.py index 5a0d14a..30d10db 100644 --- a/whirlpool/oven.py +++ b/whirlpool/oven.py @@ -247,14 +247,16 @@ def get_temp(self, cavity: Cavity = Cavity.Upper): reported_temp = self.get_attribute( CAVITY_PREFIX_MAP[cavity] + "_" + ATTR_POSTFIX_TEMP ) - # temperatures are returned in 1/10ths of a degree Celsius, e.g. 2600 returned = 260C + # temperatures are returned in 1/10ths of a degree Celsius, + # e.g. 2600 returned = 260C return None if reported_temp is None else int(reported_temp) / 10 def get_target_temp(self, cavity: Cavity = Cavity.Upper): reported_temp = self.get_attribute( CAVITY_PREFIX_MAP[cavity] + "_" + ATTR_POSTFIX_TARGET_TEMP ) - # temperatures are returned in 1/10ths of a degree Celsius, e.g. 2600 returned = 260C + # temperatures are returned in 1/10ths of a degree Celsius, + # e.g. 2600 returned = 260C return None if reported_temp is None else int(reported_temp) / 10 def get_cavity_state(self, cavity: Cavity = Cavity.Upper):