BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
535 stars 50 forks source link

Regression: Octopus Energy: Refresh previous consumption data service error for Gas entity only #782

Closed emulti closed 2 months ago

emulti commented 4 months ago

Describe the bug

Since 25th Feb 2024 there have been delays in consumption data becoming available in the Octopus API. However, data for 26th appeared in the Android App, so I tried to run the 'Refresh previous consumption data' service for the 26th onwards.

I found that the service runs correctly only for the Electricity entity. For the Gas entity the service fails with an error as in the logs below.

Reproduction steps

developer-tools/services/ 'Refresh previous consumption data' Select date to refresh data from.

Select entity: Electricity: sensor.octopus_energy_electricity_xxxx_yyyy_previous_accumulative_consumption - Result is OK Gas: sensor.octopus_energy_gas_xxxx_yyyy_previous_accumulative_consumption_m3- Failed to call service octopus_energy.refresh_previous_consumption_data. Unknown error

Previously this worked with 10.1.0 (last used about two weeks ago) but with 10.1.4 the Gas service errors.

Expected behaviour

Expected service to update Gas previous consumption data runs without error as previously (10.1.0)

Note: the 'self._account_id' in custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py line 188 appears to have been introduced with this commit: https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/commit/a328fece656eda5a5f0bf432b3ef290517abab07

Maybe the AttributeError: 'OctopusEnergyPreviousAccumulativeGasConsumptionCub' object has no attribute '_account_id' in logs means account_id needs to be added in the definition on Line 40 and following?

Tariff Code

G-1R-SILVER-23-12-06-A

Integration Version

10.1.4

Home Assistant Version

2024.2.3

Fresh Install?

After upgrading

Home Assistant Logs

Feb 29 02:56:07 pihole hass[147343]: 2024-02-29 02:56:07.348 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'OctopusEnergyPreviousAccumulativeGasConsumptionCub' object has no attribute '_account_id' Feb 29 02:56:07 pihole hass[147343]: Traceback (most recent call last): Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 485, in _async_step Feb 29 02:56:07 pihole hass[147343]: await getattr(self, handler)() Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 723, in _async_call_service_step Feb 29 02:56:07 pihole hass[147343]: response_data = await self._async_run_long_action( Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 685, in _async_run_long_action Feb 29 02:56:07 pihole hass[147343]: return long_task.result() Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/core.py", line 2279, in async_call Feb 29 02:56:07 pihole hass[147343]: response_data = await coro Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/core.py", line 2316, in _execute_service Feb 29 02:56:07 pihole hass[147343]: return await target(service_call) Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call Feb 29 02:56:07 pihole hass[147343]: single_response = await _handle_entity_call( Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call Feb 29 02:56:07 pihole hass[147343]: result = await task Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py", line 188, in async_refresh_previous_consumption_data Feb 29 02:56:07 pihole hass[147343]: self._account_id, Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: AttributeError: 'OctopusEnergyPreviousAccumulativeGasConsumptionCub' object has no attribute '_account_id' Feb 29 02:56:07 pihole hass[147343]: 2024-02-29 02:56:07.455 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [546347268416] Error handling message: Unknown error (unknown_error) username from ip (Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36) Feb 29 02:56:07 pihole hass[147343]: Traceback (most recent call last): Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response Feb 29 02:56:07 pihole hass[147343]: await func(hass, connection, msg) Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 795, in handle_execute_script Feb 29 02:56:07 pihole hass[147343]: script_result = await script_obj.async_run( Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 1600, in async_run Feb 29 02:56:07 pihole hass[147343]: return await asyncio.shield(run.async_run()) Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 435, in async_run Feb 29 02:56:07 pihole hass[147343]: await self._async_step(log_exceptions=False) Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 487, in _async_step Feb 29 02:56:07 pihole hass[147343]: self._handle_exception( Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 512, in _handle_exception Feb 29 02:56:07 pihole hass[147343]: raise exception Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 485, in _async_step Feb 29 02:56:07 pihole hass[147343]: await getattr(self, handler)() Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 723, in _async_call_service_step Feb 29 02:56:07 pihole hass[147343]: response_data = await self._async_run_long_action( Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 685, in _async_run_long_action Feb 29 02:56:07 pihole hass[147343]: return long_task.result() Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/core.py", line 2279, in async_call Feb 29 02:56:07 pihole hass[147343]: response_data = await coro Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/core.py", line 2316, in _execute_service Feb 29 02:56:07 pihole hass[147343]: return await target(service_call) Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 892, in entity_service_call Feb 29 02:56:07 pihole hass[147343]: single_response = await _handle_entity_call( Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/.venv/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 962, in _handle_entity_call Feb 29 02:56:07 pihole hass[147343]: result = await task Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: File "/var/lib/hass/custom_components/octopus_energy/gas/previous_accumulative_consumption_cubic_meters.py", line 188, in async_refresh_previous_consumption_data Feb 29 02:56:07 pihole hass[147343]: self._account_id, Feb 29 02:56:07 pihole hass[147343]: ^^^^^^^^^^^^^^^^ Feb 29 02:56:07 pihole hass[147343]: AttributeError: 'OctopusEnergyPreviousAccumulativeGasConsumptionCub' object has no attribute '_account_id'

Confirmation

BottlecapDave commented 4 months ago

Sorry that you're seeing this issue. I can see where the problem is, but there will be a delay in getting the fix out.

emulti commented 4 months ago

No problem- Octopus are several days behind with the data in any case...

KashPopatErgosoft commented 4 months ago

I am having the same but with the electricity previous cost and consumption. Also stopped on 25th Feb.

github-actions[bot] commented 3 months ago

This issue has become stale because it has been open for 30 days with no activity. If you still think it's an issue, please respond soon.

BottlecapDave commented 2 months ago

Sorry for the late response. The original issue should be fixed in the latest release (v10.2.0)