Skip to content

Commit 6e82843

Browse files
authored
Notify filename writemode (#8)
* Update notify.py write mode to 'w' notify entity_id to include filename * Update manifest.json
1 parent 2fe051c commit 6e82843

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

custom_components/file_plusplus/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"documentation": "https://github.com/benjamin-dcs/File-plusplus/blob/main/README.md",
77
"iot_class": "local_polling",
88
"issue_tracker": "https://github.com/benjamin-dcs/File-plusplus/issues",
9-
"version": "0.1.1"
9+
"version": "0.1.2"
1010
}

custom_components/file_plusplus/notify.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,16 @@ def __init__(self, unique_id: str, config: dict[str, Any]) -> None:
115115
self._file_path: str = config[CONF_FILE_PATH]
116116
self._add_timestamp: bool = config.get(CONF_TIMESTAMP, False)
117117
# Only import a name from an imported entity
118-
self._attr_name = config.get(CONF_NAME, DEFAULT_NAME)
118+
self._attr_name = config.get(CONF_NAME, DEFAULT_NAME) + "_" + self._file_path.split("/")[-1].replace(".", "_")
119119
self._attr_unique_id = unique_id
120120

121121
def send_message(self, message: str, title: str | None = None) -> None:
122122
"""Send a message to a file."""
123123
file: TextIO
124124
filepath = self._file_path
125+
message = message.strip()
125126
try:
126-
with open(filepath, "a", encoding="utf8") as file:
127+
with open(filepath, "w", encoding="utf8") as file:
127128
if self._add_timestamp:
128129
text = f"{dt_util.utcnow().isoformat()} {message}\n"
129130
else:

0 commit comments

Comments
 (0)