Skip to content

Commit d79b1ec

Browse files
committed
2 parents 0fdba2e + e58e74f commit d79b1ec

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
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",
77
"iot_class": "local_polling",
88
"issue_tracker": "https://github.com/benjamin-dcs/File-plusplus/issues",
9-
"version": "0.1.3"
9+
"version": "0.1.4"
1010
}

custom_components/file_plusplus/sensor.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,15 @@ def __init__(
9999
self._attr_unique_id = unique_id
100100

101101
def update(self) -> None:
102-
"""Get the latest entry from a file and updates the state."""
103-
try:
104-
105-
with open(self._file_path, encoding="utf-8") as f:
106-
data = f.read()
107-
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError) as e:
108-
_LOGGER.warning(
109-
"File or data not present at the moment: %s",
110-
os.path.basename(self._file_path),
111-
)
112-
return
113-
102+
"""Return entity state."""
114103
self._attr_native_value = "Ok"
115104

116105
@property
117106
def extra_state_attributes(self):
118-
"""Return device state attributes."""
107+
"""
108+
Return entity state attributes.
109+
Get the latest entry from a file and updates the state.
110+
"""
119111

120112
try:
121113
with open(self._file_path, encoding="utf-8") as f:
@@ -125,9 +117,9 @@ def extra_state_attributes(self):
125117
"File or data not present at the moment: %s",
126118
os.path.basename(self._file_path),
127119
)
128-
return
120+
data = ""
129121

130-
if self._val_tpl is not None:
122+
if data and self._val_tpl is not None:
131123
content = (
132124
self._val_tpl.async_render_with_possible_json_value(data, None)
133125
)

0 commit comments

Comments
 (0)