rospogrigio / daikin_residential

Cloud control of Daikin devices that are supported by Daikin Residential Controller app.
GNU General Public License v3.0
282 stars 39 forks source link

UnboundLocalError: local variable 'res' referenced before assignment #11

Open TASSDevon opened 3 years ago

TASSDevon commented 3 years ago

Getting a couple of the following errors, latest integration version:

This error originated from a custom integration.

Logger: homeassistant.helpers.entity
Source: custom_components/daikin_residential/daikin_api.py:87
Integration: Daikin Residential Controller (documentation, issues)
First occurred: 15:37:43 (3 occurrences)
Last logged: 19:03:44

Update for sensor.veranda_inside_temperature fails
Update for climate.airco_slaapkamer fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 446, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 641, in async_device_update
    raise exc
  File "/config/custom_components/daikin_residential/sensor.py", line 117, in async_update
    await self._device.api.async_update()
  File "/config/custom_components/daikin_residential/daikin_api.py", line 484, in async_update
    json_data = await self.getCloudDeviceDetails()
  File "/config/custom_components/daikin_residential/daikin_api.py", line 464, in getCloudDeviceDetails
    return await self.doBearerRequest("/v1/gateway-devices")
  File "/config/custom_components/daikin_residential/daikin_api.py", line 87, in doBearerRequest
    _LOGGER.debug("BEARER RESPONSE CODE: %s", res.status_code)
UnboundLocalError: local variable 'res' referenced before assignment

HA data:

System Health

version core-2021.9.6
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.9.6
os_name Linux
os_version 5.10.17-v7l+
arch armv7l
timezone Europe/Brussels
Home Assistant Community Store GitHub API | ok -- | -- Github API Calls Remaining | 4907 Installed Version | 1.15.2 Stage | running Available Repositories | 886 Installed Repositories | 15
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Lovelace dashboards | 4 -- | -- resources | 9 views | 29 mode | storage
Spotify api_endpoint_reachable | ok -- | --
rospogrigio commented 3 years ago

Mmm I see... can you please try PR #12 and tell me if it fixes the issue? Thank you

droscy commented 3 years ago

Initilizing res to None probably will only change the error: as soon as the execution passes through the exception branch and reaches the code

_LOGGER.debug("BEARER RESPONSE CODE: %s", res.status_code)

the res has no status_code attribute because it is None.

AttributeError: 'NoneType' object has no attribute 'status_code'

See #18 for a viable workaround.