home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.14k stars 31.12k forks source link

Lupusec component returning error with __init__.py #82119

Closed tomoqv closed 1 year ago

tomoqv commented 2 years ago

The problem

Following a recent HA update, the Lupusec integration no longer works. I have the old XT1 hardware, which has been working perfectly on two different locations and systems (NUC with a Docker install and RPi 4). The error I am getting is this:

2022-11-15 10:35:51.906 ERROR (MainThread) [homeassistant.setup] Error during setup of component lupusec
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 58, in setup
hass.data[DOMAIN] = LupusecSystem(username, password, ip_address, name)
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 81, in __init__
self.lupusec = lupupy.Lupusec(username, password, ip_address)

What version of Home Assistant Core has the issue?

core-2022-11-2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Lupusec

Link to integration documentation on our website

https://www.home-assistant.io/integrations/lupusec

Diagnostics information

No response

Example YAML snippet

My entry in configuration.yaml:
lupusec:
  username: !secret lupusec_user
  password: !secret lupusec_pass
  ip_address: !secret lupusec_ip

Anything in the logs that might be useful for us?

2022-11-15 10:35:51.906 ERROR (MainThread) [homeassistant.setup] Error during setup of component lupusec
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 58, in setup
hass.data[DOMAIN] = LupusecSystem(username, password, ip_address, name)
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 81, in __init__
self.lupusec = lupupy.Lupusec(username, password, ip_address)

Additional information

I am using the Lupusec XT1 alarm central with firmware 1.0.80

home-assistant[bot] commented 2 years ago

Hey there @majuss, mind taking a look at this issue as it has been labeled with an integration (lupusec) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `lupusec` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign lupusec` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


lupusec documentation lupusec source (message by IssueLinks)

tomoqv commented 2 years ago
Logger: homeassistant.setup
Source: components/lupusec/__init__.py:81
First occurred: 11:54:22 (1 occurrences)
Last logged: 11:54:22
Error during setup of component lupusec

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 58, in setup
    hass.data[DOMAIN] = LupusecSystem(username, password, ip_address, name)
  File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 81, in __init__
    self.lupusec = lupupy.Lupusec(username, password, ip_address)
  File "/usr/local/lib/python3.10/site-packages/lupupy/__init__.py", line 53, in __init__
    self.headers = {"X-Token": json.loads(response.text)["message"]}
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
digwa-ing commented 2 years ago

Same problem here.

tomoqv commented 2 years ago

Could this change in manifest.json have broken the integration with Lupusec XT1 controllers?

 - "requirements": ["lupupy==0.0.24"],
 + "requirements": ["lupupy==0.1.9"],

If so, is there a way to accomodate both the older XT1 and the newer XT2 and upwards?

majuss commented 2 years ago

lupupy version 0.0.24 is only able to talk to XT1 stations. 0.1.9 will also talk to XT2 stations. So if your XT1 integration broke, you can try to manually install version 0.0.24 as an hotfix until I find the time.

tomoqv commented 2 years ago

I appreciate the work you put into this and I would be happy to help out if possible. I am running two instances of XT1 in different locations, so I am kind of depending on the XT1 integration to work (even though I know Lupusec EOL:ed it). It has been working very well so far, even though it would be nice with some additional functionality in the future. I've been looking into your code (I have some rudimentary knowledge of python) and try to find ways to implement a hotfix like the one you mention, but I am not sure how to do that. Will keep digging into the workings of this. Thank you

tomoqv commented 2 years ago

Another thing, your XT2 commits to lupupy were made 10-12 months ago, but the integration seems to have broken with the updates to the integration in Home Assistant a couple of months ago.

majuss commented 2 years ago

You basically only need to get into the venv of your HA installation and install lupupy @ version 0.0.24. https://community.home-assistant.io/t/how-to-install-python-pillow-library-in-home-assistant-os/444086/3 See this thread. "dep" dependency, so for example the lupupy package, pip is the python package manager.

Yes this is also an interesting point... not sure what broke there. Can somebody confirm that it works with the XT2?

EDIT: I checked with the XT2 of my father in law, it works. So only the XT1 is broken.

majuss commented 1 year ago

Fix is merged in HA, wait for next release.

tomoqv commented 1 year ago

Wow, that was quick! Thank you!

majuss commented 1 year ago

New HA version is live, please update and close the issue when everything is resolved :)

tomoqv commented 1 year ago

I am afraid the problem persists. I get identical errors in both of my Lupusec instances. The last log line below is new, though.

2022-12-08 10:27:23.888 ERROR (MainThread) [homeassistant.setup] Error during setup of component lupusec
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 58, in setup
hass.data[DOMAIN] = LupusecSystem(username, password, ip_address, name)
File "/usr/src/homeassistant/homeassistant/components/lupusec/__init__.py", line 81, in __init__
self.lupusec = lupupy.Lupusec(username, password, ip_address)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.lupusec_history_cache'

To make sure I have the right ip address, I logged in to my Lupus panel with the same credentials that I have in HA and that works.

majuss commented 1 year ago

Hm it seems like due to some HA update the user is now unable to write data to the disk. The lupusec history cache is needed to detect new alarm events. On HA core it works fine. I will install HA (without core) on one of my pis to test it.

For now you could get into the HA container and try to create this file for yourself with:

touch /root/.lupusec_history_cache
tomoqv commented 1 year ago

I have tried the above in both of my HA instances. Instance 1: Intel NUC running a supervised Docker installation Instance 2: RPi 4 running HAOS

Still getting the same error.

tomoqv commented 1 year ago

New HA update today, still no cigar unfortunately.

majuss commented 1 year ago

Next PR should fix it: https://github.com/home-assistant/core/pull/83765

tomoqv commented 1 year ago

Excellent, thanks!

tomoqv commented 1 year ago

I can confirm that it is working again!