mjoshd / hyperhdr-ha

HyperHDR custom component for Home Assistant
https://github.com/awawa-dev/HyperHDR
MIT License
56 stars 7 forks source link

Installation fails with "error" #13

Closed dawiinci closed 2 years ago

dawiinci commented 2 years ago

Version of the custom_component

0.0.6

Tested with HyperHDR 17.0.0.0 and 18.0.0.0b2

Configuration

I just wanted to add the integration in the frontend, but it fails to configure.

Describe the bug

I can get a token which is shown in HyperHDR but in the next step the integration just shows "error".

Logs

Logger: aiohttp.server
Source: custom_components/hyperhdr/config_flow.py:401 
Integration: HyperHDR (documentation, issues) 
First occurred: 14:58:16 (2 occurrences) 
Last logged: 14:59:28

Error handling request
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 540, in readline
    line = await self.readuntil(sep)
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 635, in readuntil
    raise exceptions.LimitOverrunError(
asyncio.exceptions.LimitOverrunError: Separator is found, but chunk is longer than limit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/server/homeassistant/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/config/config_entries.py", line 205, in post
    return await super().post(request, flow_id)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/data_entry_flow.py", line 109, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/data_entry_flow.py", line 260, in async_configure
    result = await self._async_handle_step(
  File "/Users/server/homeassistant/lib/python3.9/site-packages/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/Users/server/homeassistant-config/custom_components/hyperhdr/config_flow.py", line 234, in async_step_user
    return await self._advance_to_auth_step_if_necessary(
  File "/Users/server/homeassistant-config/custom_components/hyperhdr/config_flow.py", line 141, in _advance_to_auth_step_if_necessary
    return await self.async_step_confirm()
  File "/Users/server/homeassistant-config/custom_components/hyperhdr/config_flow.py", line 401, in async_step_confirm
    async with self._create_client() as hyperhdr_client:
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 149, in __aenter__
    result = await self.async_client_connect()
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 369, in async_client_connect
    await self.async_client_disconnect()
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 422, in async_client_disconnect
    return await self._async_client_disconnect_internal()
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 451, in _async_client_disconnect_internal
    await self._await_or_stop_task(receive_task, stop_task=True)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 588, in _await_or_stop_task
    await task
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 568, in _receive_task_loop
    while await self._async_receive_once():
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 608, in _async_receive_once
    resp_json = await self._async_safely_read_command(use_timeout=False)
  File "/Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py", line 485, in _async_safely_read_command
    resp = await asyncio.wait_for(future_resp, timeout=timeout_secs)
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
    return await fut
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/streams.py", line 549, in readline
    raise ValueError(e.args[0])
ValueError: Separator is found, but chunk is longer than limit
mjoshd commented 2 years ago

Hi.

Sorry, but I do not understand what you are referring to with a 'token'. Perhaps if you explain to me, in detail, how to replicate your issue then I can try to be of more help.

I have set up many test instances of both HyperHDR and Home Assistant (along with the integration) and all I have ever needed to connect them is the ip address of the HyperHDR instance; I have never needed a token before.

For a simple setup guide, please follow the steps in the wiki.

dawiinci commented 2 years ago

Under Token management inside Network services are entries from Home Assistant. They are made by going to hyperhdr frontend. This is probably an automatic feature of HA.

I have these settings enabled:

Mainly because it wasn't working without that. Should I configure using yaml? If so, how?

mjoshd commented 2 years ago

Thank you for the explanation of how you are setting up tokens.

I have never used tokens before and I was able to do some testing today however I was unable to replicate the error shown in your logs.

I typically use the default settings shown below: image

I discovered that the tokens are required after "Local API Authentication" is enabled. After enabling Local API Authentication and clicking save I set up the integration in two different ways

image

Both attempts were successful.

The only way I was able to force a failure during the setup was to block HyperHDR from communicating using the firewall of the system it is running on. This did cause the setup to fail but resulted in a very different Home Assistant log message: 2022-05-12 14:59:52 WARNING (MainThread) [hyperhdr.client] Failed HyperHDR (192.168.41.41:19444) command: {'command': 'sysinfo', 'error': 'No Authorization', 'success': False, 'tan': 1}

Afterward, I removed the block in the firewall then went through setup again and it worked without issue.

The only things I can think of for you to check and/or try are:

mjoshd commented 2 years ago

Sorry, forgot to answer your last question in my long reply. There is not a way to set up the integration using yaml.

dawiinci commented 2 years ago

Thanks. It is, however, still not working.

Logger: hyperhdr.client
Source: /Users/server/homeassistant/lib/python3.9/site-packages/hyperhdr/client.py:624 
First occurred: 20:17:34 (7 occurrences) 
Last logged: 20:18:40

Failed HyperHDR (localhost:19444) command: {'command': 'authorize', 'error': 'Errors during specific message validation, please consult the HyperHDR Log', 'success': False, 'tan': 1}
Failed HyperHDR (localhost:19444) command: {'command': 'authorize-requestToken', 'error': 'Token request timeout or denied', 'success': False, 'tan': 1}
mjoshd commented 2 years ago

I see the IP address you entered was actually a hostname? e.g. localhost

What device are you using to host HyperHDR?

dawiinci commented 2 years ago

I am on macOS. And I tried the ip as well.

mjoshd commented 2 years ago

What is your Home Assistant running on?

I still think something on the HyperHDR host (your mac) is blocking communications.

As a fairly simple test, please try setting up the HyperHDR addon in Home Assistant and connecting my integration to it. I just now tested setting up my integration with that addon and it worked perfectly.

After installing and starting the addon visit its webpage to make sure it is running but don't change any settings, then set up my integration (manual setup is fine for a 1-off test) and just provide the LAN IP address of your Home Assistant instance.

If the test works then it points to your mac as being the source of the communication issue. I do not have a mac so I don't know how to help further with that.

If the test doesn't work then it points to something in your Home Assistant configuration as the culprit and I would ask that you follow the instructions to set up a fresh Virtual Machine of Home Assistant OS (don't import a backup, just set it up as basic as possible) then install the HyperHDR addon linked above and set up my integration to verify connectivity/functionality.

These tests should help to narrow down where the issue may be coming from; please let me know the results.

If all of the above tests still fail then I'm not sure how to be of further help as I cannot reproduce a setup failure without intentionally blocking communication between Home Assistant and HyperHDR.

dawiinci commented 2 years ago

Everything is running on the same Mac. I use Core (python venv) installation, so the addon can’t be used.

Thanks for your help though.