ValueError: 9 is not a valid DataType / Event loop is closed
Closed this issue · 10 comments
First of all, I would to thank you for this great project to provide an easy to consume Python wrapper.
I tried to use it with my Somfy System by:
- creating a new env
python -m venv env
and activate it - install the package
pip install pyhoma
- copy and paste the getting started example to a new script file
start.py
- entered my somfy credentials for username and password
- starting it with
python start.py
Unfortunately I recieved the following Error Messages
(env) c:\github\test-pyhoma>python start.py
ValueError: 9 is not a valid DataType
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "start.py", line 29, in
asyncio.run(main())
File "C:\Python38\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "C:\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "start.py", line 17, in main
devices = await client.get_devices()
File "c:\github\test-pyhoma\env\lib\site-packages\backoff_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\client.py", line 117, in get_devices
devices = [Device(**d) for d in humps.decamelize(response)]
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\client.py", line 117, in
devices = [Device(**d) for d in humps.decamelize(response)]
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\models.py", line 64, in init
self.attributes = States(attributes) if attributes else None
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\models.py", line 160, in init
self._states = [State(**state) for state in states]
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\models.py", line 160, in
self._states = [State(**state) for state in states]
File "c:\github\test-pyhoma\env\lib\site-packages\pyhoma\models.py", line 155, in init
self.type = DataType(type)
File "C:\Python38\lib\enum.py", line 304, in call
return cls.new(cls, value)
File "C:\Python38\lib\enum.py", line 595, in new
raise exc
File "C:\Python38\lib\enum.py", line 579, in new
result = cls.missing(value)
File "C:\Python38\lib\enum.py", line 608, in missing
raise ValueError("%r is not a valid %s" % (value, cls.name))
ValueError: 9 is not a valid DataType
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001D020474D30>
Traceback (most recent call last):
File "C:\Python38\lib\asyncio\proactor_events.py", line 116, in del
self.close()
File "C:\Python38\lib\asyncio\proactor_events.py", line 108, in close
self._loop.call_soon(self._call_connection_lost, None)
File "C:\Python38\lib\asyncio\base_events.py", line 719, in call_soon
self._check_closed()
File "C:\Python38\lib\asyncio\base_events.py", line 508, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
May someone has an idea, what is going wrong here?
It seems that your devices broadcast a different DataType (9?), which is not known by us yet. Which hub do you have? We would need to make some changes for better debugging, would you be able to run this package from source as well?
@PythonPhilipp, I assume you want to control it directly via Python and not via Home Assistant e.g.?
@iMicknl , your assumption is right. I would like to control it directly via Python.
On https://www.tahomalink.com I found following information about my hub:
- TaHoma-Box online
- date of activation 09.04.2013
- version 2018.4.4.7
- status active
- your box is up to date
Running the package from source works for me. I am familiar with github, git and software development in python.
You would need to add 9 to this enum https://github.com/iMicknl/python-tahoma-api/blob/b756859688f3083774694d6c48ec8c635a6409ff/pyhoma/enums.py#L68, however I don't know which casting you would require. Perhaps you could start with STRING
and see what kind of data is stored.
The first step in this process was for me to change .python-version to 3.7.7
I am using pyenv and 3.7.8
is not available.
Following the hint to edit enums.py, I tried to set NONE, INTEGER, FLOAT, STRING, BLOB, DATE, BOOLEAN, JSON_ARRAY and JSON_OBJECT = 9
. None of them worked.
When I set UNKNOWN = 9
it worked and I got a list of all devices by
print(f"{device.label} ({device.id}) - {device.controllable_name}") print(f"{device.widget} - {device.ui_class}")
It is now also possible to stop the script in the debugging mode and examine the pyhoma.client.TahomaClient object.
Is there a better way to solve this issue, further work necessary or might be this solution useful for the main project?
Which error did you receive when you set the enum to one of these values? Could you perhaps share your config with me?
Easiest in your situation would be to dump / print the raw response here:
https://github.com/iMicknl/python-tahoma-api/blob/b756859688f3083774694d6c48ec8c635a6409ff/pyhoma/client.py#L116
and to look for the state key, where type is 9. Could you share this object here?
Eventually this 'bug' will only affect the every call that returns an object with a state, since this DataType
enum is used in State
.
Here is the raw error message for the case STRING = 9
Microsoft Windows [Version 10.0.19042.867]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\github\python-tahoma-api>C:/github/python-tahoma-api/env/Scripts/activate.bat
(env) C:\github\python-tahoma-api> cmd /C "C:\github\python-tahoma-api\env\Scripts\python.exe c:\Users\phili\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy\launcher 53548 -- c:\github\python-tahoma-api\pyhoma\enums.py "
Traceback (most recent call last):
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\phili\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\phili\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\phili\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\github\python-tahoma-api\pyhoma\enums.py", line 68, in <module>
class DataType(Enum):
File "c:\github\python-tahoma-api\pyhoma\enums.py", line 76, in DataType
STRING = 9
File "C:\Users\phili\.pyenv\pyenv-win\versions\3.7.7\lib\enum.py", line 101, in __setitem__
raise TypeError('Attempted to reuse key: %r' % key)
TypeError: Attempted to reuse key: 'STRING'
By setting UNKOWN = 9
, it is possible to print the response object
{
'name': 'camera:viewerpwd',
'type': 9,
'value': REDACTED'
}
In the first object, named Axis1, is a attribute with 'type': 9. Is this the roote cause?
Indeed. This is the root cause! We haven't seen a state yet with type 9, which in your case is your password. I have removed most of your post and redacted your password, however it would be wise to change it if it is internet facing...
I need to double check if you can reuse keys in an enum, but otherwise setting it to PASSWORD should work for now and we can include this in our component soon.
Have you tried Home Assistant by the way? This would give you a lot of flexibility for controlling your devices.
By searching for Home Assistant, I found following website https://www.home-assistant.io/ and the project on github https://github.com/home-assistant. Thank you for this reference. The project looks great 👍
In the meantime I changed my password. Thanks for your care :)
If your also fine, we could close this issue.
Until now, I only consumed open source. Maybe you see a chance for me to support you with your tahoma projects?
At first I would need some assistance for start-up support, but hopefully this pays off on the long run.
Until now, I only consumed open source. Maybe you see a chance for me to support you with your tahoma projects?
At first I would need some assistance for start-up support, but hopefully this pays off on the long run.
Looking at your username, you program in Python? I would advise to give Home Assistant a try and explore the ecosystem. Home Assistant is written in Python and there are many ways how you could contribute. This could be via https://github.com/imicknl/ha-tahoma, but also for other integrations or the core.
I will close this issue as soon as I have made the required changed, until then I will keep this open for tracking purposes :).