Skip to content

Commit d1fbd74

Browse files
authored
Merge branch 'ha-core-2024-08-07' into main
2 parents ebaa576 + f25c735 commit d1fbd74

File tree

6 files changed

+42
-78
lines changed

6 files changed

+42
-78
lines changed

custom_components/file_plusplus/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""The file++ component."""
1+
"""The file component."""
22

33
from copy import deepcopy
44
from typing import Any
@@ -44,7 +44,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
4444
return True
4545
# The use of the legacy notify service was deprecated with HA Core 2024.6.0
4646
# and will be removed with HA Core 2024.12
47-
migrate_notify_issue(hass, DOMAIN, "File++", "2024.12.0")
47+
migrate_notify_issue(hass, DOMAIN, "File", "2024.12.0")
4848
# The YAML config was imported with HA Core 2024.6.0 and will be removed with
4949
# HA Core 2024.12
5050
ir.async_create_issue(
@@ -59,7 +59,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
5959
translation_key="deprecated_yaml",
6060
translation_placeholders={
6161
"domain": DOMAIN,
62-
"integration_title": "File++",
62+
"integration_title": "File",
6363
},
6464
)
6565

custom_components/file_plusplus/config_flow.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
"""Config flow for file++ integration."""
1+
"""Config flow for file integration."""
22

33
from copy import deepcopy
4-
import logging
54
import os
65
from typing import Any
76

@@ -23,7 +22,6 @@
2322
CONF_VALUE_TEMPLATE,
2423
Platform,
2524
)
26-
2725
from homeassistant.core import callback
2826
from homeassistant.helpers.selector import (
2927
BooleanSelector,
@@ -37,8 +35,6 @@
3735

3836
from .const import CONF_TIMESTAMP, DEFAULT_NAME, DOMAIN
3937

40-
_LOGGER = logging.getLogger(__name__)
41-
4238
BOOLEAN_SELECTOR = BooleanSelector(BooleanSelectorConfig())
4339
TEMPLATE_SELECTOR = TemplateSelector(TemplateSelectorConfig())
4440
TEXT_SELECTOR = TextSelector(TextSelectorConfig(type=TextSelectorType.TEXT))
@@ -72,7 +68,7 @@
7268

7369

7470
class FileConfigFlowHandler(ConfigFlow, domain=DOMAIN):
75-
"""Handle a file++ config flow."""
71+
"""Handle a file config flow."""
7672

7773
VERSION = 2
7874

@@ -133,9 +129,7 @@ async def async_step_sensor(
133129
"""Handle file sensor config flow."""
134130
return await self._async_handle_step(Platform.SENSOR.value, user_input)
135131

136-
async def async_step_import(
137-
self, import_data: dict[str, Any]
138-
) -> ConfigFlowResult:
132+
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
139133
"""Import `file`` config from configuration.yaml."""
140134
self._async_abort_entries_match(import_data)
141135
platform = import_data[CONF_PLATFORM]
@@ -158,12 +152,12 @@ async def async_step_import(
158152

159153

160154
class FileOptionsFlowHandler(OptionsFlowWithConfigEntry):
161-
"""Handle File++ options."""
155+
"""Handle File options."""
162156

163157
async def async_step_init(
164158
self, user_input: dict[str, Any] | None = None
165159
) -> ConfigFlowResult:
166-
"""Manage File++ options."""
160+
"""Manage File options."""
167161
if user_input:
168162
return self.async_create_entry(data=user_input)
169163

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""Constants for the file++ integration."""
1+
"""Constants for the file integration."""
22

3-
DOMAIN = "file_plusplus"
3+
DOMAIN = "file"
44

55
CONF_TIMESTAMP = "timestamp"
66

7-
DEFAULT_NAME = "file_plusplus"
7+
DEFAULT_NAME = "File"
88
FILE_ICON = "mdi:file"
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"domain": "file_plusplus",
3-
"name": "File++",
4-
"codeowners": ["@benjamin-dcs"],
5-
"config_flow": true,
6-
"documentation": "https://github.com/benjamin-dcs/File-plusplus/blob/main/README.md",
7-
"iot_class": "local_polling",
8-
"issue_tracker": "https://github.com/benjamin-dcs/File-plusplus/issues",
9-
"version": "0.1.0"
10-
}
2+
"domain": "file",
3+
"name": "File",
4+
"codeowners": ["@fabaff"],
5+
"config_flow": true,
6+
"documentation": "https://www.home-assistant.io/integrations/file",
7+
"iot_class": "local_polling",
8+
"requirements": ["file-read-backwards==2.0.0"]
9+
}

custom_components/file_plusplus/notify.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Support for file++ notification."""
1+
"""Support for file notification."""
22

33
from __future__ import annotations
44

@@ -57,7 +57,7 @@ async def async_get_service(
5757

5858

5959
class FileNotificationService(BaseNotificationService):
60-
"""Implement the notification service for the File++ service."""
60+
"""Implement the notification service for the File service."""
6161

6262
def __init__(self, file_path: str, add_timestamp: bool) -> None:
6363
"""Initialize the service."""
@@ -81,12 +81,12 @@ def send_message(self, message: str = "", **kwargs: Any) -> None:
8181
filepath = self._file_path
8282
try:
8383
with open(filepath, "a", encoding="utf8") as file:
84-
# if os.stat(filepath).st_size == 0:
85-
# title = (
86-
# f"{kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)} notifications (Log"
87-
# f" started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
88-
# )
89-
# file.write(title)
84+
if os.stat(filepath).st_size == 0:
85+
title = (
86+
f"{kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)} notifications (Log"
87+
f" started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
88+
)
89+
file.write(title)
9090

9191
if self.add_timestamp:
9292
text = f"{dt_util.utcnow().isoformat()} {message}\n"
@@ -131,12 +131,12 @@ def send_message(self, message: str, title: str | None = None) -> None:
131131
filepath = self._file_path
132132
try:
133133
with open(filepath, "a", encoding="utf8") as file:
134-
# if os.stat(filepath).st_size == 0:
135-
# title = (
136-
# f"{title or ATTR_TITLE_DEFAULT} notifications (Log"
137-
# f" started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
138-
# )
139-
# file.write(title)
134+
if os.stat(filepath).st_size == 0:
135+
title = (
136+
f"{title or ATTR_TITLE_DEFAULT} notifications (Log"
137+
f" started: {dt_util.utcnow().isoformat()})\n{'-' * 80}\n"
138+
)
139+
file.write(title)
140140

141141
if self._add_timestamp:
142142
text = f"{dt_util.utcnow().isoformat()} {message}\n"

custom_components/file_plusplus/sensor.py

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import os
77

8-
# from file_read_backwards import FileReadBackwards
8+
from file_read_backwards import FileReadBackwards
99
import voluptuous as vol
1010

1111
from homeassistant.components.sensor import (
@@ -98,50 +98,21 @@ def __init__(
9898
def update(self) -> None:
9999
"""Get the latest entry from a file and updates the state."""
100100
try:
101-
# with FileReadBackwards(self._file_path, encoding="utf-8") as file_data:
102-
# for line in file_data:
103-
# data = line
104-
# break
105-
# data = data.strip()
106-
with open(self._file_path, encoding="utf-8") as f:
107-
data = f.read()
108-
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError) as e:
109-
_LOGGER.warning(
110-
"File or data not present at the moment: %s",
111-
os.path.basename(self._file_path),
112-
)
113-
return
114-
115-
self._attr_native_value = "Ok"
116-
117-
# if self._val_tpl is not None:
118-
# self._attr_native_value = (
119-
# self._val_tpl.async_render_with_possible_json_value(data, None)
120-
# )
121-
# else:
122-
# self._attr_native_value = data
123-
124-
@property
125-
def extra_state_attributes(self):
126-
"""Return device state attributes."""
127-
128-
try:
129-
with open(self._file_path, encoding="utf-8") as f:
130-
data = f.read()
131-
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError) as e:
101+
with FileReadBackwards(self._file_path, encoding="utf-8") as file_data:
102+
for line in file_data:
103+
data = line
104+
break
105+
data = data.strip()
106+
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError):
132107
_LOGGER.warning(
133108
"File or data not present at the moment: %s",
134109
os.path.basename(self._file_path),
135110
)
136111
return
137112

138113
if self._val_tpl is not None:
139-
content = (
114+
self._attr_native_value = (
140115
self._val_tpl.async_render_with_possible_json_value(data, None)
141116
)
142117
else:
143-
content = data
144-
145-
return {
146-
"content": content,
147-
}
118+
self._attr_native_value = data

0 commit comments

Comments
 (0)