From a57a85454cea8fb3677251b027a19b5aa5377f37 Mon Sep 17 00:00:00 2001 From: bruxy70 Date: Mon, 27 Jan 2020 18:37:54 +0100 Subject: [PATCH 1/5] CountryHoliday parameters kwarg --- .gitignore | 1 + custom_components/garbage_collection/config_flow.py | 7 ++++--- custom_components/garbage_collection/sensor.py | 9 +++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index da8d1e2..ef02ef8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/settings.json +.vscode/settings.json diff --git a/custom_components/garbage_collection/config_flow.py b/custom_components/garbage_collection/config_flow.py index e8813fd..7d6fa96 100644 --- a/custom_components/garbage_collection/config_flow.py +++ b/custom_components/garbage_collection/config_flow.py @@ -832,17 +832,18 @@ async def _show_final_form(self, user_input): ] = vol.In(COUNTRY_CODES) data_schema[ vol.Optional( - CONF_PROV, default=self.config_entry.options.get(CONF_PROV, ""), + CONF_PROV, default=self.config_entry.options.get(CONF_PROV, "") ) ] = str data_schema[ vol.Optional( - CONF_STATE, default=self.config_entry.options.get(CONF_STATE, ""), + CONF_STATE, default=self.config_entry.options.get(CONF_STATE, "") ) ] = str data_schema[ vol.Optional( - CONF_OBSERVED, default=self.config_entry.options.get(CONF_OBSERVED, True), + CONF_OBSERVED, + default=self.config_entry.options.get(CONF_OBSERVED, True), ) ] = bool return self.async_show_form( diff --git a/custom_components/garbage_collection/sensor.py b/custom_components/garbage_collection/sensor.py index aecfe04..751a74d 100644 --- a/custom_components/garbage_collection/sensor.py +++ b/custom_components/garbage_collection/sensor.py @@ -155,19 +155,16 @@ def __init__(self, hass, config): self.__name, prov, state, - observed + observed, ) kwargs = {"years": years} if state is not None and state != "": kwargs["state"] = state if prov is not None and prov != "": kwargs["prov"] = prov - if observed is not None: + if observed is not None and type(observed) == bool: kwargs["observed"] = observed - hol = holidays.CountryHoliday( - country_holidays, - **kwargs - ).items() + hol = holidays.CountryHoliday(country_holidays, **kwargs).items() try: for date, name in hol: if date >= today: From a202964fab3d822f2a9b57f0c7a4e901fc67055d Mon Sep 17 00:00:00 2001 From: bruxy70 <44951610+bruxy70@users.noreply.github.com> Date: Mon, 27 Jan 2020 19:05:45 +0100 Subject: [PATCH 2/5] Delete settings.json --- .vscode/settings.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 57c2933..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "python.linting.pycodestyleEnabled": false, - "python.linting.pylintEnabled": true, - "python.linting.enabled": true, - "python.pythonPath": "C:\\Users\\Vasek\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe" -} \ No newline at end of file From f75626953c3775078007cc2c00315320e5a8ffd0 Mon Sep 17 00:00:00 2001 From: bruxy70 <44951610+bruxy70@users.noreply.github.com> Date: Mon, 27 Jan 2020 19:15:10 +0100 Subject: [PATCH 3/5] Update .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index ef02ef8..c6f9a44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ - -.vscode/settings.json .vscode/settings.json From b9aa5424a211b9dc1c187987962bc818ea3c0c02 Mon Sep 17 00:00:00 2001 From: bruxy70 <44951610+bruxy70@users.noreply.github.com> Date: Mon, 27 Jan 2020 19:18:24 +0100 Subject: [PATCH 4/5] Update sensor.py --- custom_components/garbage_collection/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/garbage_collection/sensor.py b/custom_components/garbage_collection/sensor.py index 751a74d..501c0f6 100644 --- a/custom_components/garbage_collection/sensor.py +++ b/custom_components/garbage_collection/sensor.py @@ -162,7 +162,7 @@ def __init__(self, hass, config): kwargs["state"] = state if prov is not None and prov != "": kwargs["prov"] = prov - if observed is not None and type(observed) == bool: + if len(kwargs) > 1 and observed is not None and type(observed) == bool: kwargs["observed"] = observed hol = holidays.CountryHoliday(country_holidays, **kwargs).items() try: From 3e335f55262d533db1559e0f8420e5b179830f8c Mon Sep 17 00:00:00 2001 From: bruxy70 <44951610+bruxy70@users.noreply.github.com> Date: Mon, 27 Jan 2020 20:03:15 +0100 Subject: [PATCH 5/5] CountryHolidays minimal version --- custom_components/garbage_collection/manifest.json | 4 ++-- custom_components/garbage_collection/sensor.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/custom_components/garbage_collection/manifest.json b/custom_components/garbage_collection/manifest.json index 7354161..1eba3f1 100644 --- a/custom_components/garbage_collection/manifest.json +++ b/custom_components/garbage_collection/manifest.json @@ -9,8 +9,8 @@ ], "requirements": [ "datetime", - "integrationhelper", - "holidays", + "integrationhelper>=0.2.2", + "holidays>=0.10.1", "typing", "uuid", "voluptuous" diff --git a/custom_components/garbage_collection/sensor.py b/custom_components/garbage_collection/sensor.py index 501c0f6..4eac7d2 100644 --- a/custom_components/garbage_collection/sensor.py +++ b/custom_components/garbage_collection/sensor.py @@ -151,8 +151,9 @@ def __init__(self, hass, config): state = config.get(CONF_STATE) observed = config.get(CONF_OBSERVED, True) _LOGGER.debug( - "(%s) Country Holidays with parameters: prov: %s, state: %s, observed: %s", + "(%s) Country Holidays with parameters: country: %s, prov: %s, state: %s, observed: %s", self.__name, + country_holidays, prov, state, observed, @@ -162,7 +163,7 @@ def __init__(self, hass, config): kwargs["state"] = state if prov is not None and prov != "": kwargs["prov"] = prov - if len(kwargs) > 1 and observed is not None and type(observed) == bool: + if observed is not None and type(observed) == bool and observed == False: kwargs["observed"] = observed hol = holidays.CountryHoliday(country_holidays, **kwargs).items() try: