Skip to content

Commit

Permalink
Better handling of ContryHoliday parameers
Browse files Browse the repository at this point in the history
  • Loading branch information
bruxy70 committed Jan 27, 2020
1 parent a52f461 commit ef19e6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.vscode/settings.json
33 changes: 11 additions & 22 deletions custom_components/garbage_collection/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,17 @@ def __init__(self, hass, config):
state,
observed
)
if state is None or state == "":
if prov is None or prov == "":
hol = holidays.CountryHoliday(
country_holidays, years=years, observed=observed
).items()
else:
hol = holidays.CountryHoliday(
country_holidays, years=years, prov=prov, observed=observed
).items()
else:
if prov is None or prov == "":
hol = holidays.CountryHoliday(
country_holidays, years=years, state=state, observed=observed
).items()
else:
hol = holidays.CountryHoliday(
country_holidays,
years=years,
state=state,
prov=prov,
observed=observed
).items()
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:
kwargs["observed"] = observed
hol = holidays.CountryHoliday(
country_holidays,
**kwargs
).items()
try:
for date, name in hol:
if date >= today:
Expand Down

0 comments on commit ef19e6b

Please sign in to comment.