@@ -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