zachi40 / home-assistant-mycodo

This repository contains the custom integration for the Mycodo App with Home Assistant. It allows users to monitor and control their Mycodo devices through Home Assistant.
5 stars 0 forks source link

Error while setting up mycodo_app platform for sensor #2

Closed Obelix3000 closed 1 month ago

Obelix3000 commented 2 months ago

Logger: homeassistant.components.sensor Quelle: helpers/entity_platform.py:366 Integration: Sensor (Dokumentation, Probleme) Erstmals aufgetreten: 08:49:02 (3 Vorkommnisse) Zuletzt protokolliert: 08:53:33

Error while setting up mycodo_app platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 366, in _async_setup_platform await asyncio.shield(awaitable) File "/config/custom_components/mycodo_app/sensor.py", line 45, in async_setup_entry data = await hass.async_add_executor_job( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/mycodo_app/utils.py", line 61, in get_sensor_data if not respose.get("value"): ^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'

Obelix3000 commented 2 months ago

After update, non of the inputs is getting installed by integration, only outputs.

zachi40 commented 2 months ago

I need you to run the following commands:

curl -X 'GET' \
  'https://<mycodo_ip>/api/inputs/' \
  -H 'accept: application/vnd.mycodo.v1+json' \
  -H 'X-API-KEY: <api_code>'
curl -X 'GET' \
  'https://<mycodo_ip>/api/inputs/<unique_id>' \
  -H 'accept: application/vnd.mycodo.v1+json' \
  -H 'X-API-KEY: <api_code>'
kizniche commented 2 months ago

I noticed in the latest release that there's a hardcoded channel of 0:

https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L59 https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L64 https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L82

Each input or output can have multiple channels. Just thought I'd mention it.

zachi40 commented 2 months ago

Yes, I know, but by default, I only take the first one, Do you think I need to take all?

kizniche commented 2 months ago

I'm not familiar with how the software operates, I just saw hard-coded channels and pointed it out. If you only ever need channel 0, then I suppose it is fine.

zachi40 commented 2 months ago

I noticed in the latest release that there's a hardcoded channel of 0:

https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L59

https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L64

https://github.com/zachi40/home-assistant-mycodo/blob/29c9d1899d8b5e1a6b8a675dabe1ef77e2ee6d01/custom_components/mycodo_app/utils.py#L82

Each input or output can have multiple channels. Just thought I'd mention it. @kizniche I am working on adding channels as you mentioned above. Could you provide an example of how to include channels in the output so I can see them as well?

zachi40 commented 2 months ago

@kizniche There is a bug in the system. The system returns a success message even though the operation failed to activate the button. Please see the message that popped up in the picture. image

kizniche commented 2 months ago

Could you provide an example of how to include channels in the output so I can see them as well?

I'm not sure what you mean. Each Input or Output module has the channels defined and they can be specified by the API.

There is a bug in the system. The system returns a success message even though the operation failed to activate the button.

The UI doesn't receive a status code from the state change function in an output module, it merely prints the return string it receives. In this case, it is giving you an error in that return string. It did successfully communicate with the output module to call a function, the module itself appears to have an issue in some way and you'll have to treat issues like that on a case-by-case basis since the code found in modules are unique.

kizniche commented 2 months ago

I just noticed it appears you're overwriting a previously-defined function:

https://github.com/zachi40/home-assistant-mycodo/blob/54145df6e09f437e2bde3d1211bcdcacab838b78/custom_components/mycodo_app/sensor.py#L145-L153

zachi40 commented 2 months ago

Yes, I updated my code to support the input-output channel, @Obelix3000, please update to the latest version of the extension, and tell me if you have more problems. thank you

Obelix3000 commented 2 months ago

Now i get these errors:

Logger: custom_components.mycodo_app.sensor
Quelle: custom_components/mycodo_app/sensor.py:19
Integration: MyCodo App (Dokumentation, Probleme)
Erstmals aufgetreten: 20:49:33 (3 Vorkommnisse)
Zuletzt protokolliert: 20:49:33

Failed to fetch sensors from Mycodo.
Logger: custom_components.mycodo_app.utils
Quelle: custom_components/mycodo_app/utils.py:47
Integration: MyCodo App (Dokumentation, Probleme)
Erstmals aufgetreten: 20:49:33 (6 Vorkommnisse)
Zuletzt protokolliert: 20:49:33

Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85c770>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85e840>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/inputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/inputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b8554f0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/inputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/inputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85e3c0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85d580>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
zachi40 commented 2 months ago

Now i get these errors:

Logger: custom_components.mycodo_app.sensor
Quelle: custom_components/mycodo_app/sensor.py:19
Integration: MyCodo App (Dokumentation, Probleme)
Erstmals aufgetreten: 20:49:33 (3 Vorkommnisse)
Zuletzt protokolliert: 20:49:33

Failed to fetch sensors from Mycodo.
Logger: custom_components.mycodo_app.utils
Quelle: custom_components/mycodo_app/utils.py:47
Integration: MyCodo App (Dokumentation, Probleme)
Erstmals aufgetreten: 20:49:33 (6 Vorkommnisse)
Zuletzt protokolliert: 20:49:33

Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85c770>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85e840>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/inputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/inputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b8554f0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/inputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/inputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85e3c0>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
Exception when making HTTP request to http://192.168.178.32/api/outputs: HTTPConnectionPool(host='192.168.178.32', port=80): Max retries exceeded with url: /api/outputs (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f6b85d580>: Failed to establish a new connection: [Errno 113] Host is unreachable'))

@Obelix3000, It seems the application didn't run properly. Please check if you can connect to it from the browser. Meanwhile, try deleting the extension and adding it again.

Obelix3000 commented 2 months ago

Holy moly, after redownloading the extension everything worked fine. Thank you so much for your effort! Will add now every Mycodo unit to HA and give you updates if there are any.