hass-aarlo icon indicating copy to clipboard operation
hass-aarlo copied to clipboard

AttributeError: 'AarloFlowHandler' object has no attribute 'email'

Open msawyer91 opened this issue 2 years ago • 3 comments

First let me say I'm very appreciative of the community for building an Arlo connector for Home Assistant. It appears the "official" Arlo add-in is no longer maintained and it is not available in the Home Assistant store.

I have Home Assistant Container running on a Raspberry Pi 4. The Container installation doesn't officially support the Home Assistant Store, so I have to add integrations/add-ons manually or via HACS. I did also set up Home Assistant in a Hyper-V virtual machine. But, when it comes to Aarlo, I am encountering the issue of "AttributeError: 'AarloFlowHandler' object has no attribute 'email'".

I downloaded aarlo and deployed the aarlo folder into /custom_components, restarted HA, then updated /configuration.yaml to add the following entries:

aarlo: username: !secret arlo_username password: !secret arlo_password refresh_devices_every: 2 stream_timeout: 120 tfa_host: 'imap.gmail.com' tfa_username: !secret arlo_tfa_username tfa_password: !secret arlo_tfa_password reconnect_every: 90 stream_snapshot_stop: 0 save_media_to: "/config/www/arlo/${Y}/${m}/${d}/${T}"

I then made the following entries in secrets.yaml:

arlo_username: [email protected] arlo_password: mysupersecretpasswordstoredinplaintext arlo_tfa_username: [email protected] arlo_tfa_password: mysupersecretapplicationpasswordgooglecreatedforme

I restarted HA, then went to enable Arlo Camera Support. I am immediately prompted to enter my Arlo username and password, along with my TFA username, TFA password, and TFA host. I re-enter the same information, and am informed an unknown error was detected. Portainer allows me to see the container log, which reports:

2022-01-31 23:50:26 ERROR (MainThread) [aiohttp.server] Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, 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 98, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, 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 181, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 157, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 252, 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 325, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/aarlo/config_flow.py", line 42, in async_step_user title=f"${DOMAIN} - ${self.email}", data=info AttributeError: 'AarloFlowHandler' object has no attribute 'email'

I received the same error when I created an Arlo account using my Comcast email, which actually had 2FA enabled. My Gmail account doesn't have 2FA enabled, but Aarlo is requiring me to provide TFA details anyway.

Where have I made a boo-boo?

Matt

msawyer91 avatar Feb 01 '22 05:02 msawyer91

I dug into this a bit more today, since it was calling out line 42 in config_flow.py. I put a try/except block around line 42, so it now reads like:

        else:
            try:
                return self.async_create_entry(
                    title=f"${DOMAIN} - ${self.email}", data=info
                )
            except:
                print("Exceptions were detected by the Server.")
                return self.async_create_entry(
                    #title=f"${DOMAIN} - [email protected]", data=info
                    title="Arlo Cameras", data=info
                )

Restarted HA, got a new error. This one was "AttributeError: module 'custom_components.aarlo' has no attribute 'async_setup_entry'" Thankfully the search consultants of the Googlé were either on their game, or my query was good enough. I found the exact same error on another HA integration, duofern. Their fix? Add the following two lines to init.py:

         async def async_setup_entry(hass, entry):
           return True

Rebooted HA again. I had a few other small issues to work through, like remembering to grant Administrative rights to my Arlo HA account. But once I had done that, and added all necessary options to my configuration.yaml file, I saw my cameras and was able to test out the siren which earned me snarky feedback from my daughter. :)

So overall I think I'm good to go! I'm not sure if what I did to config_flow.py was the most appropriate course of action; I just wanted to see if I could get past the error, and it worked. I'll leave it to your team to determine the best long-term strategy. It would seem, however, that HA does want to see the call to async_setup_entry in the init.py though.

Matt

msawyer91 avatar Feb 01 '22 20:02 msawyer91

Well done on getting 0.8 going! That stream is still very experimental and - truthfully - I haven't had much time to look at it recently. Thanks for the fix, it's noted and I'll probably use it when I get round to testing the release here.

If 0.8 is working for you then great. But the official release is the 0.7 stream.

twrecked avatar Feb 03 '22 13:02 twrecked

Thank you for the feedback! And thank you for putting this project together! You've done a really nice job on it. Overall I think 0.8 is working pretty well, but I noticed that after 3-4 hours the cameras all become unavailable, and the container log in Portainer (I'm using HA Container) shows entries like this:

2022-02-03 10:01:00 ERROR (ArloBackgroundWorker) [pyaarlo] failed to read modes (v2) 2022-02-03 10:04:00 WARNING (ArloBackgroundWorker) [pyaarlo] No devices returned from /hmsweb/v2/users/devices?t=1643900640180 2022-02-03 10:11:00 ERROR (ArloBackgroundWorker) [pyaarlo] failed to read modes (v2)

I also noticed that HA has a notification showing Arlo authentication has failed.

I don't know Python well enough to try wiring in a "fix" to catch for this error and trigger a reauthentication. I can fix the problem by restarting HA. Within 30 seconds I'll see a fresh 2FA email in my Gmail, and then Aarlo will be good for a few more hours. The fact that this email shows up leads me to believe I was either logged out of Arlo or the access token expired.

I set the HA Arlo account up specifically for use with HA, and made sure I logged out of Arlo on that device afterwards. Arlo doesn't like being logged in on more than one device.

I'm not sure if a refresh token isn't being generated, or if there's another issue. I looked up ArloBackgroundWorker and see that it's a part of PyAarlo but I haven't gotten to dig into that repo yet. If I could automate the recycling of just the Aarlo integration that would be ideal, but it's not a huge deal. It's interesting to tinker with and it's giving me an opportunity to learn Python, even if just a little at a time.

msawyer91 avatar Feb 03 '22 15:02 msawyer91