It’s the same file. Maybe you get an other exception or it is not used. I added a catch all for exceptions and a log entry to check if the function read is used. Could you check if those entries are listed in the HA logs?
(I did only list the read function … the rest can be the same)
async def read(self, sensors):
"""Returns necessary sensors from SAJ inverter"""
_LOGGER.warning('The pysaj read function is called')
try:
timeout = aiohttp.ClientTimeout(total=5)
async with aiohttp.ClientSession(timeout=timeout,
raise_for_status=True) as session:
current_url = self.url_info
async with session.get(current_url) as response:
data = await response.text()
if self.wifi:
csv_data = StringIO(data)
reader = csv.reader(csv_data)
for row in reader:
self.serialnumber = row.pop(0)
else:
xml = ET.fromstring(data)
find = xml.find("SN")
if find is not None:
self.serialnumber = find.text
_LOGGER.debug("Inverter SN: %s", self.serialnumber)
current_url = self.url
async with session.get(current_url) as response:
data = await response.text()
at_least_one_enabled = False
if self.wifi:
csv_data = StringIO(data)
reader = csv.reader(csv_data)
ncol = len(next(reader))
csv_data.seek(0)
values = []
for row in reader:
for (i, v) in enumerate(row):
values.append(v)
for sen in sensors:
if ncol < 24:
if sen.csv_1_key != -1:
try:
v = values[sen.csv_1_key]
except IndexError:
v = None
else:
v = None
else:
if sen.csv_2_key != -1:
try:
v = values[sen.csv_2_key]
except IndexError:
v = None
else:
v = None
if v is not None:
if sen.name == "state":
sen.value = MAPPER_STATES[v]
else:
sen.value = eval(
"{0}{1}".format(v, sen.factor)
)
sen.date = date.today()
sen.enabled = True
at_least_one_enabled = True
else:
xml = ET.fromstring(data)
for sen in sensors:
find = xml.find(sen.key)
if find is not None:
sen.value = find.text
sen.date = date.today()
sen.enabled = True
at_least_one_enabled = True
if not at_least_one_enabled:
if self.wifi:
raise csv.Error
else:
raise ET.ParseError
if sen.enabled:
_LOGGER.debug("Got new value for sensor %s: %s",
sen.name, sen.value)
return True
except (asyncio.exceptions.TimeoutError,
concurrent.futures._base.TimeoutError):
# Connection to inverter not possible.
# This can be "normal" - so warning instead of error - as SAJ
# inverters are powered by DC and thus have no power after the sun
# has set.
_LOGGER.warning("Connection to SAJ inverter is not possible. " +
"The inverter may be offline due to darkness. " +
"Otherwise check host/ip address.")
return False
except aiohttp.client_exceptions.ClientResponseError as err:
# 401 Unauthorized: wrong username/password
if err.status == 401:
raise UnauthorizedException(err)
else:
raise UnexpectedResponseException(err)
except csv.Error:
# CSV is not valid
raise UnexpectedResponseException(
str.format("No valid CSV received from {0} at {1}", self.host,
current_url)
)
except ET.ParseError:
# XML is not valid or even no XML at all
raise UnexpectedResponseException(
str.format("No valid XML received from {0} at {1}", self.host,
current_url)
)
except Exception as e:
_LOGGER.warning('Uncaught Exception Found: {}'.format(type(e)))