Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Citybike sensor error #16523

Closed
reefab opened this issue Sep 9, 2018 · 7 comments · Fixed by #22683
Closed

Citybike sensor error #16523

reefab opened this issue Sep 9, 2018 · 7 comments · Fixed by #22683

Comments

@reefab
Copy link
Contributor

reefab commented Sep 9, 2018

Home Assistant release with the issue:
0.77.3

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):
Docker.

Official Docker Image running on a ubuntu 18.04 server.

Component/platform:

https://www.home-assistant.io/components/sensor.citybikes/

Description of problem:
Adding the basic citybikes component configuration doesn't work and prevent the server from restarting.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

sensor:
  - platform: citybikes
    radius: 500

Traceback (if applicable):

Sun Sep 09 2018 20:19:40 GMT+0200 (CEST)

Error executing service <ServiceCall homeassistant.restart (c:1973bf7a02cd4f209c9ab6dc05f6d008)>
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/core.py", line 1117, in _event_to_service_call
    await service_handler.func(service_call)
  File "/usr/src/app/homeassistant/components/__init__.py", line 175, in async_handle_core_service
    errors = yield from conf_util.async_check_ha_config_file(hass)
  File "/usr/src/app/homeassistant/config.py", line 793, in async_check_ha_config_file
    check_ha_config_file, hass)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/scripts/check_config.py", line 372, in check_ha_config_file
    platform = loader.get_platform(hass, domain, p_name)
  File "/usr/src/app/homeassistant/loader.py", line 62, in get_platform
    return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
  File "/usr/src/app/homeassistant/loader.py", line 94, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/app/homeassistant/components/sensor/citybikes.py", line 173, in <module>
    class CityBikesNetwork:
  File "/usr/src/app/homeassistant/components/sensor/citybikes.py", line 177, in CityBikesNetwork
    NETWORKS_LIST_LOADING = asyncio.Condition()
  File "/usr/local/lib/python3.6/asyncio/locks.py", line 303, in __init__
    self._loop = events.get_event_loop()
  File "/usr/local/lib/python3.6/asyncio/events.py", line 694, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "/usr/local/lib/python3.6/asyncio/events.py", line 602, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'SyncWorker_4'.

Additional information:

I've spun up a local instance on my macOS 10.13.6 machine with python 3.7 on the dev branch and I can't reproduce this bug on it.

@reefab reefab changed the title hass Citybike sensor error Sep 9, 2018
@flowolf
Copy link
Contributor

flowolf commented Oct 2, 2018

is this still a problem? is the current version of Home Assistant showing the same error?

Do you have more info on when this error occurs?

@reefab
Copy link
Contributor Author

reefab commented Oct 2, 2018

I've just spun up a new docker instance, with 0.79.3 and I'm still getting the same error.

This is a test instance with no modification from the default configuration apart for the city bikes sensor.

Steps:

Installed via compose:

version: '2'
services:
  homeassistant:
    image: homeassistant/home-assistant
    environment:
      - TZ=Europe/Paris
      - /etc/localtime:/etc/localtime:ro
    restart: always
    ports:
      - 8124:8123

Edited configuration.yaml by adding at the end (after commenting the default sensor: platform: yr):

sensor:
  - platform: citybikes
    radius: 500

Clicked "Check Config" and in the log in the info pane:

Log Details (ERROR)
Wed Oct 03 2018 00:39:00 GMT+0200 (CEST)

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 390, in start
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 366, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 106, in impl
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/static.py", line 66, in staticresource_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/ban.py", line 66, in ban_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/auth.py", line 68, in auth_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/real_ip.py", line 34, in real_ip_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/ban.py", line 66, in ban_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/auth.py", line 68, in auth_middleware
    return await handler(request)
  File "/usr/src/app/homeassistant/components/http/view.py", line 113, in handle
    result = await result
  File "/usr/src/app/homeassistant/components/config/core.py", line 24, in post
    errors = yield from async_check_ha_config_file(request.app['hass'])
  File "/usr/src/app/homeassistant/config.py", line 795, in async_check_ha_config_file
    check_ha_config_file, hass)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/scripts/check_config.py", line 372, in check_ha_config_file
    platform = loader.get_platform(hass, domain, p_name)
  File "/usr/src/app/homeassistant/loader.py", line 60, in get_platform
    return get_component(hass, PLATFORM_FORMAT.format(domain, platform))
  File "/usr/src/app/homeassistant/loader.py", line 92, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/src/app/homeassistant/components/sensor/citybikes.py", line 173, in <module>
    class CityBikesNetwork:
  File "/usr/src/app/homeassistant/components/sensor/citybikes.py", line 177, in CityBikesNetwork
    NETWORKS_LIST_LOADING = asyncio.Condition()
  File "/usr/local/lib/python3.6/asyncio/locks.py", line 303, in __init__
    self._loop = events.get_event_loop()
  File "/usr/local/lib/python3.6/asyncio/events.py", line 694, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "/usr/local/lib/python3.6/asyncio/events.py", line 602, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'SyncWorker_0'.

@pulimento
Copy link

Confirming the issue here. My configuration:

  - platform: citybikes
    name: Sevici
    network: sevici
    radius: 500

Log at service startup:

Jan 14 20:34:31 controlcasa hass[1127]: 2019-01-14 20:34:31 INFO (MainThread) [homeassistant.setup] Setting up sensor
Jan 14 20:34:31 controlcasa hass[1127]: 2019-01-14 20:34:31 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.citybikes
Jan 14 20:34:32 controlcasa hass[1127]: 2019-01-14 20:34:32 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.yr
Jan 14 20:34:32 controlcasa hass[1127]: 2019-01-14 20:34:32 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.systemmonitor
Jan 14 20:34:38 controlcasa hass[1127]: 2019-01-14 20:34:38 ERROR (MainThread) [homeassistant.components.sensor.citybikes] Could not connect to CityBikes API endpoint
Jan 14 20:34:41 controlcasa hass[1127]: 2019-01-14 20:34:41 WARNING (MainThread) [homeassistant.components.sensor] Setup of platform citybikes is taking over 10 seconds.
Jan 14 20:35:32 controlcasa hass[1127]: 2019-01-14 20:35:32 ERROR (MainThread) [homeassistant.components.sensor] Setup of platform citybikes is taking longer than 60 seconds. Startup will proceed without waiting any longer.
Jan 14 20:35:32 controlcasa hass[1127]: 2019-01-14 20:35:32 INFO (MainThread) [homeassistant.setup] Setup of domain sensor took 60.1 seconds.
Jan 14 20:35:32 controlcasa hass[1127]: 2019-01-14 20:35:32 INFO (MainThread) [homeassistant.loader] Loaded sensor.mqtt from homeassistant.components.sensor.mqtt
Jan 14 20:35:32 controlcasa hass[1127]: 2019-01-14 20:35:32 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.mqtt
Jan 14 20:35:33 controlcasa hass[1127]: 2019-01-14 20:35:33 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Jan 14 20:35:33 controlcasa hass[1127]: Traceback (most recent call last):
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 113, in async_citybikes_request
Jan 14 20:35:33 controlcasa hass[1127]:     req = await session.get(DEFAULT_ENDPOINT.format(uri=uri))
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/client.py", line 370, in _request
Jan 14 20:35:33 controlcasa hass[1127]:     timeout=timeout
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/connector.py", line 445, in connect
Jan 14 20:35:33 controlcasa hass[1127]:     proto = await self._create_connection(req, traces, timeout)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/connector.py", line 757, in _create_connection
Jan 14 20:35:33 controlcasa hass[1127]:     req, traces, timeout)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/connector.py", line 862, in _create_direct_connection
Jan 14 20:35:33 controlcasa hass[1127]:     req=req, client_error=client_error)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/connector.py", line 822, in _wrap_create_connection
Jan 14 20:35:33 controlcasa hass[1127]:     return await self._loop.create_connection(*args, **kwargs)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 801, in create_connection
Jan 14 20:35:33 controlcasa hass[1127]:     sock, protocol_factory, ssl, server_hostname)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/base_events.py", line 827, in _create_connection_transport
Jan 14 20:35:33 controlcasa hass[1127]:     yield from waiter
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Jan 14 20:35:33 controlcasa hass[1127]:     yield self  # This tells Task to wait for completion.
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Jan 14 20:35:33 controlcasa hass[1127]:     future.result()
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/futures.py", line 285, in result
Jan 14 20:35:33 controlcasa hass[1127]:     raise CancelledError
Jan 14 20:35:33 controlcasa hass[1127]: concurrent.futures._base.CancelledError
Jan 14 20:35:33 controlcasa hass[1127]: During handling of the above exception, another exception occurred:
Jan 14 20:35:33 controlcasa hass[1127]: Traceback (most recent call last):
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 215, in async_refresh
Jan 14 20:35:33 controlcasa hass[1127]:     STATIONS_RESPONSE_SCHEMA)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 124, in async_citybikes_request
Jan 14 20:35:33 controlcasa hass[1127]:     raise CityBikesRequestError
Jan 14 20:35:33 controlcasa hass[1127]: homeassistant.components.sensor.citybikes.CityBikesRequestError
Jan 14 20:35:33 controlcasa hass[1127]: During handling of the above exception, another exception occurred:
Jan 14 20:35:33 controlcasa hass[1127]: Traceback (most recent call last):
Jan 14 20:35:33 controlcasa hass[1127]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
Jan 14 20:35:33 controlcasa hass[1127]:     result = coro.throw(exc)
Jan 14 20:35:33 controlcasa hass[1127]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 222, in async_refresh
Jan 14 20:35:33 controlcasa hass[1127]:     raise PlatformNotReady
Jan 14 20:35:33 controlcasa hass[1127]: homeassistant.exceptions.PlatformNotReady
Jan 14 20:35:35 controlcasa hass[1127]: 2019-01-14 20:35:35 INFO (MainThread) [homeassistant.loader] Loaded sun from homeassistant.components.sun
Jan 14 20:35:35 controlcasa hass[1127]: 2019-01-14 20:35:35 INFO (MainThread) [homeassistant.setup] Setting up sun

@altersis
Copy link
Contributor

Gents, are you using the latest HASS release now? A big number of issues have been fixed in the core and this might be solved as a consequence. Could you please try and update (and hopefully close the issue) if it woroks now? Thanks!

@pulimento
Copy link

pulimento commented Mar 22, 2019 via email

@PiotrMachowski
Copy link
Contributor

Issue still exists in 0.90.1 (Raspberry Pi, Python venv)
When sensor.citybikes is added I get following error when checking configuration:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/ban.py", line 68, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/auth.py", line 206, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/http/view.py", line 112, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/config/core.py", line 21, in post
    errors = await async_check_ha_config_file(request.app['hass'])
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/config.py", line 785, in async_check_ha_config_file
    check_ha_config_file, hass)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/scripts/check_config.py", line 371, in check_ha_config_file
    platform = loader.get_platform(hass, domain, p_name)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 105, in get_platform
    base_paths)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 166, in _load_file
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 171, in <module>
    class CityBikesNetwork:
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/citybikes.py", line 175, in CityBikesNetwork
    NETWORKS_LIST_LOADING = asyncio.Condition()
  File "/usr/lib/python3.5/asyncio/locks.py", line 284, in __init__
    self._loop = events.get_event_loop()
  File "/usr/lib/python3.5/asyncio/events.py", line 671, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "/usr/lib/python3.5/asyncio/events.py", line 583, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-11'.

@MartinHjelmare
Copy link
Member

MartinHjelmare commented Mar 30, 2019

This is a bug in the platform module. The hass event loop must be passed to the asyncio.Condition and the asyncio.Event when those are created, since the creating (function) scopes aren't coroutines.

@MartinHjelmare MartinHjelmare self-assigned this Mar 30, 2019
@MartinHjelmare MartinHjelmare mentioned this issue Apr 3, 2019
3 tasks
@ghost ghost added the in progress label Apr 3, 2019
@ghost ghost removed the in progress label Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants