firstof9 / ha-openei

OpenEI integration for Home Assistant
MIT License
15 stars 2 forks source link

Not presented with correct utility company options on setup #7

Closed coleya closed 3 years ago

coleya commented 3 years ago

I get power from PG&E, but only the SFPUC shows up as an option to select for my utility so the rates aren't correct. Even if I select one of the rates for that utility I get a setup error and no new entities show up.

firstof9 commented 3 years ago

Someone else had this issue, try reloading the integration.

coleya commented 3 years ago

I tried a reinstall from HACS and resetup the integration and still ran into the same issue. Screenshot_20210907-113924

firstof9 commented 3 years ago

Guess their API misses your provider for some reason, I'll add a zip code lookup since I'm doing it by your HA lon/lat.

EDIT: Looks like it doesn't have zip code lookup. Can you verify your lon/lat are correct?

coleya commented 3 years ago

My lat/lon as defined in my configuration.yaml is accurate. I wonder if this is being caused by the fact that multiple providers service the area. I'm not sure its that since PG&E seems to be in the database.

firstof9 commented 3 years ago

I'm updating the library to support the radius option, I'll have an update shortly.

firstof9 commented 3 years ago

The latest update will allow you to specify a radius, start small at like 5 and see if it picks up your proper utility company.

coleya commented 3 years ago

Hi, now PG&E shows up but it just says unknown error occurred when I click submit. image

This is what looks to be the relevant section in the log.

2021-09-07 14:43:20 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 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/openei/config_flow.py", line 45, in async_step_user_2
    return await self.async_step_user_3()
  File "/config/custom_components/openei/config_flow.py", line 59, in async_step_user_3
    return await self._show_config_form_3(user_input)
  File "/config/custom_components/openei/config_flow.py", line 90, in _show_config_form_3
    plan_list = await _get_plan_list(self.hass, self._data)
  File "/config/custom_components/openei/config_flow.py", line 271, in _get_plan_list
    for plan in plans[utility]:
KeyError: 'Pacific Gas & Electric Co'
2021-09-07 14:45:01 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 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/openei/config_flow.py", line 45, in async_step_user_2
    return await self.async_step_user_3()
  File "/config/custom_components/openei/config_flow.py", line 59, in async_step_user_3
    return await self._show_config_form_3(user_input)
  File "/config/custom_components/openei/config_flow.py", line 90, in _show_config_form_3
    plan_list = await _get_plan_list(self.hass, self._data)
  File "/config/custom_components/openei/config_flow.py", line 271, in _get_plan_list
    for plan in plans[utility]:
KeyError: 'Pacific Gas & Electric Co'
firstof9 commented 3 years ago

Well that's a nasty lil bug

firstof9 commented 3 years ago

This PR fixes it

coleya commented 3 years ago

Now I can get through the setup dialog and the correct company and tariff show up but once I select them the integration tile says retrying setup: none and the log contains this every minute or so it does this even after a restart of home assistant and reinstalling from HACS.

ERROR (MainThread) [custom_components.openei] Error fetching openei data: 

This might be unrelated though because this happened even when I selected a random tariff with the wrong company before all the fixes.

firstof9 commented 3 years ago

Can you enable debugging on custom_components.openei and see what's being dumped out?

coleya commented 3 years ago

I enabled debug, but the output only got a bit more verbose it now repeatedly says:

2021-09-07 17:37:47 ERROR (MainThread) [custom_components.openei] Error fetching openei data: 
2021-09-07 17:37:47 DEBUG (MainThread) [custom_components.openei] Finished fetching openei data in 0.467 seconds (success: False)
2021-09-07 17:37:47 DEBUG (MainThread) [homeassistant.config_entries] Config entry 'Pacific Gas & Electric Co' for openei integration not ready yet: None; Retrying in 80 seconds

It also says this with anywhere between 1300-1600 seconds as the time:

2021-09-07 17:33:29 DEBUG (MainThread) [custom_components.openei] Data will be updated at the top of every hour.
2021-09-07 17:33:29 DEBUG (MainThread) [custom_components.openei] Next update in 1591 seconds.

I looked in the web UI log and found something I didn't see before

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/openei/__init__.py:103
Integration: OpenEI Utility Rates (documentation, issues)
First occurred: 6:00:00 PM (23 occurrences)
Last logged: 6:00:01 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/openei/__init__.py", line 99, in _async_refresh_data
    self._data = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/openei/__init__.py", line 113, in get_sensors
    rate.update()
  File "/usr/local/lib/python3.9/site-packages/openeihttp/__init__.py", line 92, in update
    data = result.json()["items"][0]
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/openei/__init__.py", line 103, in _async_refresh_data
    raise UpdateFailed() from exception
homeassistant.helpers.update_coordinator.UpdateFailed

I can send you any other lines you think might be relevant but this is what came up when I did a search for custom_components.openei. I can send you the whole log if you email me.

firstof9 commented 3 years ago

It sounds like the plan doesn't have any data in it, can you give me the info from step 3, the uuid looking config bit that gets put in?

coleya commented 3 years ago

Sure the tariff schedule ID is 539fbd5aec4f024c27d87ac1

firstof9 commented 3 years ago

Ah I see the error, it's in the library, give me a min to update.

firstof9 commented 3 years ago

Give 0.0.8 a shot once it's available.

coleya commented 3 years ago

The logs look the same as before this doesn't seem to have fixed it.

coleya commented 3 years ago

After waiting for the next hour boundary a slightly new error has shown up:

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/openei/__init__.py:103
Integration: OpenEI Utility Rates (documentation, issues)
First occurred: 10:00:01 PM (48 occurrences)
Last logged: 10:00:03 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/openei/__init__.py", line 99, in _async_refresh_data
    self._data = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/openei/__init__.py", line 118, in get_sensors
    _sensor[sensor] = getattr(rate, sensor)
  File "/usr/local/lib/python3.9/site-packages/openeihttp/__init__.py", line 172, in distributed_generation
    return self._data["dgrules"]
KeyError: 'dgrules'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/openei/__init__.py", line 103, in _async_refresh_data
    raise UpdateFailed() from exception
homeassistant.helpers.update_coordinator.UpdateFailed