mirror of
https://github.com/home-assistant/core.git
synced 2025-12-26 14:08:21 +00:00
Black
This commit is contained in:
@@ -9,14 +9,20 @@ import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA, BaseNotificationService)
|
||||
ATTR_TITLE,
|
||||
ATTR_TITLE_DEFAULT,
|
||||
PLATFORM_SCHEMA,
|
||||
BaseNotificationService,
|
||||
)
|
||||
|
||||
CONF_TIMESTAMP = 'timestamp'
|
||||
CONF_TIMESTAMP = "timestamp"
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_FILENAME): cv.string,
|
||||
vol.Optional(CONF_TIMESTAMP, default=False): cv.boolean,
|
||||
})
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_FILENAME): cv.string,
|
||||
vol.Optional(CONF_TIMESTAMP, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -39,16 +45,17 @@ class FileNotificationService(BaseNotificationService):
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
"""Send a message to a file."""
|
||||
with open(self.filepath, 'a') as file:
|
||||
with open(self.filepath, "a") as file:
|
||||
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, ATTR_TITLE_DEFAULT),
|
||||
dt_util.utcnow().isoformat(),
|
||||
'-' * 80)
|
||||
"-" * 80,
|
||||
)
|
||||
file.write(title)
|
||||
|
||||
if self.add_timestamp:
|
||||
text = '{} {}\n'.format(dt_util.utcnow().isoformat(), message)
|
||||
text = "{} {}\n".format(dt_util.utcnow().isoformat(), message)
|
||||
else:
|
||||
text = '{}\n'.format(message)
|
||||
text = "{}\n".format(message)
|
||||
file.write(text)
|
||||
|
||||
Reference in New Issue
Block a user