binary_sensor.workday: fix handling of states vs provinces (#7162)
* binary_sensor.workday: fix handling of states vs provinces * Add test cases for workday sensor with states * remove redundant assignment * Repair unit test to improve coverage Patch from Wolf-Bastian Pöttner * Fix handling of invalid states/provinces * fix indentation to satisfy pylint
This commit is contained in:
1 parent
8df5de2bb8
commit
7ff1ded0b5
2 files changed
+55
-7
No files matched your search
@@ -65,15 +65,20 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
obj_holidays = getattr(holidays, country)(years=year)
|
||||
|
||||
if province:
|
||||
if province not in obj_holidays.PROVINCES and \
|
||||
province not in obj_holidays.STATES:
|
||||
# 'state' and 'prov' are not interchangeable, so need to make
|
||||
# sure we use the right one
|
||||
if (hasattr(obj_holidays, "PROVINCES") and
|
||||
province in obj_holidays.PROVINCES):
|
||||
obj_holidays = getattr(holidays, country)(prov=province,
|
||||
years=year)
|
||||
elif (hasattr(obj_holidays, "STATES") and
|
||||
province in obj_holidays.STATES):
|
||||
obj_holidays = getattr(holidays, country)(state=province,
|
||||
years=year)
|
||||
else:
|
||||
_LOGGER.error("There is no province/state %s in country %s",
|
||||
province, country)
|
||||
return False
|
||||
else:
|
||||
year = datetime.datetime.now().year
|
||||
obj_holidays = getattr(holidays, country)(prov=province,
|
||||
years=year)
|
||||
|
||||
_LOGGER.debug("Found the following holidays for your configuration:")
|
||||
for date, name in sorted(obj_holidays.items()):
|
||||
|
||||
Reference in new issue
Block a user