mirror of
https://github.com/home-assistant/core.git
synced 2026-09-28 02:18:10 -04:00
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:
committed by
Paulus Schoutsen
parent
8df5de2bb8
commit
7ff1ded0b5
@@ -38,12 +38,27 @@ class TestWorkdaySetup(object):
|
||||
},
|
||||
}
|
||||
|
||||
self.config_state = {
|
||||
'binary_sensor': {
|
||||
'platform': 'workday',
|
||||
'country': 'US',
|
||||
'province': 'CA'
|
||||
},
|
||||
}
|
||||
|
||||
self.config_nostate = {
|
||||
'binary_sensor': {
|
||||
'platform': 'workday',
|
||||
'country': 'US',
|
||||
},
|
||||
}
|
||||
|
||||
self.config_includeholiday = {
|
||||
'binary_sensor': {
|
||||
'platform': 'workday',
|
||||
'country': 'DE',
|
||||
'province': 'BW',
|
||||
'workdays': ['holiday', 'mon', 'tue', 'wed', 'thu', 'fri'],
|
||||
'workdays': ['holiday'],
|
||||
'excludes': ['sat', 'sun']
|
||||
},
|
||||
}
|
||||
@@ -122,6 +137,34 @@ class TestWorkdaySetup(object):
|
||||
entity = self.hass.states.get('binary_sensor.workday_sensor')
|
||||
assert entity.state == 'on'
|
||||
|
||||
# Freeze time to a public holiday in state CA
|
||||
@freeze_time("Mar 31st, 2017")
|
||||
def test_public_holiday_state(self):
|
||||
"""Test if public holidays are reported correctly."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config_state)
|
||||
|
||||
assert self.hass.states.get('binary_sensor.workday_sensor') is not None
|
||||
|
||||
self.hass.start()
|
||||
|
||||
entity = self.hass.states.get('binary_sensor.workday_sensor')
|
||||
assert entity.state == 'off'
|
||||
|
||||
# Freeze time to a public holiday in state CA
|
||||
@freeze_time("Mar 31st, 2017")
|
||||
def test_public_holiday_nostate(self):
|
||||
"""Test if public holidays are reported correctly."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config_nostate)
|
||||
|
||||
assert self.hass.states.get('binary_sensor.workday_sensor') is not None
|
||||
|
||||
self.hass.start()
|
||||
|
||||
entity = self.hass.states.get('binary_sensor.workday_sensor')
|
||||
assert entity.state == 'on'
|
||||
|
||||
def test_setup_component_invalidprovince(self):
|
||||
"""Setup workday component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
|
||||
Reference in New Issue
Block a user