DCSBL / ha-homewizard-energy

The old custom Home Assistant integration for HomeWizard Energy. This integration is now available in Core.
https://community.home-assistant.io/t/custom-component-homewizard-energy-wifi-p1-meter-and-kwh-meter/227441
Apache License 2.0
26 stars 3 forks source link

Integration no longer working “ AttributeError: module 'aiohwenergy' has no attribute 'AioHwEnergyException'” #60

Closed dieugab closed 2 years ago

dieugab commented 2 years ago

Describe the bug

Integration suddenly stopped working, with the error “AttributeError: module 'aiohwenergy' has no attribute 'AioHwEnergyException'”

Environment (please complete the following information)

To Reproduce

  1. Go to 'Integrations'
  2. HomeWizard is automatically discovered
  3. Setup integration
  4. See error

Expected behavior

Entities to be loaded in and working

Screenshots

063F350C-0B9D-441F-A031-8B4879ADF581

Log Output

Traceback (most recent call last):
  File "/config/custom_components/homewizard_energy/config_flow.py", line 48, in async_step_user
    await energy_api.initialize()
  File "/usr/local/lib/python3.9/site-packages/aiohwenergy/hwenergy.py", line 48, in initialize
    status = await self.device.update()
  File "/usr/local/lib/python3.9/site-packages/aiohwenergy/device.py", line 67, in update
    status, response = await self._request("get", "api")
  File "/usr/local/lib/python3.9/site-packages/aiohwenergy/hwenergy.py", line 111, in request
    async with self._clientsession.request(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 1117, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 544, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 890, in start
    message, payload = await self._protocol.read()  # type: ignore
  File "/usr/local/lib/python3.9/site-packages/aiohttp/streams.py", line 604, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 89, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 63, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 109, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 202, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/homewizard_energy/config_flow.py", line 58, in async_step_user
    except aiohwenergy.AioHwEnergyException:
AttributeError: module 'aiohwenergy' has no attribute 'AioHwEnergyException'

Additional context

P1 is working fine in the app and shows it’s connected and displays new data

DCSBL commented 2 years ago

Thanks. I think you found an actual bug that is triggered by an issue on your side. I suspect that the P1 meter is unreachable (see aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected).

This can be caused by a changed IP address (it should fix itself if you use mDNS), changes in your router or that the API is somehow broken. Can you check if you can reach the API at http://<ip_address/api?

You also can try to remove and re-add the P1 meter. It is safe to to this as long as you use the same name (and therefor the same entity_id's).

I will look into the bug at a later moment

dieugab commented 2 years ago

Thanks for the reply @DCSBL! I removed and added the integration, which didn't work. So I tried accessing it's API like you said which also resulted in a "not found message". Weird, considering the IP address hadn't changed. However, unplugging the P1 meter and plugging it back in did the trick! You can close this one

DCSBL commented 2 years ago

Good to know! Weird.

Still the integration should handle this situation more gracefully. I will leave this open until i’ve added a fix for that.

jeffreybrits commented 2 years ago

@DCSBL I second the error above... I just installed the P1 meter over the weekend and it stopped working today. Not sure how to solve this

DCSBL commented 2 years ago

The error AttributeError: module 'aiohwenergy' has no attribute 'AioHwEnergyException should be fixed in 0.11.0-beta-1 (released a few minutes ago. Please install and check this for me.

This error was triggered by something that causes the aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected exception. Sometimes this has to do with the API that stops responding, an issue that is under investigation. Try to powercycle your P1 meter to see if all goes back online. This issue can occour more often when you have an unstable wi-fi connection and/or multiple devices are using the API, please let me know if any of this is true at your side.

DCSBL commented 2 years ago

Fixed in 0.11.0