Skip to content

Commit ec4214f

Browse files
authored
Remove unnecessary state logic from sensor (#10)
1 parent 89f2219 commit ec4214f

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

custom_components/file_plusplus/sensor.py

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

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

112101
@property
113102
def extra_state_attributes(self):
114-
"""Return device state attributes."""
103+
"""
104+
Return entity state attributes.
105+
Get the latest entry from a file and updates the state.
106+
"""
115107

116108
try:
117109
with open(self._file_path, encoding="utf-8") as f:
@@ -121,9 +113,9 @@ def extra_state_attributes(self):
121113
"File or data not present at the moment: %s",
122114
os.path.basename(self._file_path),
123115
)
124-
return
116+
data = ""
125117

126-
if self._val_tpl is not None:
118+
if data and self._val_tpl is not None:
127119
content = (
128120
self._val_tpl.async_render_with_possible_json_value(data, None)
129121
)

0 commit comments

Comments
 (0)