BottlecapDave / HomeAssistant-OctopusEnergy

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

Getting "NameError: name 'ir' is not defined" in octopus_energy/__init__.py line 91 #192

Closed rdowner closed 1 year ago

rdowner commented 1 year ago

Describe the bug

Since updating to the newest version 6.3.1 via HACS, the Octopus Energy integration is not starting. All sensors are reporting "this entity is no longer being provided".

It seems that the integration is erroring on startup. The relevant log entry is below.

My guess is that commit 1198034, committed just before the 6.3.1 release, may be responsible.

To Reproduce

Upgrade to 6.3.1 and restart HomeAssistant.

Expected behavior

The integration to provide sensors with data.

Home Assistant Version

2023.3.6

Integration Version

6.3.1

Fresh Install?

Upgrade using HACS from 6.0.0 to 6.3.1

Home Assistant Logs

Logger: homeassistant.components.sensor
Source: helpers/update_coordinator.py:197
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 23:36:26 (1 occurrences)
Last logged: 23:36:26
Error while setting up octopus_energy platform for sensor

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 225, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 181, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/octopus_energy/__init__.py", line 150, in async_update_electricity_rates_data
    tariff_codes = await async_get_current_electricity_agreement_tariff_codes(hass, client, account_id)
  File "/config/custom_components/octopus_energy/__init__.py", line 91, in async_get_current_electricity_agreement_tariff_codes
    ir.async_delete_issue(hass, DOMAIN, f"account_not_found_{account_id}")
NameError: name 'ir' is not defined

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

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/octopus_energy/sensor.py", line 129, in async_setup_entry
    await async_setup_default_sensors(hass, entry, async_add_entities)
  File "/config/custom_components/octopus_energy/sensor.py", line 141, in async_setup_default_sensors
    await rate_coordinator.async_config_entry_first_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 197, in async_config_entry_first_refresh
    raise ex
homeassistant.exceptions.ConfigEntryNotReady: name 'ir' is not defined
BottlecapDave commented 1 year ago

Sorry, this was caused by a silly mistake by myself that wasn't caused by my CI. I'm planning on adding some additional checks to ensure this doesn't happen again. A new release (https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/releases/tag/v6.3.2) should rectify this.