andrewleech / uhoo-homeassistant

uHoo consumer integration for homeassistant
MIT License
6 stars 0 forks source link

Error Fetching Data #1

Open s28400 opened 1 year ago

s28400 commented 1 year ago

Hello, This integration has stopped returning data and can not reload as of 5/1. I tried deleting and recreating with no luck.

Here is what I can see in the log: Error: an exception occurred while attempting to get latest data: Cannot connect to host api.uhooinc.com:443 ssl:default [Try again] Error: an exception occurred while attempting to get latest data: 'int' object is not subscriptable Error: an exception occurred while attempting to get latest data: 'float' object is not subscriptable

andrewleech commented 1 year ago

Yep this is affecting me too. Apparently uhoo changed their API format, a fix for me to copy is detailed here https://github.com/wrouesnel/pyuhoo/pull/1

s28400 commented 1 year ago

Yep, the issue is with the pyuhoo python package under the hood. I ended up forking the package and the home assistant project and made the required fixes. It’s running fine for me so far.

dvhub commented 1 year ago

Same problem for me. @andrewleech, will you merge the fix?

UPDATE: I updated to latest and have a different error:

This error originated from a custom integration.

Logger: homeassistant.setup Source: custom_components/uhoo/init.py:28 Integration: uHoo (documentation, issues) First occurred: 9:51:57 AM (1 occurrences) Last logged: 9:51:57 AM

Error during setup of component uhoo Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 257, in _async_setup_component result = await task File "/config/custom_components/uhoo/init.py", line 28, in async_setup self.config_entry, platform)) NameError: name 'self' is not defined

andrewleech commented 1 year ago

Yeah those other issues are what I'm working on myself, compatibility with the latest HA updates

dvhub commented 1 year ago

Okay. Thank you very much!

On Sun, May 7, 2023, 11:12 AM Andrew Leech @.***> wrote:

Yeah those other issues are what I'm working on myself, compatibility with the latest HA updates

— Reply to this email directly, view it on GitHub https://github.com/andrewleech/uhoo-homeassistant/issues/1#issuecomment-1537464711, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABU7GZC5MVCVOXA3QJF5CSLXE63XVANCNFSM6AAAAAAXTJXELI . You are receiving this because you commented.Message ID: @.***>

andrewleech commented 1 year ago

This issue should be fixed with https://github.com/andrewleech/uhoo-homeassistant/commit/f3ea536a5d943df8255a5f35d460dd44cdcb7e4a

adynis commented 1 year ago

Can I use this fixed version already somehow in HomeAssistant? Or I need to wait for @csacca to create a 0,0,5 release version on https://github.com/csacca/uhoo-homeassistant ?

andrewleech commented 1 year ago

@adynis you can use it straight from here, I've got a few fixes in place.

Just add this repo to HACS and install it directly from here:

https://github.com/andrewleech/uhoo-homeassistant.git

It's probably best to remove the original csacca repo from your HACS for now so they don't get mixed up.

adynis commented 1 year ago

Thank you, @andrewleech ! I tried before asking you but probably I messed-up something. But after you wrote, I re-tried it properly, removing repo from HACS, restarting, adding it, restarting, etc ... and IT WORKED !!!

wlockwood commented 1 year ago

I'm getting the same int/float not subscriptable errors, but I have yet to get the integration to work as yet so I don't know if I'm doing something wrong or if there's a bug. FWIW, HACS shows f3ea536 as the version, which matches the commit hash.

It's working for both of you right now?

andrewleech commented 1 year ago

Yeah it's flawless for me since I fixed the new home assistant version compatibility issue just over 2 weeks ago, the int/float error should be long gone I would have thought. Maybe if you can completely uninstall the integration, restart ha, then reinstall from mine it might clear out.

dvhub commented 1 year ago

It works well for me also.

On Thu, Jun 1, 2023, 2:20 AM William Lockwood @.***> wrote:

I'm getting the same int/float not subscriptable errors, but I have yet to get the integration to work as yet so I don't know if I'm doing something wrong or if there's a bug. FWIW, HACS shows f3ea536 https://github.com/andrewleech/uhoo-homeassistant/commit/f3ea536a5d943df8255a5f35d460dd44cdcb7e4a as the version, which matches the commit hash.

It's working for both of you right now?

— Reply to this email directly, view it on GitHub https://github.com/andrewleech/uhoo-homeassistant/issues/1#issuecomment-1571425810, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABU7GZER5AIALIC7SVKI2JTXJAYCDANCNFSM6AAAAAAXTJXELI . You are receiving this because you commented.Message ID: @.***>

andrewleech commented 1 year ago

@wlockwood I've just removed my local install, gone to "redownload" in the uhoo integration menu in HACS, restarted HA then re-added it in settings/devices/integrations. image

Just to be sure I tried putting in the wrong password on the initial user/pass configuration and it immediately detected and showed the password was wrong, so I doubt that's the issue for you.

My sensors immediately came up working again.

What version HA are you running?

wlockwood commented 1 year ago

I'm running Home Assistant 2023.5.4, Frontend 20230503.3 - latest. Hass front page says that's the latest version.

Here's what I'm doing to try again:

  1. Remove the integration from Hass
  2. Remove the integration from HACS
  3. Restart Hass
  4. Check in /config/custom_components/ to confirm there's no uHoo folder
  5. Confirm that the custom repository is set to andrewleech/uhoo-homeassistant
  6. Restart Hass again for good measure
  7. Wait for HACS to finish starting up
  8. Explore & download repositories > uHoo
  9. Restart Hass again
  10. Add the integration
  11. Error:
    
    This error originated from a custom integration.

Logger: custom_components.uhoo Source: custom_components/uhoo/init.py:56 Integration: uHoo (documentation, issues) First occurred: 9:30:52 PM (7 occurrences) Last logged: 9:32:38 PM

Error: an exception occurred while attempting to get latest data: 'int' object is not subscriptable


This time around, I tried using just the username part of my email instead of my email and it responded with a 401 "account not found", which is promising from an auth standpoint at least. That was resolved by using my email address, but I still have the other errors.
wlockwood commented 1 year ago

For whatever reason, my Options dialog for the integration looks like this: image

I'd expect that to have credentials in it, but it's just one unlabeled checkbox. Edit: I just checked and I get the same thing in Edge as I do in Vivaldi. Edit 2: To confirm I'm actually running the fixed code from your repo, I opened up the __init.py__ and looked for the changes from your f3ea536 commit and they are there.

andrewleech commented 1 year ago

@wlockwood there's something strange going on for sure, unfortunately that error message isn't giving much to go on.

The line referred to is https://github.com/andrewleech/uhoo-homeassistant/blob/client_id/custom_components/uhoo/__init__.py#L56

await coordinator.async_refresh()

Which definitely isn't the line that's throwing the exception, it must be coming from somewhere else during the attempt to read data but the default HA logging here isn't showing the full context.

I'll probably need to try to add more customised error detection and logging at a lower level to hopefully catch and report the real source of the error. Then maybe that'll inform what's needed to fix it.

andrewleech commented 1 year ago

I'd expect that to have credentials in it, but it's just one unlabeled checkbox.

Yeah mine shows the same here, I'm not sure what's intended to be displayed on this to be honest.

adynis commented 1 year ago

I'd expect that to have credentials in it, but it's just one unlabeled checkbox.

I'f I'm not wrong that "empty" checkbox is something like: Add newly appeared entities into HA ... or something like this. I've seen this "empty" checkbox in more integrations .... so that I almost got used with it.

Later Update: I just re-checked and seems my previous statement was wrong: If on the integration I press: "Configure" , then I get the "emtpy" checkbox. But If I press the 3-dots button and system options, then I see 2 valid options, one of them being "Enable newly added entities" ... so the "empty" checkbox must be something else .... But .. anyhow : I also have it and the uhoo integrations works just fine !

wlockwood commented 1 year ago

@andrewleech - Using the cli.py that's included in csacca's repo, I ran just the API sans Hass and still got the same error, but with more detail:

DEBUG:pyuhoo:[_request] 200 get https://api.uhooinc.com/v1/getalllatestdata
Traceback (most recent call last):
  File "C:\Users\jinks\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\jinks\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "D:\code\pyuhoo\pyugit\pyuhoo\cli.py", line 74, in <module>
    cli()
  File "D:\code\imagequal\.venv\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "D:\code\imagequal\.venv\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "D:\code\imagequal\.venv\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "D:\code\imagequal\.venv\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "D:\code\pyuhoo\pyugit\pyuhoo\cli.py", line 70, in cli
    asyncio.get_event_loop().run_until_complete(example(username, password))
  File "C:\Users\jinks\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "D:\code\pyuhoo\pyugit\pyuhoo\cli.py", line 23, in example
    await client.get_latest_data()
  File "D:\code\imagequal\.venv\lib\site-packages\pyuhoo\client.py", line 132, in get_latest_data
    device_obj.update_data(data)
  File "D:\code\imagequal\.venv\lib\site-packages\pyuhoo\device.py", line 49, in update_data
    self.co = data["co"]["value"]
TypeError: 'int' object is not subscriptable

Editing device.py to dump the data it's trying to update with, it looks like the value returned is just a normal integer:

{'serialNumber': 'xxxx',
 'timestamp': 1685721884,
 'temp': 71.4,
 'humidity': 47.3,
 'pressure': 1000,
 'voc': 225,
 'co2': 571,
 'co': 0,
 'ozone': 6,
 'no2': 1,
 'dust': 2,
 'virusScore': 1}

Are you using a different version of pyuhoo than what's in PyPi? I had previously tried that, but it was automatically reverted during one of the times I removed it.

andrewleech commented 1 year ago

@wlockwood no the pypi version isn't used here, there's a direct reference to my fixed fork on GitHub see https://github.com/andrewleech/uhoo-homeassistant/blob/client_id/custom_components/uhoo/manifest.json#L10

That should ensure the correct version is installed, though I'm not sure how best to actually check this.

wlockwood commented 1 year ago

There's probably a better way to do this, but I don't know what that way is, so here's what I did: /root/.local/lib/python3.10/site-packages returns

sys.path = [
    '/lib',
    '/usr/local/lib/python310.zip',
    '/usr/local/lib/python3.10',
    '/usr/local/lib/python3.10/lib-dynload',
    '/usr/local/lib/python3.10/site-packages',
    '/usr/src/homeassistant',
]

If I navigate to /usr/local/lib/python3.10/site-packages, I can open up client.py and compare that against your repo: image

It looks like I'm getting the old, unpatched version of pyuhoo.

Given that, I ran pip install --upgrade --force-reinstall git+https://github.com/andrewleech/pyuhoo.git@f2f05e756bd344b5571f76e3125d34ce56b7961c, restarted Hass, and now it works!

Thanks for your help!

andrewleech commented 1 year ago

@wlockwood that's great, often times the best way is the one that works!

Thanks for sharing the details too, that's really interesting and has me wondering why the correct package wasn't installed. Of its failed for you it probably has / will fit others too.

Perhaps I'd be better off bundling the lower level package into the git repo rather than relying on specifying it in the manifest file.

Bwiep commented 11 months ago

Having the same problem. But I can’t update the python package because I am running Hassio. Is there a workaround?