jcgoette / baby_buddy_homeassistant

This custom integration provides sensors for Baby Buddy API endpoints.
MIT License
64 stars 30 forks source link

Always attempts to connect on port 80 #61

Closed danepowell closed 2 years ago

danepowell commented 2 years ago

Recently this integration stopped working for me, I suspect after a Baby Buddy update in the 1.10 range.

In the Home Assistant logs I see this frequently:

2022-04-21 14:56:10 ERROR (MainThread) [custom_components.babybuddy] Error fetching babybuddy data: Cannot connect to host babybuddy:80 ssl:default [Connect call failed ('172.20.0.8', 80)]

That's really weird because I configured HACS Baby Buddy to use port 8000, which should be the default. I don't understand where port 80 comes from.

Note that Baby Buddy and Home Assistant both run as Docker containers, hostnames babybuddy and homeassistant.

jcgoette commented 2 years ago

Take a peek at https://github.com/jcgoette/baby_buddy_homeassistant/issues/60#issuecomment-1105149254.

danepowell commented 2 years ago

I don't think that's the problem in my case since I'm using Baby Buddy's built-in web server. I do have a reverse proxy (Traefik) for external requests, but since this is a case of one Docker container (Home Assistant) connecting to another (Baby Buddy), the reverse proxy shouldn't be involved.

The issue seems to be this integration attempting to connect to Baby Buddy on port 80 instead of 8000, as configured.

jcgoette commented 2 years ago

Can you post the full error from HA logs? Or is that it?

danepowell commented 2 years ago

That's the entirety of the error. I enabled debug logging but there's nothing else relevant.

jcgoette commented 2 years ago

I added some hopefully helpful debug-level logging in v2.4.1 if you want to upgrade and enable debug-level logging.

# Example configuration.yaml entry
logger:
  default: info
  logs:
    custom_components.babybuddy: debug
danepowell commented 2 years ago

Thanks, here are the relevant logs. You can see that some part of the integration knows to use port 8000, but when the GET request actually goes out it's on port 80.

2022-04-21 16:11:17 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.005 seconds (success: False)
2022-04-21 16:12:17 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.005 seconds (success: False)
2022-04-21 16:13:17 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.005 seconds (success: False)
2022-04-21 16:13:27 ERROR (MainThread) [custom_components.babybuddy] Error fetching babybuddy data: Cannot connect to host babybuddy:80 ssl:default [Connect call failed ('172.20.0.11', 80)]
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] Client API Token: <snip>
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] Client URL: http://babybuddy:8000
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET URL: http://babybuddy:8000/api/
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET response: {"children":"http://babybuddy/api/children/","changes":"http://babybuddy/api/changes/","feedings":"http://babybuddy/api/feedings/","notes":"http://babybuddy/api/notes/","sleep":"http://babybuddy/api/sleep/","temperature":"http://babybuddy/api/temperature/","timers":"http://babybuddy/api/timers/","tummy-times":"http://babybuddy/api/tummy-times/","weight":"http://babybuddy/api/weight/","height":"http://babybuddy/api/height/","head-circumference":"http://babybuddy/api/head-circumference/","bmi":"http://babybuddy/api/bmi/"}
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] Endpoints: {'children': 'http://babybuddy/api/children/', 'changes': 'http://babybuddy/api/changes/', 'feedings': 'http://babybuddy/api/feedings/', 'notes': 'http://babybuddy/api/notes/', 'sleep': 'http://babybuddy/api/sleep/', 'temperature': 'http://babybuddy/api/temperature/', 'timers': 'http://babybuddy/api/timers/', 'tummy-times': 'http://babybuddy/api/tummy-times/', 'weight': 'http://babybuddy/api/weight/', 'height': 'http://babybuddy/api/height/', 'head-circumference': 'http://babybuddy/api/head-circumference/', 'bmi': 'http://babybuddy/api/bmi/'}
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET URL: http://babybuddy/api/children/
2022-04-23 08:29:29 ERROR (MainThread) [custom_components.babybuddy] Error fetching babybuddy data: Cannot connect to host babybuddy:80 ssl:default [Connect call failed ('172.20.0.11', 80)]
2022-04-23 08:29:29 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.026 seconds (success: False)
2022-04-23 08:30:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET URL: http://babybuddy/api/children/
2022-04-23 08:30:29 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.009 seconds (success: False)
2022-04-23 08:31:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET URL: http://babybuddy/api/children/
2022-04-23 08:31:29 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.006 seconds (success: False)
2022-04-23 08:32:29 DEBUG (MainThread) [custom_components.babybuddy.client] GET URL: http://babybuddy/api/children/
2022-04-23 08:32:29 DEBUG (MainThread) [custom_components.babybuddy] Finished fetching babybuddy data in 0.006 seconds (success: False)

Also I'd suggest changing the debug log to not print sensitive information like API tokens 😄

jcgoette commented 2 years ago

Ok, this definitely seems the same as https://github.com/jcgoette/baby_buddy_homeassistant/issues/60#issuecomment-1107448142. Closing this in favor of that.

jcgoette commented 2 years ago

Also I'd suggest changing the debug log to not print sensitive information like API tokens 😄

See 319286dac5b060c10d78ca9467f1254f9c80cd59.