Hoffmann77 / home_assistant_enphase_gateway

A custom integration for Home Assistant to read data from your Enphase Gateway.
Apache License 2.0
0 stars 0 forks source link

'GatewayReader' object has no attribute 'raise_for_status' #9

Closed catsmanac closed 1 year ago

catsmanac commented 1 year ago

8 fixed the update attribute but revealed missing attribute for 'reaie_for_status'.

2023-07-04 08:42:27.665 DEBUG (MainThread) [custom_components.enphase_gateway.gateway_reader.gateway_reader] HTTP GET Attempt #1: https://192.168.3.112/production.json: Header:{'Authorization': 'Bearer 
2023-07-04 08:42:27.898 ERROR (MainThread) [custom_components.enphase_gateway] Unexpected error fetching envoy Envoy 122302045041 data: 'GatewayReader' object has no attribute 'raise_for_status'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 242, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/enphase_gateway/__init__.py", line 45, in async_update_data
    await gateway_reader.getData()
  File "/config/custom_components/enphase_gateway/gateway_reader/gateway_reader.py", line 190, in getData
    await self._setup_gateway()
  File "/config/custom_components/enphase_gateway/gateway_reader/gateway_reader.py", line 401, in _setup_gateway
    await self._update(detection=True, gateway_type="ENVOY_MODEL_S")
  File "/config/custom_components/enphase_gateway/gateway_reader/gateway_reader.py", line 241, in _update
    await self._update_endpoint(key, endpoint)
  File "/config/custom_components/enphase_gateway/gateway_reader/gateway_reader.py", line 247, in _update_endpoint
    response = await self._async_get(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/enphase_gateway/gateway_reader/gateway_reader.py", line 280, in _async_get
    if self.raise_for_status:
       ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'GatewayReader' object has no attribute 'raise_for_status'

gateway_reader.py has in _async_get test for self.rais_for_status while raise_for_status is function paramater. Removing self solves it

    async def _async_get(
            self, url, handle_401=True, raise_for_status=True, **kwargs):

                    r = await client.get(
                        url, headers=self._auth_header, **kwargs
                    )
                    if self.raise_for_status:
                        r.raise_for_status()

changed to

                    if raise_for_status:
                        r.raise_for_status()