Add test for default values

Check that if no initial value is set, state returns 1970-01-01 at 00:00
This commit is contained in:
Tsvi Mostovicz
2019-03-11 12:16:29 +02:00
parent 3d0a04958b
commit e7bcddc7df

View File

@@ -199,6 +199,36 @@ def test_restore_state(hass):
assert state_bogus.state == str(initial) assert state_bogus.state == str(initial)
@asyncio.coroutine
def test_default_value(hass):
"""Test default value if none has been set via inital or restore state."""
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'test_time': {
'has_time': True,
'has_date': False
},
'test_date': {
'has_time': False,
'has_date': True
},
'test_datetime': {
'has_time': True,
'has_date': True
},
}})
dt_obj = datetime.datetime(1970, 1, 1, 0, 0)
state_time = hass.states.get('input_datetime.test_time')
assert state_time.state == str(dt_obj.time())
state_date = hass.states.get('input_datetime.test_date')
assert state_date.state == str(dt_obj.date())
state_datetime = hass.states.get('input_datetime.test_datetime')
assert state_datetime.state == str(dt_obj)
async def test_input_datetime_context(hass, hass_admin_user): async def test_input_datetime_context(hass, hass_admin_user):
"""Test that input_datetime context works.""" """Test that input_datetime context works."""
assert await async_setup_component(hass, 'input_datetime', { assert await async_setup_component(hass, 'input_datetime', {