mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
use with open
This commit is contained in:
parent
832e9a631e
commit
ef40b94a87
@ -62,19 +62,17 @@ class FileNotificationService(BaseNotificationService):
|
|||||||
def send_message(self, message="", **kwargs):
|
def send_message(self, message="", **kwargs):
|
||||||
""" Send a message to a file. """
|
""" Send a message to a file. """
|
||||||
|
|
||||||
file = open(self.filepath, 'a')
|
with open(self.filepath, 'a') as file:
|
||||||
if os.stat(self.filepath).st_size == 0:
|
if os.stat(self.filepath).st_size == 0:
|
||||||
title = '{} notifications (Log started: {})\n{}\n'.format(
|
title = '{} notifications (Log started: {})\n{}\n'.format(
|
||||||
kwargs.get(ATTR_TITLE),
|
kwargs.get(ATTR_TITLE),
|
||||||
dt_util.strip_microseconds(dt_util.utcnow()),
|
dt_util.strip_microseconds(dt_util.utcnow()),
|
||||||
'-'*80)
|
'-'*80)
|
||||||
file.write(title)
|
file.write(title)
|
||||||
|
|
||||||
if self.add_timestamp == 1:
|
if self.add_timestamp == 1:
|
||||||
text = '{} {}\n'.format(dt_util.utcnow(), message)
|
text = '{} {}\n'.format(dt_util.utcnow(), message)
|
||||||
file.write(text)
|
file.write(text)
|
||||||
else:
|
else:
|
||||||
text = '{}\n'.format(message)
|
text = '{}\n'.format(message)
|
||||||
file.write(text)
|
file.write(text)
|
||||||
|
|
||||||
file.close()
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user