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

import error #2

Closed
hallonstedt opened this issue Mar 9, 2022 · 1 comment
Closed

import error #2

hallonstedt opened this issue Mar 9, 2022 · 1 comment

Comments

@hallonstedt
Copy link

I would like to get data out of my inverter but I seem unable to import the SungrowInverter library.
pip3 successfully installed both SungrowModbusTcpClient-0.1.6 and SungrowInverter-0.1.7 but when I try to import the module I get a TypeError that I am unable to figure out the reason for.

`PI:~# python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

from sungrowinverter import SungrowInverter
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/dist-packages/sungrowinverter/init.py", line 4, in
from sungrowinverter.SungrowInverter import SungrowInverter
File "/usr/local/lib/python3.7/dist-packages/sungrowinverter/SungrowInverter.py", line 16, in
from sungrowinverter.configs.inverter import (
File "/usr/local/lib/python3.7/dist-packages/sungrowinverter/configs/inverter.py", line 21, in
ModBusRegister(5001, "nominal_output_power", "U16", 0.1, KILO_WATT),
TypeError: 'type' object is not subscriptable
`

@hallonstedt
Copy link
Author

After some additional trolling on the Internet, I realized that the problem is that the code is using type hinting, which was introduced in python 3.9. The setup.cfg file incorrectly lists python >= 3.5 as requirements.

The workaround, if you would like to avoid upgrading python, is to use the typing library to avoid problems with generic typing. See example diff for configs/inverter.py;

PI:~# diff /usr/src/SungrowInverter/sungrowinverter/configs/inverter.py /usr/local/lib/python3.7/dist-packages/sungrowinverter/configs/inverter.py
12a13,14
> from typing import Tuple, List
18c20
< INVERTER_READ_REGISTERS: tuple[ModBusRegister, ...] = (
---
> INVERTER_READ_REGISTERS: Tuple[ModBusRegister, ...] = (
24c26
< INVERTER_HOLDING_REGISTERS: tuple[ModBusRegister, ...] = (
---
> INVERTER_HOLDING_REGISTERS: Tuple[ModBusRegister, ...] = (
30c32
< INVERTER_MODELS: list[SungrowInverterModel] = (
---
> INVERTER_MODELS: List[SungrowInverterModel] = (

Repeat procedure for hybrid.py and string.py and it will work like a charm!

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

No branches or pull requests

1 participant