mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix time functions would throw errors in python scripts (#11414)
* Fix time functions would throw errors in python scripts * Added unit test for time.strptime, change variable name to satisfy lint * Added docstring for time attribute wrapper method to satisfy lint * Fixed line too long lint problem
This commit is contained in:
parent
5c2cecde70
commit
939d1b5ff6
@ -202,4 +202,11 @@ class TimeWrapper:
|
|||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
"""Fetch an attribute from Time module."""
|
"""Fetch an attribute from Time module."""
|
||||||
return getattr(time, attr)
|
attribute = getattr(time, attr)
|
||||||
|
if callable(attribute):
|
||||||
|
def wrapper(*args, **kw):
|
||||||
|
"""Wrapper to return callable method if callable."""
|
||||||
|
return attribute(*args, **kw)
|
||||||
|
return wrapper
|
||||||
|
else:
|
||||||
|
return attribute
|
||||||
|
@ -236,6 +236,8 @@ def test_exposed_modules(hass, caplog):
|
|||||||
caplog.set_level(logging.ERROR)
|
caplog.set_level(logging.ERROR)
|
||||||
source = """
|
source = """
|
||||||
hass.states.set('module.time', time.strftime('%Y', time.gmtime(521276400)))
|
hass.states.set('module.time', time.strftime('%Y', time.gmtime(521276400)))
|
||||||
|
hass.states.set('module.time_strptime',
|
||||||
|
time.strftime('%H:%M', time.strptime('12:34', '%H:%M')))
|
||||||
hass.states.set('module.datetime',
|
hass.states.set('module.datetime',
|
||||||
datetime.timedelta(minutes=1).total_seconds())
|
datetime.timedelta(minutes=1).total_seconds())
|
||||||
"""
|
"""
|
||||||
@ -244,6 +246,7 @@ hass.states.set('module.datetime',
|
|||||||
yield from hass.async_block_till_done()
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state('module.time', '1986')
|
assert hass.states.is_state('module.time', '1986')
|
||||||
|
assert hass.states.is_state('module.time_strptime', '12:34')
|
||||||
assert hass.states.is_state('module.datetime', '60.0')
|
assert hass.states.is_state('module.datetime', '60.0')
|
||||||
|
|
||||||
# No errors logged = good
|
# No errors logged = good
|
||||||
|
Loading…
x
Reference in New Issue
Block a user