Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_battery_data: 'NoneType' object cannot be interpreted as an integer #71

Closed
baststar opened this issue Apr 1, 2023 · 2 comments · Fixed by #86
Closed

get_battery_data: 'NoneType' object cannot be interpreted as an integer #71

baststar opened this issue Apr 1, 2023 · 2 comments · Fixed by #86

Comments

@baststar
Copy link

baststar commented Apr 1, 2023

Get this error when i run e3dc-to-mqtt (https://github.com/mdhom/e3dc-to-mqtt)

File "/home/pi/gitstuff/e3dc-to-mqtt/e3dc_to_mqtt/e3dc_to_mqtt_base.py", line 164, in run
battery_data = await self.e3dc.get_battery_data()
File "/home/pi/gitstuff/e3dc-to-mqtt/e3dc_to_mqtt/e3dc_to_mqtt_base.py", line 299, in get_battery_data
battery_data = self.__e3dc.get_battery_data(batIndex=i)
File "/root/.local/lib/python3.7/site-packages/e3dc/_e3dc.py", line 1324, in get_battery_data
for sensor in range(0, sensorCount):
TypeError: 'NoneType' object cannot be interpreted as an integer

@baststar
Copy link
Author

baststar commented Sep 24, 2023

Pasted the code and the error to ChatGPT:

image

The error message you provided indicates that there's an issue in the _e3dc.py file, on line 1324, where the code is attempting to iterate over a range with sensorCount as the upper limit. However, it seems that sensorCount is None, hence the error.

To help you further, I will inspect the _e3dc.py file, specifically around line 1324, to identify the source of the problem and suggest a potential solution.

From the code snippet, the error occurs at this line:

for sensor in range(0, sensorCount):

Here, sensorCount is expected to be an integer, but it's returning None. The value of sensorCount is determined by the line:

sensorCount = rscpFindTagIndex(info, "BAT_DCB_NR_SENSOR")

It seems that the function rscpFindTagIndex might be returning None when it doesn't find the specified tag within the provided data (info in this case).

To resolve this issue, you could:

  1. Ensure that the tag "BAT_DCB_NR_SENSOR" is present in the data.
  2. Add a check to handle the case when sensorCount is None.

Here's a suggestion on how to handle it:

sensorCount = rscpFindTagIndex(info, "BAT_DCB_NR_SENSOR")
if sensorCount is None:
    sensorCount = 0  # Or handle this case in some other appropriate way
for sensor in range(0, sensorCount):
    ...

This will prevent the error by setting sensorCount to 0 if it's None. Depending on your use case, you might want to log a warning or take some other action if sensorCount is None.

Would you like to apply this fix or investigate further?

@eikowagenknecht
Copy link
Contributor

eikowagenknecht commented Sep 26, 2023

Same problem here with a S10 X Compact 14.

Please also see torbennehmer/hacs-e3dc#45, some tests are already documented there.

If I can help in diagnosing it by running some more commands, I'm happy to help @fsantini @torbennehmer !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants