Skip to content

Commit 2fc669e

Browse files
authored
Sync File++ with HA Core File 2025.3 (#18)
1 parent 2a70c3f commit 2fc669e

File tree

9 files changed

+61
-29
lines changed

9 files changed

+61
-29
lines changed

.github/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Init package."""

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
release_zip_file:
10+
name: Prepare release asset 📁
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
id-token: write
15+
steps:
16+
- name: ⤵️ Checkout repository
17+
uses: /checkout@v4
18+
19+
- name: 📦 Created zipped release package
20+
run: |
21+
cd custom_components/file_plusplus
22+
zip file-plusplus.zip -r ./
23+
24+
- name: 🔏 Sign release package
25+
uses: sigstore/[email protected]
26+
with:
27+
inputs: ${{ github.workspace }}/custom_components/file_plusplus/file-plusplus.zip
28+
29+
- name: ⬆️ Upload zip to release
30+
uses: softprops/[email protected]
31+
with:
32+
files: ${{ github.workspace }}/custom_components/file_plusplus/file-plusplus.zip

custom_components/file_plusplus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
6464
hass.config_entries.async_update_entry(
6565
config_entry, version=2, data=data, options=options
6666
)
67-
return True
67+
return True

custom_components/file_plusplus/config_flow.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
TextSelectorType,
3333
)
3434

35-
from .const import CONF_TIMESTAMP, DEFAULT_NAME, DOMAIN
35+
from .const import CONF_TIMESTAMP, DOMAIN
3636

3737
BOOLEAN_SELECTOR = BooleanSelector(BooleanSelectorConfig())
3838
TEMPLATE_SELECTOR = TemplateSelector(TemplateSelectorConfig())
@@ -105,7 +105,6 @@ async def _async_handle_step(
105105
if not await self.validate_file_path(user_input[CONF_FILE_PATH]):
106106
errors[CONF_FILE_PATH] = "not_allowed"
107107
else:
108-
# title = f"{DEFAULT_NAME} [{user_input[CONF_FILE_PATH]}]"
109108
title = f"{platform.capitalize()} [{user_input[CONF_FILE_PATH]}]"
110109
data = deepcopy(user_input)
111110
options = {}
@@ -148,4 +147,4 @@ async def async_step_init(
148147
data_schema=self.add_suggested_values_to_schema(
149148
FILE_OPTIONS_SCHEMAS[platform], self.config_entry.options or {}
150149
),
151-
)
150+
)

custom_components/file_plusplus/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
CONF_TIMESTAMP = "timestamp"
66

77
DEFAULT_NAME = "File++"
8-
FILE_ICON = "mdi:file"
8+
FILE_ICON = "mdi:file"

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",
77
"iot_class": "local_polling",
88
"issue_tracker": "https://github.com/benjamin-dcs/file-plusplus/issues",
9-
"version": "1.1.0"
9+
"version": "1.1.1"
1010
}

custom_components/file_plusplus/notify.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
from __future__ import annotations
44

5-
import os
5+
from pathlib import Path
66
from typing import Any, TextIO
77

8-
from homeassistant.components.notify import (
9-
ATTR_TITLE_DEFAULT,
10-
NotifyEntity,
11-
NotifyEntityFeature,
12-
)
8+
from homeassistant.components.notify import NotifyEntity, NotifyEntityFeature
139
from homeassistant.config_entries import ConfigEntry
1410
from homeassistant.const import CONF_FILE_PATH, CONF_NAME
1511
from homeassistant.core import HomeAssistant
1612
from homeassistant.exceptions import ServiceValidationError
17-
from homeassistant.helpers.entity_platform import AddEntitiesCallback
18-
import homeassistant.util.dt as dt_util
13+
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
14+
from homeassistant.util import dt as dt_util
1915

2016
from .const import CONF_TIMESTAMP, DEFAULT_NAME, DOMAIN, FILE_ICON
2117

2218

2319
async def async_setup_entry(
2420
hass: HomeAssistant,
2521
entry: ConfigEntry,
26-
async_add_entities: AddEntitiesCallback,
22+
async_add_entities: AddConfigEntryEntitiesCallback,
2723
) -> None:
2824
"""Set up notify entity."""
2925
unique_id = entry.entry_id
@@ -50,7 +46,7 @@ def send_message(self, message: str, title: str | None = None) -> None:
5046
filepath = self._file_path
5147
try:
5248
# File++ - Mode to 'w'
53-
with open(filepath, "w", encoding="utf8") as file:
49+
with Path.open(filepath, "w", encoding="utf8") as file:
5450
# File++ - Delete header
5551
if self._add_timestamp:
5652
text = f"{dt_util.utcnow().isoformat()} {message}\n"

custom_components/file_plusplus/sensor.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import logging
6-
import os
6+
from pathlib import Path
77

88
from homeassistant.components.sensor import SensorEntity
99
from homeassistant.config_entries import ConfigEntry
@@ -14,7 +14,7 @@
1414
CONF_VALUE_TEMPLATE,
1515
)
1616
from homeassistant.core import HomeAssistant
17-
from homeassistant.helpers.entity_platform import AddEntitiesCallback
17+
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
1818
from homeassistant.helpers.template import Template
1919

2020
from .const import DEFAULT_NAME, FILE_ICON
@@ -25,7 +25,7 @@
2525
async def async_setup_entry(
2626
hass: HomeAssistant,
2727
entry: ConfigEntry,
28-
async_add_entities: AddEntitiesCallback,
28+
async_add_entities: AddConfigEntryEntitiesCallback,
2929
) -> None:
3030
"""Set up the File++ sensor."""
3131
config = dict(entry.data)
@@ -70,28 +70,31 @@ def update(self) -> None:
7070

7171
@property
7272
def extra_state_attributes(self):
73-
"""
74-
Return entity state attributes.
73+
"""Return entity state attributes.
74+
7575
Get the latest entry from a file and updates the state.
7676
"""
7777

7878
try:
79-
with open(self._file_path, encoding="utf-8") as f:
79+
with Path.open(self._file_path, encoding="utf-8") as f:
8080
data = f.read()
81-
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError) as e:
81+
except (
82+
IndexError,
83+
FileNotFoundError,
84+
IsADirectoryError,
85+
UnboundLocalError,
86+
):
8287
_LOGGER.warning(
8388
"File or data not present at the moment: %s",
84-
os.path.basename(self._file_path),
89+
Path(self._file_path).name,
8590
)
8691
data = ""
8792

8893
if data and self._val_tpl is not None:
89-
content = (
90-
self._val_tpl.async_render_with_possible_json_value(data, None)
91-
)
94+
content = self._val_tpl.async_render_with_possible_json_value(data, None)
9295
else:
9396
content = data
9497

9598
return {
9699
"content": content,
97-
}
100+
}

hacs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"name": "File++",
3-
"render_readme": true
3+
"render_readme": true,
4+
"homeassistant": "2025.3.0"
45
}

0 commit comments

Comments
 (0)