diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45d6236f..3ca2dc42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,10 +25,12 @@ repos: rev: 3.8.1 hooks: - id: flake8 + args: + - --ignore=D100,D101,D102,D103,D104,D105,D107,E501,W503 additional_dependencies: - flake8-docstrings==1.5.0 - pydocstyle==5.0.2 - files: ^(homeassistant|script|tests)/.+\.py$ + files: ^(custom_components|script|tests)/.+\.py$ - repo: https://github.com/PyCQA/bandit rev: 1.6.2 hooks: diff --git a/custom_components/waste_collection_schedule/__init__.py b/custom_components/waste_collection_schedule/__init__.py index 6c585f6d..c4c51ce8 100644 --- a/custom_components/waste_collection_schedule/__init__.py +++ b/custom_components/waste_collection_schedule/__init__.py @@ -1,5 +1,4 @@ """Waste Collection Schedule Component.""" -import asyncio import logging from random import randrange @@ -68,7 +67,6 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: dict): """Set up the component. config contains data from configuration.yaml.""" - # create empty api object as singleton api = WasteCollectionApi( hass, diff --git a/custom_components/waste_collection_schedule/package/scraper.py b/custom_components/waste_collection_schedule/package/scraper.py index d7745536..3a5e4a89 100644 --- a/custom_components/waste_collection_schedule/package/scraper.py +++ b/custom_components/waste_collection_schedule/package/scraper.py @@ -1,12 +1,10 @@ #!/usr/bin/python3 -import collections import datetime import importlib import itertools import logging import os -from itertools import islice from typing import Dict, List from .helpers import CollectionAppointment, CollectionAppointmentGroup @@ -113,7 +111,7 @@ class Scraper: def get_upcoming(self, count=None, leadtime=None, types=None, include_today=False): """Return list of all entries, limited by count and/or leadtime. - + Keyword arguments: count -- limits the number of returned entries (default=10) leadtime -- limits the timespan in days of returned entries (default=7, 0 = today) diff --git a/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py b/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py index 748bf880..c34796dc 100644 --- a/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py +++ b/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py @@ -115,7 +115,7 @@ class AbfallnaviDe: return self._get_dates("hausnummern", house_number_id, waste_types=None) def get_dates(self, city, street, house_number=None): - """Convenient function to get dates by strings only.""" + """Get dates by strings only for convenience.""" # find city_id city_id = self.get_city_id(city) if city_id is None: diff --git a/custom_components/waste_collection_schedule/package/source/abfall_io.py b/custom_components/waste_collection_schedule/package/source/abfall_io.py index 186ff307..9ad5ee38 100644 --- a/custom_components/waste_collection_schedule/package/source/abfall_io.py +++ b/custom_components/waste_collection_schedule/package/source/abfall_io.py @@ -74,7 +74,7 @@ class Source: # get csv file r = requests.post( - f"https://api.abfall.io", params=params, data=args, headers=HEADERS + "https://api.abfall.io", params=params, data=args, headers=HEADERS ) # prepare csv reader diff --git a/custom_components/waste_collection_schedule/package/source/abfall_zollernalbkreis_de.py b/custom_components/waste_collection_schedule/package/source/abfall_zollernalbkreis_de.py index 58e26871..51741ed7 100644 --- a/custom_components/waste_collection_schedule/package/source/abfall_zollernalbkreis_de.py +++ b/custom_components/waste_collection_schedule/package/source/abfall_zollernalbkreis_de.py @@ -1,4 +1,4 @@ -from datetime import date, datetime +from datetime import datetime import requests @@ -76,7 +76,7 @@ class Source: } # get ics file - r = requests.get(f"https://www.abfallkalender-zak.de", params=args,) + r = requests.get("https://www.abfallkalender-zak.de", params=args,) # parse ics file dates = self._ics.convert(r.text) diff --git a/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py b/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py index 9410cb36..0e6a8393 100644 --- a/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py +++ b/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py @@ -28,7 +28,7 @@ class Source: args["end_month"] = now.month # get json file - r = requests.get(f"https://www.awbkoeln.de/api/calendar", params=args) + r = requests.get("https://www.awbkoeln.de/api/calendar", params=args) data = json.loads(r.text) diff --git a/custom_components/waste_collection_schedule/package/source/bsr_de.py b/custom_components/waste_collection_schedule/package/source/bsr_de.py index 4b680c05..877df08d 100644 --- a/custom_components/waste_collection_schedule/package/source/bsr_de.py +++ b/custom_components/waste_collection_schedule/package/source/bsr_de.py @@ -1,4 +1,3 @@ -import datetime import urllib.parse import requests diff --git a/custom_components/waste_collection_schedule/package/source/muellmax_de.py b/custom_components/waste_collection_schedule/package/source/muellmax_de.py index 594d1e69..f1f3fdc7 100644 --- a/custom_components/waste_collection_schedule/package/source/muellmax_de.py +++ b/custom_components/waste_collection_schedule/package/source/muellmax_de.py @@ -1,4 +1,3 @@ -import datetime from html.parser import HTMLParser import requests diff --git a/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py b/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py index f5229158..da73e3de 100644 --- a/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py +++ b/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py @@ -21,7 +21,7 @@ class Source: # get ics file r = requests.post( - f"https://www.stadtreinigung.hamburg/privatkunden/abfuhrkalender/Abfuhrtermin.ics", + "https://www.stadtreinigung.hamburg/privatkunden/abfuhrkalender/Abfuhrtermin.ics", data=args, ) diff --git a/custom_components/waste_collection_schedule/package/wizard/abfall_io.py b/custom_components/waste_collection_schedule/package/wizard/abfall_io.py index 1583306e..6749d8a9 100755 --- a/custom_components/waste_collection_schedule/package/wizard/abfall_io.py +++ b/custom_components/waste_collection_schedule/package/wizard/abfall_io.py @@ -8,8 +8,10 @@ import requests MODUS_KEY = "d6c5855a62cf32a4dadbc2831f0f295f" HEADERS = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"} -# Parser for HTML option list + class OptionParser(HTMLParser): + """Parser for HTML option list.""" + def __init__(self): super().__init__() self._within_option = False @@ -76,7 +78,7 @@ def select_and_query(data, answers): args = {"key": answers["key"], "modus": MODUS_KEY, "waction": parser.waction} r = requests.post( - f"https://api.abfall.io", params=args, data=answers, headers=HEADERS + "https://api.abfall.io", params=args, data=answers, headers=HEADERS ) return r.text @@ -104,7 +106,7 @@ def main(): # prompt for first level args = {"key": answers["key"], "modus": MODUS_KEY, "waction": "init"} - r = requests.get(f"https://api.abfall.io", params=args, headers=HEADERS) + r = requests.get("https://api.abfall.io", params=args, headers=HEADERS) data = r.text while True: diff --git a/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py b/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py index 4150533d..638da415 100755 --- a/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py +++ b/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py @@ -1,11 +1,9 @@ #!/usr/bin/python3 -import json import os import sys import inquirer -import requests PACKAGE_PARENT = ".." SCRIPT_DIR = os.path.dirname( @@ -40,8 +38,6 @@ def main(): # create service api = AbfallnaviDe(service_id) - SERVICE_URL = f"https://{service_id}-abfallapp.regioit.de/abfall-app-{service_id}" - # select city cities = api.get_cities() questions = [ diff --git a/custom_components/waste_collection_schedule/package/wizard/awbkoeln_de.py b/custom_components/waste_collection_schedule/package/wizard/awbkoeln_de.py index cb1c8125..7ab572e6 100755 --- a/custom_components/waste_collection_schedule/package/wizard/awbkoeln_de.py +++ b/custom_components/waste_collection_schedule/package/wizard/awbkoeln_de.py @@ -17,7 +17,7 @@ def main(): args = answers args["form"] = "json" - r = requests.get(f"https://www.awbkoeln.de/api/streets", params=args) + r = requests.get("https://www.awbkoeln.de/api/streets", params=args) # "data":[{"street_name":"Bahnhofplatz","building_number":"5","building_number_plain":"5","building_number_addition":"","street_code":"4270", # "district":"Gremberghoven","zipcode":"51149","district_code":"4","area_code":"7","user_street_name":"Bahnhofplatz","user_building_number":"1"} diff --git a/custom_components/waste_collection_schedule/package/wizard/muellmax_de.py b/custom_components/waste_collection_schedule/package/wizard/muellmax_de.py index 725fe71a..aba5f721 100755 --- a/custom_components/waste_collection_schedule/package/wizard/muellmax_de.py +++ b/custom_components/waste_collection_schedule/package/wizard/muellmax_de.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import json from html.parser import HTMLParser import inquirer diff --git a/custom_components/waste_collection_schedule/package/wizard/stadtreinigung_hamburg.py b/custom_components/waste_collection_schedule/package/wizard/stadtreinigung_hamburg.py index 183d1f21..262736d1 100755 --- a/custom_components/waste_collection_schedule/package/wizard/stadtreinigung_hamburg.py +++ b/custom_components/waste_collection_schedule/package/wizard/stadtreinigung_hamburg.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import json from html.parser import HTMLParser import inquirer diff --git a/custom_components/waste_collection_schedule/package/wizard/stuttgart_de.py b/custom_components/waste_collection_schedule/package/wizard/stuttgart_de.py index 072cc741..7d478331 100755 --- a/custom_components/waste_collection_schedule/package/wizard/stuttgart_de.py +++ b/custom_components/waste_collection_schedule/package/wizard/stuttgart_de.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import json -from html.parser import HTMLParser import inquirer import requests diff --git a/custom_components/waste_collection_schedule/sensor.py b/custom_components/waste_collection_schedule/sensor.py index 3384d5e4..76b60778 100644 --- a/custom_components/waste_collection_schedule/sensor.py +++ b/custom_components/waste_collection_schedule/sensor.py @@ -24,8 +24,10 @@ CONF_LEADTIME = "leadtime" CONF_DATE_TEMPLATE = "date_template" CONF_APPOINTMENT_TYPES = "types" -# values for CONF_DETAILS_FORMAT + class DetailsFormat(Enum): + """Values for CONF_DETAILS_FORMAT.""" + upcoming = "upcoming" # list of " " appointment_types = "appointment_types" # list of " " generic = "generic" # all values in separate attributes @@ -135,7 +137,7 @@ class ScheduleSensor(Entity): return self._attributes async def async_added_to_hass(self): - """Called if entity has been added to hass.""" + """Entities have been added to hass.""" self._update_sensor() @property diff --git a/custom_components/waste_collection_schedule/test_sources.py b/custom_components/waste_collection_schedule/test_sources.py index 99befa37..c491467a 100755 --- a/custom_components/waste_collection_schedule/test_sources.py +++ b/custom_components/waste_collection_schedule/test_sources.py @@ -2,7 +2,6 @@ import argparse import importlib -import os import pathlib