Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion homeassistant/components/python_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,11 @@ def sleep(self, *args, **kwargs):

def __getattr__(self, attr):
"""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 attribute is callable."""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (81 > 79 characters)

return attribute(*args, **kw)
return wrapper
else:
return attribute
3 changes: 3 additions & 0 deletions tests/components/test_python_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def test_exposed_modules(hass, caplog):
caplog.set_level(logging.ERROR)
source = """
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',
datetime.timedelta(minutes=1).total_seconds())
"""
Expand All @@ -244,6 +246,7 @@ def test_exposed_modules(hass, caplog):
yield from hass.async_block_till_done()

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')

# No errors logged = good
Expand Down