hahn-th / homematicip-rest-api

A python wrapper for the homematicIP REST API (Access Point Based)
https://hahn-th.github.io/homematicip-rest-api/
GNU General Public License v3.0
215 stars 63 forks source link

hmip_cli.py --list-devices fails #530

Open mamugit opened 3 months ago

mamugit commented 3 months ago

Hello,

I was running the cli script to list devices of my installation but the command fails with the following error message:


UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013' in position 60: ordinal not in range(256) Traceback (most recent call last): File "/home/mm/.local/lib/python3.9/site-packages/homematicip/cli/hmip_cli.py", line 54, in main if not run(config, home, logger, parsed_args): File "/home/mm/.local/lib/python3.9/site-packages/homematicip/cli/hmip_cli.py", line 135, in run print("{} {}".format(d.id, str(d))) UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013' in position 60: ordinal not in range(256)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/mm/.local/bin/./hmip_cli", line 8, in sys.exit(main()) File "/home/mm/.local/lib/python3.9/site-packages/homematicip/cli/hmip_cli.py", line 69, in main if parsed_args.log_level: AttributeError: 'Namespace' object has no attribute 'log_level'

I have installed it on Debian 11 bulleseye on a 64bit x86 machine using Python 3.9.2 on a raspberry pi 5 with 64 bit Raspbian Bookworm with Python 3.11.2 python3 hmip_cli.py is not running at all; no output with --list-devices. Generation auf Auth token worked well on Raspberry Pi as well as on my x86 machine. hmip_cli.py --dump-devices is working on x86 machine. I'm wondering why --list-devices fails ??? Any idea ?

after installation I got a the following script to run hmip_cli:

cat hmip_cli

!/usr/bin/python3

-- coding: utf-8 --

import re import sys from homematicip.cli.hmip_cli import main if name == 'main': sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0]) sys.exit(main())

here is the version I'm using: pip3 show homematicip Name: homematicip Version: 1.1.1

hahn-th commented 3 months ago

Try without .py Just hmip --list-devices. And you have to run the auth script before.

mamugit commented 3 months ago

thank you but in my installation there is no hmip; there is only hmip_cli script and hmip_cli.py script; the .py doesn't work, the hmip_cli gives the error above.

mamugit commented 3 months ago

I tried version 1.0.0 and it gives some output but also containing '\u2013' in position 60 error; 1.0.9 seems to work either but 1.1.10 has the same failure as 1.1.1

hahn-th commented 3 months ago

i invite you to beta test version 2 :) pip install homematicip==1.1.0.post1.dev44

Just use hmip.

mamugit commented 3 months ago

thank you! I installed python 3.12.3 and tested your beta version on my raspberry pi but unfortunately with no success:

./hmip version

HomematicIP-Rest-Api: 1.1.0.post1.dev44 Python: 3.12.3 (main, Jun 8 2024, 10:16:28) [GCC 12.2.0]

./hmip auth

============================= Generating an auth token to access the HomematicIP Cloud. Please enter the access point id []:xxx Please enter the client/devicename (leave blank to use default): xxx
Please enter the PIN (leave Blank if there is none): Please enter the PIN (leave Blank if there is none): xxx Requesting connection to the HomematicIP Cloud... Please press the blue button on the access point... on 0: Exception in thread Thread-2 (run): Traceback (most recent call last): File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner self.run() on 0: File "/usr/local/lib/python3.12/threading.py", line 1010, in run self._target(*self._args, self._kwargs) on 0: File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/core/progress.py", line 140, in run alive_repr(next(spinner_player), spinner_suffix) on 0: File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/core/progress.py", line 165, in alive_repr run.last_len = print_cells(fragments, term.cols(), term, run.last_len) on 0: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on 0: File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/utils/cells.py", line 109, in print_cells term.write(join_cells(fragment)) on 0: File "/usr/local/lib/python3.12/encodings/iso8859_15.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] on 0: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on 0: UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-14: character maps to Traceback (most recent call last): File "/home/mm/.local/bin/./hmip", line 8, in sys.exit(cli()) ^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/click/core.py", line 783, in invoke return __callback(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/homematicip/cli/hmip.py", line 149, in auth with alive_bar(0, monitor=False, stats=False) as bar: File "/usr/local/lib/python3.12/contextlib.py", line 144, in exit next(self.gen) File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/core/progress.py", line 364, in __alive_bar alive_repr() File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/core/progress.py", line 165, in alive_repr run.last_len = print_cells(fragments, term.cols(), term, run.last_len) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mm/.local/lib/python3.12/site-packages/alive_progress/utils/cells.py", line 109, in print_cells term.write(join_cells(fragment)) File "/usr/local/lib/python3.12/encodings/iso8859_15.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-40: character maps to

=============================

cat hmip

!/usr/local/bin/python3.12

-- coding: utf-8 --

import re import sys from homematicip.cli.hmip import cli if name == 'main': sys.argv[0] = re.sub(r'(-script.pyw|.exe)?$', '', sys.argv[0]) sys.exit(cli())

/usr/local/bin/python3.12 --version Python 3.12.3

hahn-th commented 3 months ago

Thats progress bar when waiting for the button to be pressed. Give it another try please. I also added encoding utf-8 to open and read config file. pip install homematicip==1.1.0.post1.dev46

mamugit commented 3 months ago

great, thank you! many thanks for your support! ... it's now working; auth file is created.

.... but ./hmip list devices does not find the auth file .... the auth file was generated and put to: ~/.homematicip-rest-api/config.json

mamugit commented 3 months ago

seems to find the auth file if I go directly into the directory of the auth file, and start command from there, but it fails:

../.local/bin/hmip list devices

Devices: (xxxxxxxxxxxxxx) - HOME_CONTROL_ACCESS_POINT - HOME_CONTROL_ACCESS_POINT [0] - ACCESS_CONTROLLER_CHANNEL - Traceback (most recent call last): File "/home/user/.homematicip-rest-api/../.local/bin/hmip", line 8, in sys.exit(cli()) ^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 1157, in call return self.main(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/click/core.py", line 783, in invoke return __callback(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/user/.local/lib/python3.12/site-packages/homematicip/cli/hmip.py", line 146, in devices click.echo(f"\t({device.id}) - {device.label} - {device.type}") File "/home/user/.local/lib/python3.12/site-packages/click/utils.py", line 318, in echo file.write(out) # type: ignore ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/encodings/iso8859_15.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 51: character maps to

hahn-th commented 3 months ago

I am sorry. I have no idea. Something seems to be strange with encoding. Looks like click (lib for the cli) is trying to write to stdout, what doesn't work. According to click's docs they do their very best to handle unicode very well. https://click.palletsprojects.com/en/8.1.x/unicode-support/

At the point where your error happened, the config file is read correct and you got the state of your homematicIP installation.

btw: I guess i fixed the path to config file problem pip3 install homematicip==1.1.0.post1.dev47

mamugit commented 3 months ago

path problem with dev47 is not solved; still the same behaviour; it only works if I directly go to ~/.homematicip-rest-api/

hahn-th commented 3 months ago

And if you run hmip auth again?

mamugit commented 3 months ago

thanks yes it works now; new auth file resolved it!

mamugit commented 3 months ago

I was able to resolve the encoding-error '\u2013' above.

The HmIP-eTRV-C-2 has the default name "Heizkörperthermostat - kompakt" which was also in the Label of the Device, as I did not change names in my HomematicIP setup. The problem is that the dash "-" in the name is not a normal dash but the wider \u2013 dash; this comes from the factory naming of eQ3 / ELV device. I changed the label naming in my HMIP setup and now I can run hmip list devices successfully

there seems to be an encoding problem in the hmip script which is not capable of handeling all possible lable names