1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Workday sensor offset (#8824)

* Add support for offset for the workday sensor

* Update tests for workday sensor

* Changed from 'offset' to 'days_offset'

* Attributes bugfix (dictionary key variable repeated with different values)
This commit is contained in:
Ståle Semb Hauknes
2017-08-21 13:24:30 +02:00
committed by Pascal Vizeli
parent f7daefd7a5
commit 7c380588a0
2 changed files with 92 additions and 8 deletions

View File

@@ -63,6 +63,30 @@ class TestWorkdaySetup(object):
},
}
self.config_tomorrow = {
'binary_sensor': {
'platform': 'workday',
'country': 'DE',
'days_offset': 1
},
}
self.config_day_after_tomorrow = {
'binary_sensor': {
'platform': 'workday',
'country': 'DE',
'days_offset': 2
},
}
self.config_yesterday = {
'binary_sensor': {
'platform': 'workday',
'country': 'DE',
'days_offset': -1
},
}
def teardown_method(self):
"""Stop everything that was started."""
self.hass.stop()
@@ -188,6 +212,51 @@ class TestWorkdaySetup(object):
entity = self.hass.states.get('binary_sensor.workday_sensor')
assert entity.state == 'on'
# Freeze time to a saturday to test offset
@freeze_time("Aug 5th, 2017")
def test_tomorrow(self):
"""Test if tomorrow are reported correctly."""
with assert_setup_component(1, 'binary_sensor'):
setup_component(self.hass, 'binary_sensor',
self.config_tomorrow)
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 saturday to test offset
@freeze_time("Aug 5th, 2017")
def test_day_after_tomorrow(self):
"""Test if the day after tomorrow are reported correctly."""
with assert_setup_component(1, 'binary_sensor'):
setup_component(self.hass, 'binary_sensor',
self.config_day_after_tomorrow)
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'
# Freeze time to a saturday to test offset
@freeze_time("Aug 5th, 2017")
def test_yesterday(self):
"""Test if yesterday are reported correctly."""
with assert_setup_component(1, 'binary_sensor'):
setup_component(self.hass, 'binary_sensor',
self.config_yesterday)
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_day_to_string(self):
"""Test if day_to_string is behaving correctly."""
assert day_to_string(0) == 'mon'