diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70e5f20f6..45d6236f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: args: - --safe - --quiet - files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$ + files: ^((custom_components|script|tests)/.+)?[^/]+\.py$ - repo: https://github.com/codespell-project/codespell rev: v1.16.0 hooks: diff --git a/custom_components/waste_collection_schedule/package/scraper.py b/custom_components/waste_collection_schedule/package/scraper.py index d2b5df939..d77455362 100644 --- a/custom_components/waste_collection_schedule/package/scraper.py +++ b/custom_components/waste_collection_schedule/package/scraper.py @@ -48,7 +48,7 @@ def __repr__(self): return f"Customize{{name={self.name}, alias={self.alias}, show={self.show}, icon={self.icon}, picture={self.picture}}}" -def filter_function(entry: CollectionAppointment, customize:Dict[str,Customize]): +def filter_function(entry: CollectionAppointment, customize: Dict[str, Customize]): c = customize.get(entry.type) if c is None: return True @@ -56,7 +56,7 @@ def filter_function(entry: CollectionAppointment, customize:Dict[str,Customize]) return c.show -def customize_function(entry: CollectionAppointment, customize:Dict[str,Customize]): +def customize_function(entry: CollectionAppointment, customize: Dict[str, Customize]): c = customize.get(entry.type) if c is not None: if c.alias is not None: @@ -69,9 +69,9 @@ def customize_function(entry: CollectionAppointment, customize:Dict[str,Customiz class Scraper: - def __init__(self, source: str, customize:Dict[str,Customize]): + def __init__(self, source: str, customize: Dict[str, Customize]): self._source = source - self._entries:List[CollectionAppointment] = [] + self._entries: List[CollectionAppointment] = [] self._refreshtime = None self._customize = customize # dict of class Customize @@ -180,7 +180,7 @@ def _filter( return entries @staticmethod - def create(source_name: str, dir_offset, customize:Dict[str,Customize], kwargs): + def create(source_name: str, dir_offset, customize: Dict[str, Customize], kwargs): # load source module # for home-assistant, use the last 3 folders, e.g. custom_component/wave_collection_schedule/package @@ -194,7 +194,7 @@ def create(source_name: str, dir_offset, customize:Dict[str,Customize], kwargs): return # create source - source = source_module.Source(**kwargs) # type: ignore + source = source_module.Source(**kwargs) # type: ignore # create scraper g = Scraper(source, customize) diff --git a/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py b/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py index b384ebfce..748bf8801 100644 --- a/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py +++ b/custom_components/waste_collection_schedule/package/service/AbfallnaviDe.py @@ -26,6 +26,7 @@ "wml2": "EGW Westmünsterland", } + class AbfallnaviDe: def __init__(self, service_domain): self._service_domain = service_domain @@ -135,7 +136,6 @@ def get_dates(self, city, street, house_number=None): else: return self.get_dates_by_street_id(street_id) - def _find_in_inverted_dict(self, mydict, value): inverted_dict = dict(map(reversed, mydict.items())) return inverted_dict.get(value) @@ -151,5 +151,6 @@ def main(): roe = AbfallnaviDe("roe") print(roe.get_dates("Roetgen", "Am Sportplatz", "2")) + if __name__ == "__main__": main() 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 19372817c..186ff307f 100644 --- a/custom_components/waste_collection_schedule/package/source/abfall_io.py +++ b/custom_components/waste_collection_schedule/package/source/abfall_io.py @@ -8,23 +8,20 @@ DESCRIPTION = "Source for AbfallPlus.de based services. Service is hosted on abfall.io" URL = "https://www.abfallplus.de" TEST_CASES = { - "Waldenbuch": - { + "Waldenbuch": { "key": "8215c62763967916979e0e8566b6172e", "f_id_kommune": 2999, "f_id_strasse": 1087, # "f_abfallarten": [50, 53, 31, 299, 328, 325] }, - "Landshut": - { + "Landshut": { "key": "bd0c2d0177a0849a905cded5cb734a6f", "f_id_kommune": 2655, "f_id_bezirk": 2655, "f_id_strasse": 763, # "f_abfallarten": [31, 17, 19, 218] }, - "Schoenmackers": - { + "Schoenmackers": { "key": "e5543a3e190cb8d91c645660ad60965f", "f_id_kommune": 3682, "f_id_strasse": "3682adenauerplatz", diff --git a/custom_components/waste_collection_schedule/package/source/abfall_kreis_tuebingen_de.py b/custom_components/waste_collection_schedule/package/source/abfall_kreis_tuebingen_de.py index 6a3447c7f..3618af34e 100644 --- a/custom_components/waste_collection_schedule/package/source/abfall_kreis_tuebingen_de.py +++ b/custom_components/waste_collection_schedule/package/source/abfall_kreis_tuebingen_de.py @@ -7,14 +7,7 @@ DESCRIPTION = "Source for Abfall Landkreis Tuebingen" URL = "https://www.abfall-kreis-tuebingen.de" -TEST_CASES = { - "Dettenhausen": - { - "ort": 3, - "dropzone": 525, - "ics_with_drop": False - } -} +TEST_CASES = {"Dettenhausen": {"ort": 3, "dropzone": 525, "ics_with_drop": False}} class Source: 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 ba358e05d..58e268712 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 @@ -7,38 +7,38 @@ DESCRIPTION = "Source for Abfallwirtschaft Zollernalbkreis based services" URL = "https://www.abfallkalender-zak.de" -TEST_CASES ={ - "Ebingen": - { +TEST_CASES = { + "Ebingen": { "city": "2,3,4", "street": "3", - "types": ["restmuell", - "gelbersack", - "papiertonne", - "biomuell", - "gruenabfall", - "schadstoffsammlung", - "altpapiersammlung", - "schrottsammlung", - "weihnachtsbaeume", - "elektrosammlung" - ] + "types": [ + "restmuell", + "gelbersack", + "papiertonne", + "biomuell", + "gruenabfall", + "schadstoffsammlung", + "altpapiersammlung", + "schrottsammlung", + "weihnachtsbaeume", + "elektrosammlung", + ], }, - "Erlaheim": - { + "Erlaheim": { "city": "79", "street": "", - "types": ["restmuell", - "gelbersack", - "papiertonne", - "biomuell", - "gruenabfall", - "schadstoffsammlung", - "altpapiersammlung", - "schrottsammlung", - "weihnachtsbaeume", - "elektrosammlung" - ] + "types": [ + "restmuell", + "gelbersack", + "papiertonne", + "biomuell", + "gruenabfall", + "schadstoffsammlung", + "altpapiersammlung", + "schrottsammlung", + "weihnachtsbaeume", + "elektrosammlung", + ], }, } @@ -57,7 +57,9 @@ def fetch(self): # also get data for next year if we are already in december try: entries.extend( - self.fetch_year((now.year + 1), self._city, self._street, self._types) + self.fetch_year( + (now.year + 1), self._city, self._street, self._types + ) ) except Exception: # ignore if fetch for next year fails @@ -74,10 +76,7 @@ def fetch_year(self, year, city, street, types): } # get ics file - r = requests.get( - f"https://www.abfallkalender-zak.de", - params=args, - ) + r = requests.get(f"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/abfallnavi_de.py b/custom_components/waste_collection_schedule/package/source/abfallnavi_de.py index 414d63177..7db373108 100644 --- a/custom_components/waste_collection_schedule/package/source/abfallnavi_de.py +++ b/custom_components/waste_collection_schedule/package/source/abfallnavi_de.py @@ -4,25 +4,22 @@ DESCRIPTION = "Source for AbfallNavi (= regioit.de) based services" URL = "https://www.regioit.de" TEST_CASES = { - "Aachen, Abteiplatz 7": - { + "Aachen, Abteiplatz 7": { "service": "aachen", - "ort": "Aachen", - "strasse": "Abteiplatz", - "hausnummer": "7" + "ort": "Aachen", + "strasse": "Abteiplatz", + "hausnummer": "7", }, - "Lindlar, Aggerweg": - { + "Lindlar, Aggerweg": { "service": "lindlar", "ort": "Lindlar", - "strasse": "Aggerweg" + "strasse": "Aggerweg", }, - "Roetgen, Am Sportplatz 2": - { - "service": "roe", - "ort": "Roetgen", - "strasse": "Am Sportplatz", - "hausnummer": "2" + "Roetgen, Am Sportplatz 2": { + "service": "roe", + "ort": "Roetgen", + "strasse": "Am Sportplatz", + "hausnummer": "2", }, } 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 c4df0da7e..9410cb36b 100644 --- a/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py +++ b/custom_components/waste_collection_schedule/package/source/awbkoeln_de.py @@ -7,13 +7,7 @@ DESCRIPTION = "Source for AWB Koeln." URL = "https://www.awbkoeln.de" -TEST_CASES = { - "Koeln": - { - "street_code": 2, - "building_number": 50 - } -} +TEST_CASES = {"Koeln": {"street_code": 2, "building_number": 50}} class Source: 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 cd09e52de..4b680c051 100644 --- a/custom_components/waste_collection_schedule/package/source/bsr_de.py +++ b/custom_components/waste_collection_schedule/package/source/bsr_de.py @@ -9,13 +9,11 @@ DESCRIPTION = "Source for Berliner Stadtreinigungsbetriebe" URL = "bsr.de" TEST_CASES = { - "Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)": - { + "Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)": { "abf_strasse": "Bahnhofstr., 12159 Berlin (Tempelhof-Schöneberg)", "abf_hausnr": 1, }, - "Am Ried, 13467 Berlin (Reinickendorf)": - { + "Am Ried, 13467 Berlin (Reinickendorf)": { "abf_strasse": "Am Ried, 13467 Berlin (Reinickendorf)", "abf_hausnr": "11G", }, @@ -62,9 +60,9 @@ def fetch(self): "abf_config_biogut": "on", "abf_config_wertstoffe": "on", "abf_config_laubtonne": "on", - #"abf_selectmonth": "5 2020", - #"abf_datepicker": "28.04.2020", - #"listitems":7, + # "abf_selectmonth": "5 2020", + # "abf_datepicker": "28.04.2020", + # "listitems":7, } r = requests.post( "https://www.bsr.de/abfuhrkalender_ajax.php?script=dynamic_kalender_ajax", @@ -82,8 +80,8 @@ def fetch(self): "abf_config_biogut": "on", "abf_config_wertstoffe": "on", "abf_config_laubtonne": "on", - #"abf_selectmonth": "5 2020", - #"listitems":7, + # "abf_selectmonth": "5 2020", + # "listitems":7, } # create url using private url encoding diff --git a/custom_components/waste_collection_schedule/package/source/example.py b/custom_components/waste_collection_schedule/package/source/example.py index 0e8444bda..ec562ecac 100644 --- a/custom_components/waste_collection_schedule/package/source/example.py +++ b/custom_components/waste_collection_schedule/package/source/example.py @@ -5,7 +5,7 @@ DESCRIPTION = "Example scraper" URL = "" -TEST_CASES:Dict[str, Dict[str, str]] = {} +TEST_CASES: Dict[str, Dict[str, str]] = {} class Source: diff --git a/custom_components/waste_collection_schedule/package/source/ics.py b/custom_components/waste_collection_schedule/package/source/ics.py index 91ef2cd4e..6f481f3aa 100644 --- a/custom_components/waste_collection_schedule/package/source/ics.py +++ b/custom_components/waste_collection_schedule/package/source/ics.py @@ -9,24 +9,19 @@ DESCRIPTION = "Source for ICS based services" URL = "" TEST_CASES = { - "Dortmund, Dudenstr. 5": - { + "Dortmund, Dudenstr. 5": { "url": "https://www.edg.de/ical/kalender.ics?Strasse=Dudenstr.&Hausnummer=5&Erinnerung=-1&Abfallart=1,2,3,4" }, - "Leipzig, Sandgrubenweg 27": - { + "Leipzig, Sandgrubenweg 27": { "url": "https://www.stadtreinigung-leipzig.de/leistungen/abfallentsorgung/abfallkalender-entsorgungstermine.html&ical=true&loc=Sandgrubenweg%20%2027&lid=x38296" }, - "Ludwigsburg": - { + "Ludwigsburg": { "url": "https://www.avl-ludwigsburg.de/fileadmin/Files/Abfallkalender/ICS/Privat/Privat_{%Y}_Ossweil.ics" }, - "Esslingen, Bahnhof": - { + "Esslingen, Bahnhof": { "url": "https://api.abfall.io/?kh=DaA02103019b46345f1998698563DaAd&t=ics&s=1a862df26f6943997cef90233877a4fe" }, - "Test File": - { + "Test File": { # Path is used here to allow to call the Source from any location. # This is not required in a yaml configuration! "file": Path(__file__) @@ -34,8 +29,7 @@ .parents[1] .joinpath("test/test.ics") }, - "Test File (recurring)": - { + "Test File (recurring)": { # Path is used here to allow to call the Source from any location. # This is not required in a yaml configuration! "file": Path(__file__) @@ -43,12 +37,10 @@ .parents[1] .joinpath("test/recurring.ics") }, - "München, Bahnstr. 11": - { + "München, Bahnstr. 11": { "url": "https://www.awm-muenchen.de/index/abfuhrkalender.html?tx_awmabfuhrkalender_pi1%5Bsection%5D=ics&tx_awmabfuhrkalender_pi1%5Bstandplatzwahl%5D=true&tx_awmabfuhrkalender_pi1%5Bsinglestandplatz%5D=false&tx_awmabfuhrkalender_pi1%5Bstrasse%5D=Bahnstr.&tx_awmabfuhrkalender_pi1%5Bhausnummer%5D=11&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Brestmuell%5D=70024507&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Bpapier%5D=70024507&tx_awmabfuhrkalender_pi1%5Bstellplatz%5D%5Bbio%5D=70024507&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BR%5D=001%3BU&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BP%5D=1%2F2%3BG&tx_awmabfuhrkalender_pi1%5Bleerungszyklus%5D%5BB%5D=1%2F2%3BU&tx_awmabfuhrkalender_pi1%5Byear%5D={%Y}" }, - "Buxtehude, Am Berg": - { + "Buxtehude, Am Berg": { "url": "https://abfall.landkreis-stade.de/api_v2/collection_dates/1/ort/10/strasse/90/hausnummern/1/abfallarten/R02-R04-B02-D04-D12-P04-R12-R14-W0-R22-R24-R31/kalender.ics" }, } diff --git a/custom_components/waste_collection_schedule/package/source/jumomind_de.py b/custom_components/waste_collection_schedule/package/source/jumomind_de.py index 3762ea307..ca570d8ff 100644 --- a/custom_components/waste_collection_schedule/package/source/jumomind_de.py +++ b/custom_components/waste_collection_schedule/package/source/jumomind_de.py @@ -8,20 +8,11 @@ DESCRIPTION = "Source for Jumomind.de based services." URL = "https://www.jumomind.de" TEST_CASES = { - "ZAW": - { - "service_id": "zaw", - "city_id": 106, - "area_id": 94 - }, - "Bad Homburg": - { - "service_id": "hom", - "city_id": 1, - "area_id": 461 - }, + "ZAW": {"service_id": "zaw", "city_id": 106, "area_id": 94}, + "Bad Homburg": {"service_id": "hom", "city_id": 1, "area_id": 461}, } + class Source: def __init__(self, service_id, city_id, area_id): self._service_id = service_id 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 e8a353336..594d1e69d 100644 --- a/custom_components/waste_collection_schedule/package/source/muellmax_de.py +++ b/custom_components/waste_collection_schedule/package/source/muellmax_de.py @@ -9,23 +9,17 @@ DESCRIPTION = "Source for Muellmax.de based services." URL = "https://www.muellmax.de" TEST_CASES = { - "Frankfurt, Achenbachstrasse 5": - { + "Frankfurt, Achenbachstrasse 5": { "service": "Fes", "mm_frm_str_sel": "Achenbachstraße", "mm_frm_hnr_sel": "60596;Sachsenhausen;5;", }, - "Rhein-Sieg-Kreis, Alfter": - { + "Rhein-Sieg-Kreis, Alfter": { "service": "Rsa", "mm_frm_ort_sel": "Alfter", "mm_frm_str_sel": "Ahrweg (105-Ende/94-Ende)", }, - "Münster, Achatiusweg": - { - "service": "Awm", - "mm_frm_str_sel": "Achatiusweg" - }, + "Münster, Achatiusweg": {"service": "Awm", "mm_frm_str_sel": "Achatiusweg"}, } 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 63e37113f..f5229158c 100644 --- a/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py +++ b/custom_components/waste_collection_schedule/package/source/stadtreinigung_hamburg.py @@ -6,11 +6,7 @@ DESCRIPTION = "Source for Stadtreinigung.Hamburg based services." URL = "https://www.stadtreinigung.hamburg" TEST_CASES = { - "Hamburg": - { - "asId": 5087, - "hnId": 113084 - }, + "Hamburg": {"asId": 5087, "hnId": 113084}, } diff --git a/custom_components/waste_collection_schedule/package/source/stuttgart_de.py b/custom_components/waste_collection_schedule/package/source/stuttgart_de.py index 88e363b02..bd67f6f1a 100644 --- a/custom_components/waste_collection_schedule/package/source/stuttgart_de.py +++ b/custom_components/waste_collection_schedule/package/source/stuttgart_de.py @@ -7,13 +7,7 @@ DESCRIPTION = "Source for stuttgart.de based services." URL = "https://service.stuttgart.de/lhs-services/aws/" -TEST_CASES = { - "Im Steinengarten 7": - { - "street": "Im Steinengarten", - "streetnr": 7 - } -} +TEST_CASES = {"Im Steinengarten 7": {"street": "Im Steinengarten", "streetnr": 7}} # Parser for HTML checkbox 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 bb7387781..4150533d6 100755 --- a/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py +++ b/custom_components/waste_collection_schedule/package/wizard/abfallnavi_de.py @@ -7,8 +7,10 @@ import inquirer import requests -PACKAGE_PARENT = '..' -SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))) +PACKAGE_PARENT = ".." +SCRIPT_DIR = os.path.dirname( + os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))) +) sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT))) from service.AbfallnaviDe import SERVICE_DOMAINS, AbfallnaviDe # isort:skip @@ -46,7 +48,7 @@ def main(): inquirer.List( "city_id", choices=convert_dict_to_array(cities), - message="Select municipality [Kommune/Ort]" + message="Select municipality [Kommune/Ort]", ) ] city_id = inquirer.prompt(questions)["city_id"] @@ -56,9 +58,7 @@ def main(): streets = api.get_streets(city_id) questions = [ inquirer.List( - "street_id", - choices=convert_dict_to_array(streets), - message="Select street" + "street_id", choices=convert_dict_to_array(streets), message="Select street" ) ] street_id = inquirer.prompt(questions)["street_id"]