ckarrie / ckw-ha-gs108e

HomeAssistant Netgear Switch Integration
18 stars 6 forks source link

Can't start using the integration. Exception Raised and HA doesn't start #6

Closed degrammont closed 1 year ago

degrammont commented 1 year ago

Hello, Tested with 2 HA deploiement (one with an HA container in Docker, one on Raspberry Pi using HA OS with only this integration) with the same error. GS108Ev3 Firmware Version V2.06.16EN Here is the stack. Thanks for your help.

2022-11-21 15:51:37.722 ERROR (MainThread) [homeassistant] Error doing job: unhandled exception during shutdown
Traceback (most recent call last):
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 54, in get_switch_infos
    f = open(cookie_dir + '/.gs108ecookie' + switch_ip, 'r')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.gs108ecookie192.168.1.58'
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 243, in async_setup_platform
    await self._platforms[key].async_setup(platform_config, discovery_info)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 224, in async_setup
    await self._async_setup_platform(async_create_setup_task)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ckw_hass_gs108e/sensor.py", line 58, in setup_platform
    switch_infos = get_switch_infos(switch_ip=host, switch_password=password)
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 65, in get_switch_infos
    exit(1)
  File "/usr/local/lib/python3.10/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/scrape/sensor.py", line 111, in async_setup_platform
    raise PlatformNotReady
homeassistant.exceptions.PlatformNotReady: None
2022-11-21 15:51:37.829 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139656981357728] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 54, in get_switch_infos
    f = open(cookie_dir + '/.gs108ecookie' + switch_ip, 'r')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.gs108ecookie192.168.1.58'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 243, in async_setup_platform
    await self._platforms[key].async_setup(platform_config, discovery_info)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 224, in async_setup
    await self._async_setup_platform(async_create_setup_task)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ckw_hass_gs108e/sensor.py", line 58, in setup_platform
    switch_infos = get_switch_infos(switch_ip=host, switch_password=password)
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 65, in get_switch_infos
    exit(1)
  File "/usr/local/lib/python3.10/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 358, in handle_get_services
    descriptions = await async_get_all_descriptions(hass)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 473, in async_get_all_descriptions
    contents = await hass.async_add_executor_job(
  File "/usr/src/homeassistant/homeassistant/core.py", line 517, in async_add_executor_job
    task = self.loop.run_in_executor(None, target, *args)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 811, in run_in_executor
    self._check_default_executor()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 519, in _check_default_executor
    raise RuntimeError('Executor shutdown has been called')
RuntimeError: Executor shutdown has been called
2022-11-21 15:51:37.964 ERROR (MainThread) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-11-21 15:51:38.001 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139656981357728] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 54, in get_switch_infos
    f = open(cookie_dir + '/.gs108ecookie' + switch_ip, 'r')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.gs108ecookie192.168.1.58'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 243, in async_setup_platform
    await self._platforms[key].async_setup(platform_config, discovery_info)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 224, in async_setup
    await self._async_setup_platform(async_create_setup_task)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ckw_hass_gs108e/sensor.py", line 58, in setup_platform
    switch_infos = get_switch_infos(switch_ip=host, switch_password=password)
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 65, in get_switch_infos
    exit(1)
  File "/usr/local/lib/python3.10/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 312, in async_get_translations
    cached = await cache.async_fetch(language, category, components)
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/frontend/__init__.py", line 679, in websocket_get_translations
    resources = await async_get_translations(
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 307, in async_get_translations
    async with lock:
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 20, in __aexit__
    self.release()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 138, in release
    self._wake_up_first()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 155, in _wake_up_first
    fut.set_result(True)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 750, in call_soon
    self._check_closed()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
2022-11-21 15:51:38.067 ERROR (MainThread) [homeassistant] Error doing job: Task was destroyed but it is pending!
2022-11-21 15:51:38.069 ERROR (MainThread) [homeassistant] Error doing job: _GatheringFuture exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 54, in get_switch_infos
    f = open(cookie_dir + '/.gs108ecookie' + switch_ip, 'r')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/.gs108ecookie192.168.1.58'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 633, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 600, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1896, in _run_once
    handle._run()
  File "/usr/local/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 243, in async_setup_platform
    await self._platforms[key].async_setup(platform_config, discovery_info)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 224, in async_setup
    await self._async_setup_platform(async_create_setup_task)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/ckw_hass_gs108e/sensor.py", line 58, in setup_platform
    switch_infos = get_switch_infos(switch_ip=host, switch_password=password)
  File "/config/custom_components/ckw_hass_gs108e/utils.py", line 65, in get_switch_infos
    exit(1)
  File "/usr/local/lib/python3.10/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/translation.py", line 179, in async_get_component_strings
    load_translations_job = hass.async_add_executor_job(
  File "/usr/src/homeassistant/homeassistant/core.py", line 517, in async_add_executor_job
    task = self.loop.run_in_executor(None, target, *args)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 811, in run_in_executor
    self._check_default_executor()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 519, in _check_default_executor
    raise RuntimeError('Executor shutdown has been called')
RuntimeError: Executor shutdown has been called
2022-11-21 15:52:03.023 ERROR (Thread-5 (_thread_main)) [paho.mqtt.client] Caught exception in on_message: Event loop is closed
2022-11-21 15:52:03.029 ERROR (Thread-5 (_thread_main)) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/client.py", line 613, in _mqtt_on_message
    self.hass.add_job(self._mqtt_handle_message, msg)
  File "/usr/src/homeassistant/homeassistant/core.py", line 386, in add_job
    self.loop.call_soon_threadsafe(self.async_add_job, target, *args)
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 795, in call_soon_threadsafe
    self._check_closed()
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
el97 commented 1 year ago

I'm experiencing similar issues.

mwurth commented 1 year ago

+1 Unfortunately I am unable to get logs because HA is not reachable anymore if the sensor is configured. Is this an issue with newer Switch firmware versions? Which is the last known working version?

MrPePperNL commented 1 year ago

I tried this component also some time ago. Was not working for both my gs110tpv3 switches with firmware 7.0.9.5. Same after HA restart unable to open HA and massive errors in logs (looking as same error here).

What I think is happening : the component tries to get a login cookie when opening http://-switchip-/login.cgi. But at my switches this isnot working as it is using html auth and not cgi.

Manually entering http://-switchip-/login.cgi redirects me to the html login page.

So either we need to find the correct cgi file for login, or the component needs to be rewritten to use html auth.

Sorry but cannot help getting neither of them as I'm not a programmer.

ckarrie commented 1 year ago

I'll take a look into it. However HA starts for me with this integration (Home Assistant 2022.12.9)

ckarrie commented 1 year ago

Looks like your HomeAssistant environment does not have a temp filesystem, I will change that.

ckarrie commented 1 year ago

I removed the tempfile in 166e736a531547e04358a50e63008174ba781029 Could you check if it works now?

Tested it with

cd src/ckw-ha-gs108e/custom_components/ckw_hass_gs108e
python
import utils
utils.get_switch_infos("192.168.178.5", "password")

Results

{'switch_ip': '192.168.178.5', 'response_time_s': 0.9566987780272029, 'ports': [{'port_nr': 1, 'port_name': 'Port 0', 'traffic_rx_bytes': 0, 'traffic_tx_bytes': 0, 'speed_rx_bytes': 0, 'speed_tx_bytes': 0, 'speed_io_bytes': 0, 'crc_errors': 0}, {'port_nr': 2, 'port_name': 'Port 1', 'traffic_rx_bytes': 52986, 'traffic_tx_bytes': 2187785, 'speed_rx_bytes': 55384, 'speed_tx_bytes': 2286806, 'speed_io_bytes': 2342190, 'crc_errors': 0}, {'port_nr': 3, 'port_name': 'Port 2', 'traffic_rx_bytes': 16849, 'traffic_tx_bytes': 36856, 'speed_rx_bytes': 17611, 'speed_tx_bytes': 38524, 'speed_io_bytes': 56135, 'crc_errors': 0}, {'port_nr': 4, 'port_name': 'Port 3', 'traffic_rx_bytes': 0, 'traffic_tx_bytes': 0, 'speed_rx_bytes': 0, 'speed_tx_bytes': 0, 'speed_io_bytes': 0, 'crc_errors': 0}, {'port_nr': 5, 'port_name': 'Port 4', 'traffic_rx_bytes': 0, 'traffic_tx_bytes': 3234, 'speed_rx_bytes': 0, 'speed_tx_bytes': 3380, 'speed_io_bytes': 3380, 'crc_errors': 0}, {'port_nr': 6, 'port_name': 'Port 5', 'traffic_rx_bytes': 352, 'traffic_tx_bytes': 3298, 'speed_rx_bytes': 367, 'speed_tx_bytes': 3447, 'speed_io_bytes': 3814, 'crc_errors': 0}, {'port_nr': 7, 'port_name': 'Port 6', 'traffic_rx_bytes': 2223710, 'traffic_tx_bytes': 81190, 'speed_rx_bytes': 2324357, 'speed_tx_bytes': 84864, 'speed_io_bytes': 2409221, 'crc_errors': 0}, {'port_nr': 8, 'port_name': 'Port 7', 'traffic_rx_bytes': 0, 'traffic_tx_bytes': 0, 'speed_rx_bytes': 0, 'speed_tx_bytes': 0, 'speed_io_bytes': 0, 'crc_errors': 0}], 'sum_port_traffic_rx': 2293897, 'sum_port_traffic_tx': 2312363, 'sum_port_traffic_crc_err': 0, 'sum_port_speed_bps_rx': 2397719, 'sum_port_speed_bps_tx': 2417021, 'sum_port_speed_bps_io': 4814740}
el97 commented 1 year ago

With the latest version I get the following error "Platform error sensor.ckw_hass_gs108e - Integration 'lxml' not found."

degrammont commented 1 year ago

I confirm the same error for me with the new tag. Seems related to the new manifest.json file.

ckarrie commented 1 year ago

I fixed that

degrammont commented 1 year ago

In the log I can see "The ckw_hass_gs108e platform for the sensor integration does not support platform setup. Please remove it from your config". I think it is normal as the CKW GS108e Integration is now available with a UI setup.

However when I enter IP and password I get the following error: "Connection or login error: please check your configuration" (I verified both IP and password several times using a direct connection to the switch). I don't know how to get additional logs.

ckarrie commented 1 year ago

Which Firmware version? I'm using 2.00.05

image

ckarrie commented 1 year ago

And yes, setup via configuration.yaml isn't supported any more.

el97 commented 1 year ago

I get the same error as @degrammont. The latest firmware version is 2.06.17 which is also the one I use. If it's possible you should upgrade to the latest since it covers security vulnerabilities. You can download the latest one here.

ckarrie commented 1 year ago

I figured it out with 2.06.17, passwords gets encrypted on the frontend before transmitted to the switch. For a quick fix, open your Browser Developer Console and look for login.cgi when entering the password and submitting the form. Use the generated password in the integration.

image

ckarrie commented 1 year ago

The encryption is done in http://192.168.178.8/login.js?v1.10

function encryptPwd(){
    var password = document.getElementById("password").value;
    var randNum  = document.getElementById("rand").value;
    var resultStr = merge(password,randNum);
    document.getElementById("submitPwd").value = md5(resultStr);
}
degrammont commented 1 year ago

Thanks for your help. Now with the encrypted password I can create the integration but all sensors give an "Unknown" status (except IP Address and Reponse Time).

image

ckarrie commented 1 year ago

Yes, i'm aware of that. The new firmware changed the structure of portStatistics.cgi too, I'm working on this

ckarrie commented 1 year ago

Reworked again , please test again. Thank you all for testing <3

Attention!!!

Please remove the switches you added with the hashed/encrypted password and re-add them with the real password (see https://github.com/ckarrie/ckw-ha-gs108e/issues/6#issuecomment-1373418905)

degrammont commented 1 year ago

Tested succesfully on the Raspberry Pi (using HA OS 2023.1.0) I'm using for test, but I got the following error with an HA docker container on my NAS (2022.12.1).

"Unable to prepare setup for platform ckw_hass_gs108e.sensor: Platform not found (cannot import name 'UnitOfDataRate' from 'homeassistant.const' (/usr/src/homeassistant/homeassistant/const.py)). and I can't see any entity.

image

ckarrie commented 1 year ago

Unfortunately it only works with Home Assistant 2023.1.0 at the moment, I can spent some time for backwards compatibility

el97 commented 1 year ago

I did a test with the latest version and it worked with 2023.1.1 for me.

ckarrie commented 1 year ago

I close this issue for now, thanks for all the tests.