hardbyte / ha-evnex

A cloud-polling Home Assistant component to integrate with an Evnex Charger
MIT License
12 stars 1 forks source link

Evnex charger not available in 2024.6 #36

Open sydney2711 opened 5 months ago

sydney2711 commented 5 months ago

Hello

2024.5.5 and the charger was working fine 2024.6 and I get this error log:

This error originated from a custom integration.

############### Logger: custom_components.evnex Source: custom_components/evnex/init.py:185 integration: Evnex EV Charger (documentation, issues) First occurred: 09:53:27 (5 occurrences) Last logged: 09:54:40

Unhandled exception while updating evnex info Traceback (most recent call last): File "/config/custom_components/evnex/init.py", line 185, in async_update_data for connector_brief in charge_point_detail.connectors: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'connectors'

#################

I hope there is a way to fix this issue because the charger is one of my most important device in home assistant.

colinjgibbs commented 5 months ago

Exactly the same issue here. Was fine on 2024.5 versions.

drc38 commented 5 months ago

I expect the root cause of it failing in 2024.6.0 are the HA warnings associated with blocking calls inside the event loop such as: with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf:

colinjgibbs commented 5 months ago

Happy to test if you would like me to.

The-Organist commented 5 months ago

Somewhat novice, but does this pull request mean that we don’t have to individually do anything - it just fixes at some point?

colinjgibbs commented 5 months ago

@The-Organist - typically a pull request is asking for collaborators on the code (in this case hardbyte) to review and comment on the changes. Highly likely this will fix the problem when released.

sydney2711 commented 5 months ago

Just updated core to 2024.6.2 I get basically the same error just the name of the python file that causes the problem has changed

####################

The-Organist commented 5 months ago

after EVNEX package update installed:

Logger: homeassistant.util.package Source: util/package.py:123 First occurred: 6:51:23 AM (3 occurrences) Last logged: 6:51:39 AM

Unable to install package evnex>=0.4.1: ERROR: Cannot install evnex==0.4.1 because these package versions have conflicting dependencies. ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

drc38 commented 5 months ago

If you stick with pydantic v1 (HA default) and downgrade to evnex v0.5.3 then you should be fine. Other option is to force install pydantic v2 and use v0.6 pre-releases but other integrations may have problems if they still use v1

sultanoswing commented 5 months ago

then you should be fine.

Nope. Downgraded to 0.53 (by pulling the code then copying across to my HA's custom_components folder using WinSCP). The integration starts, asks for my Evnex login, which appears successful (my real name pops up), but it still fails to start. The logs now show:

`Logger: homeassistant.util.loop Source: util/loop.py:84 First occurred: 12:22:15 (24 occurrences) Last logged: 12:27:36

Detected blocking call to open inside the event loop by custom integration 'evnex' at custom_components/evnex/init.py, line 55: with open(file, "r") as spf: (offender: /config/custom_components/evnex/init.py, line 55: with open(file, "r") as spf:), please create a bug report at https://github.com/hardbyte/ha-evnex/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, request.match_info) File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin return await func(self, request, *args, *kwargs) File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 70, in wrapper return await method(view, request, data, args, kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure result = await self._async_configure(flow_id, user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 572, in _async_handle_step result = await self.async_finish_flow(flow, result.copy()) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1403, in async_finish_flow await self.config_entries.async_add(entry) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1708, in async_add await self.async_setup(entry.entry_id) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1819, in async_setup await entry.async_setup(self.hass) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/evnex/init.py", line 263, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh await self._async_refresh( File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_update_data return await self.update_method() File "/config/custom_components/evnex/init.py", line 150, in async_update_data persist_evnex_auth_tokens( File "/config/custom_components/evnex/init.py", line 55, in persist_evnex_auth_tokens with open(file, "r") as spf: Detected blocking call to open inside the event loop by custom integration 'evnex' at custom_components/evnex/init.py, line 67: with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf: (offender: /config/custom_components/evnex/init.py, line 67: with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf:), please create a bug report at https://github.com/hardbyte/ha-evnex/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, *self._args) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, request.match_info) File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin return await func(self, request, *args, *kwargs) File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 70, in wrapper return await method(view, request, data, args, kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 368, in async_configure result = await self._async_configure(flow_id, user_input) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 572, in _async_handle_step result = await self.async_finish_flow(flow, result.copy()) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1403, in async_finish_flow await self.config_entries.async_add(entry) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1708, in async_add await self.async_setup(entry.entry_id) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1819, in async_setup await entry.async_setup(self.hass) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/evnex/init.py", line 263, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh await self._async_refresh( File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_update_data return await self.update_method() File "/config/custom_components/evnex/init.py", line 150, in async_update_data persist_evnex_auth_tokens( File "/config/custom_components/evnex/init.py", line 67, in persist_evnex_auth_tokens with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf: Detected blocking call to open inside the event loop by custom integration 'evnex' at custom_components/evnex/init.py, line 78: with open(file, "r") as spf: (offender: /config/custom_components/evnex/init.py, line 78: with open(file, "r") as spf:), please create a bug report at https://github.com/hardbyte/ha-evnex/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, self._args) File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1510, in _run_async_call_action hass.async_run_hass_job(job, time_tracker_utcnow()) File "/usr/src/homeassistant/homeassistant/core.py", line 936, in async_run_hass_job hassjob.target(args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 720, in _async_setup_again hass.async_create_background_task( File "/usr/src/homeassistant/homeassistant/core.py", line 860, in async_create_background_task task = create_eagertask(target, name=name, loop=self.loop) File "/usr/src/homeassistant/homeassistant/util/async.py", line 37, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/evnex/init.py", line 104, in async_setup_entry evnex_auth_tokens = retrieve_evnex_auth_tokens(hass, entry) File "/config/custom_components/evnex/init.py", line 78, in retrieve_evnex_auth_tokens with open(file, "r") as spf: Detected blocking call to open inside the event loop by custom integration 'evnex' at custom_components/evnex/init.py, line 55: with open(file, "r") as spf: (offender: /config/custom_components/evnex/init.py, line 55: with open(file, "r") as spf:), please create a bug report at https://github.com/hardbyte/ha-evnex/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/evnex/init.py", line 263, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh await self._async_refresh( File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_update_data return await self.update_method() File "/config/custom_components/evnex/init.py", line 150, in async_update_data persist_evnex_auth_tokens( File "/config/custom_components/evnex/init.py", line 55, in persist_evnex_auth_tokens with open(file, "r") as spf: Detected blocking call to open inside the event loop by custom integration 'evnex' at custom_components/evnex/init.py, line 67: with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf: (offender: /config/custom_components/evnex/init.py, line 67: with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf:), please create a bug report at https://github.com/hardbyte/ha-evnex/issues Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in sys.exit(main()) File "/usr/src/homeassistant/homeassistant/main.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run self._context.run(self._callback, self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 742, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 594, in async_setup result = await component.async_setup_entry(hass, self) File "/config/custom_components/evnex/init.py", line 263, in async_setup_entry await coordinator.async_config_entry_first_refresh() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 277, in async_config_entry_first_refresh await self._async_refresh( File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh self.data = await self._async_update_data() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 268, in _async_update_data return await self.update_method() File "/config/custom_components/evnex/init.py", line 150, in async_update_data persist_evnex_auth_tokens( File "/config/custom_components/evnex/init.py", line 67, in persist_evnex_auth_tokens with open(os.open(file, os.O_CREAT | os.O_WRONLY, 0o600), "w") as spf:`

drc38 commented 5 months ago

You can include https://github.com/hardbyte/ha-evnex/commit/623b9da56c1317da93e1fdfc2317f3c202acb8c4 to get rid of blocking errors. But the warnings should not prevent the integration working.

sultanoswing commented 5 months ago

Thanks - that update got rid of those errors, now just the previous:

Logger: custom_components.evnex Source: custom_components/evnex/init.py:186 integration: Evnex EV Charger (documentation, issues) First occurred: 13:42:30 (3 occurrences) Last logged: 13:43:00

Unhandled exception while updating evnex info Traceback (most recent call last): File "/config/custom_components/evnex/init.py", line 186, in async_update_data for connector_brief in charge_point_detail.connectors: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'connectors'

So - following the log errors, I commented out the following lines in init.py

         #           data["connector_brief"][
         #               (charge_point.id, connector_brief.connectorId)
         #           ] = connector_brief

_LOGGER.debug(

          #              f"Getting evnex charge point override for '{charge_point.name}'"
          #          )
          #          charge_point_override: EvnexChargePointOverrideConfig = (
          #              await evnex_client.get_charge_point_override(
          #                  charge_point_id=charge_point.id
          #              )
          #          )
          #      else:
          #          _LOGGER.debug(
          #              "Not getting charge point override as charge point is not ONLINE"
          #          )
          #          charge_point_override = None

          #      data["charge_point_brief"][charge_point.id] = charge_point
          #      data["charge_point_details"][charge_point.id] = charge_point_detail
          #      data["charge_point_override"][
          #          charge_point.id
          #      ] = charge_point_override
          #      data["charge_point_sessions"][
          #          charge_point.id
          #      ] = charge_point_sessions

....and it worked!. I'm not sure how or why the above lines are causing errors, but at least I've got some functionality back.

drc38 commented 5 months ago

Pull a fresh HA image, the pydantic versions may have got messed up or make these changes https://github.com/hardbyte/ha-evnex/pull/38

sultanoswing commented 5 months ago

Pull a fresh HA

Since I run HAOS in a VM, it's a little more involved....but yes, I may look at a fresh install. At least with HAOS you can restore from a backup file, which, along with HACS, is the major advantage of HAOS as far as I can tell.

colinjgibbs commented 5 months ago

Have made the changes as per #38 and all working now. I'm on a RPi 4: Core 2024.6.4 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240610.1

zurnaik commented 4 months ago

Having the same error as the originally reported issue on 0.5.3. Integration configuration successfully authenticates to Evnex then retries indefinitely due to this unhandled exception with or without the patch #38. I can't test 0.6.x because a 500 Internal Server Error pops up instead of the Evnex username / password prompt.

I am running Home Assistant: 12.3 Home Assistant Core: 2024.7

Unhandled exception while updating evnex info Traceback (most recent call last): File "/config/custom_components/evnex/init.py", line 185, in async_update_data for connector_brief in charge_point_detail.connectors: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'connectors'

################

hardbyte commented 4 months ago

What version of Pydantic does your system have @zurnaik?

zurnaik commented 3 months ago

What version of Pydantic does your system have @zurnaik?

pydantic 1.10.17 pydantic_core 2.20.1

glasody commented 3 months ago

I have found a simple fix for those that are still using pydantic v1. Just replace these lines (L181-183) inside __init__.py with the below code then restart homeassistant.

charge_point_detail = EvnexChargePointDetail(
    **api_v3_response.data.attributes
)

I'm not a python developer so wasn't sure if this code is compatible with the latest versions of pydantic so I didn't submit a PR. Hope this helps others out there like me

The-Organist commented 3 months ago

This worked a treat, thank you. Now have control back again. Hopefully this is not something I have to adjust every time an update downloads?