From 63f9f7fea505fdf9a26c77c6cd0bff889abcdb05 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <9592452+CFenner@users.noreply.github.com> Date: Wed, 27 Dec 2023 09:53:03 +0100 Subject: [PATCH] build: add pylint workflow (#349) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lukas Wöhrl --- .github/workflows/build.yml | 19 ++++++++++++ .pylintrc | 36 ++++++++++++++++++++++ PyViCare/PyViCareDeviceConfig.py | 3 +- PyViCare/PyViCareElectricalEnergySystem.py | 1 - PyViCare/PyViCareHeatingDevice.py | 10 +++--- PyViCare/PyViCareOAuthManager.py | 2 +- PyViCare/PyViCareService.py | 4 +-- PyViCare/PyViCareVentilationDevice.py | 2 +- tests/test_VitoairFs300E.py | 1 - tests/test_Vitocal200.py | 2 +- 10 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 .pylintrc diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f12fe7a9..7c161560 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,6 +9,25 @@ on: - master jobs: + pylint: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: ["3.9"] + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Analysing the code with pylint + run: pylint $(git ls-files '*.py') + build: runs-on: ubuntu-20.04 strategy: diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..09cdeba6 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,36 @@ +[MAIN] + +[MESSAGES CONTROL] +disable= + duplicate-code, + fixme, + format, + invalid-name, + too-many-public-methods, + too-few-public-methods, + # fix later + arguments-differ, + attribute-defined-outside-init, + bad-classmethod-argument, + chained-comparison, + consider-merging-isinstance, + consider-using-dict-items, + consider-using-generator, + consider-using-in, + deprecated-decorator, + f-string-without-interpolation, + logging-fstring-interpolation, + logging-not-lazy, + missing-class-docstring, + missing-function-docstring, + missing-module-docstring, + missing-timeout, + no-else-raise, + no-else-return, + pointless-string-statement, + raise-missing-from, + super-init-not-called, + too-many-boolean-expressions, + unspecified-encoding, + useless-object-inheritance, + useless-parent-delegation, diff --git a/PyViCare/PyViCareDeviceConfig.py b/PyViCare/PyViCareDeviceConfig.py index 0a776a40..613677c4 100644 --- a/PyViCare/PyViCareDeviceConfig.py +++ b/PyViCare/PyViCareDeviceConfig.py @@ -94,8 +94,7 @@ def asAutoDetectDevice(self): for (creator_method, type_name, roles) in device_types: if re.search(type_name, self.device_model) or self.service.hasRoles(roles): - logger.info("detected %s %s" % - (self.device_model, creator_method.__name__)) + logger.info(f"detected {self.device_model} {creator_method.__name__}") return creator_method() logger.info( diff --git a/PyViCare/PyViCareElectricalEnergySystem.py b/PyViCare/PyViCareElectricalEnergySystem.py index 8e13c1c4..e2962961 100644 --- a/PyViCare/PyViCareElectricalEnergySystem.py +++ b/PyViCare/PyViCareElectricalEnergySystem.py @@ -1,4 +1,3 @@ -from typing import Any, List from PyViCare.PyViCareDevice import Device from PyViCare.PyViCareUtils import handleNotSupported from PyViCare.PyViCareService import ViCareService diff --git a/PyViCare/PyViCareHeatingDevice.py b/PyViCare/PyViCareHeatingDevice.py index 9256ce6a..78fd3723 100644 --- a/PyViCare/PyViCareHeatingDevice.py +++ b/PyViCare/PyViCareHeatingDevice.py @@ -13,8 +13,8 @@ VICARE_DHW_TEMP2 = "temp-2" -def all_set(list: List[Any]) -> bool: - return all(v is not None for v in list) +def all_set(_list: List[Any]) -> bool: + return all(v is not None for v in _list) def get_available_burners(service): @@ -605,9 +605,9 @@ def getActiveProgram(self): @handleNotSupported def getPrograms(self): available_programs = [] - for program in ['comfort', 'comfortCooling', 'comfortCoolingEnergySaving', 'comfortEnergySaving', - 'comfortHeating', 'dhwPrecedence', 'eco', 'external', 'fixed', 'forcedLastFromSchedule', - 'frostprotection', 'holiday', 'holidayAtHome', 'manual', 'normal', 'normalCooling', + for program in ['comfort', 'comfortCooling', 'comfortCoolingEnergySaving', 'comfortEnergySaving', + 'comfortHeating', 'dhwPrecedence', 'eco', 'external', 'fixed', 'forcedLastFromSchedule', + 'frostprotection', 'holiday', 'holidayAtHome', 'manual', 'normal', 'normalCooling', 'normalCoolingEnergySaving', 'normalEnergySaving', 'normalHeating', 'reduced', 'reducedCooling', 'reducedCoolingEnergySaving', 'reducedEnergySaving', 'reducedHeating', 'standby', 'summerEco']: with suppress(PyViCareNotSupportedFeatureError): diff --git a/PyViCare/PyViCareOAuthManager.py b/PyViCare/PyViCareOAuthManager.py index eab9b3ab..276346a0 100644 --- a/PyViCare/PyViCareOAuthManager.py +++ b/PyViCare/PyViCareOAuthManager.py @@ -96,7 +96,7 @@ def __serialize_token(self, oauth, token_file): with open(token_file, mode='wb') as binary_file: pickle.dump(oauth, binary_file) - logger.info("Token serialized to %s" % token_file) + logger.info(f"Token serialized to {token_file}") def __deserialize_token(self, token_file): if token_file is None or not os.path.isfile(token_file): diff --git a/PyViCare/PyViCareService.py b/PyViCare/PyViCareService.py index 259deeee..f79a9e50 100644 --- a/PyViCare/PyViCareService.py +++ b/PyViCare/PyViCareService.py @@ -28,8 +28,8 @@ def buildSetPropertyUrl(accessor, property_name, action): class ViCareDeviceAccessor: - def __init__(self, id: int, serial: str, device_id: str) -> None: - self.id = id + def __init__(self, _id: int, serial: str, device_id: str) -> None: + self.id = _id self.serial = serial self.device_id = device_id diff --git a/PyViCare/PyViCareVentilationDevice.py b/PyViCare/PyViCareVentilationDevice.py index 11d307be..c780f3d1 100644 --- a/PyViCare/PyViCareVentilationDevice.py +++ b/PyViCare/PyViCareVentilationDevice.py @@ -60,7 +60,7 @@ def getActiveProgram(self): json representation of the answer """ def activateProgram(self, program): - return self.service.setProperty("ventilation.operating.programs.{program}", "activate", {}) + return self.service.setProperty(f"ventilation.operating.programs.{program}", "activate", {}) """ Deactivate a program Parameters diff --git a/tests/test_VitoairFs300E.py b/tests/test_VitoairFs300E.py index 8e3a29db..1dcfcbbf 100644 --- a/tests/test_VitoairFs300E.py +++ b/tests/test_VitoairFs300E.py @@ -1,6 +1,5 @@ import unittest -from PyViCare.PyViCareUtils import PyViCareNotSupportedFeatureError from PyViCare.PyViCareVentilationDevice import VentilationDevice from tests.ViCareServiceMock import ViCareServiceMock diff --git a/tests/test_Vitocal200.py b/tests/test_Vitocal200.py index ad04e7fa..2bf37d46 100644 --- a/tests/test_Vitocal200.py +++ b/tests/test_Vitocal200.py @@ -102,7 +102,7 @@ def test_getActiveProgramMinTemperature(self): def test_getActiveProgramMaxTemperature(self): self.assertEqual(self.device.getCircuit(0).getActiveProgramMaxTemperature(), 30) - def test_getActiveProgramMaxTemperature(self): + def test_getActiveProgramStepping(self): self.assertEqual(self.device.getCircuit(0).getActiveProgramStepping(), 1) def test_getNormalProgramMinTemperature(self):