Browse Source

first sucesfull data load

DebenOldert 6 months ago
parent
commit
d200e377a6

+ 6 - 8
custom_components/odido_klikklaar/__init__.py

@@ -9,21 +9,19 @@ import logging
 from homeassistant.config_entries import ConfigEntry
 from homeassistant.const import Platform
 from homeassistant.core import HomeAssistant
-from homeassistant.exceptions import ConfigEntryNotReady
 from homeassistant.helpers.device_registry import DeviceEntry
 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
-from homeassistant.helpers.entity import DeviceInfo
 
 from .coordinator import RouterCoordinator
-from .const import EP_DEVICESTATUS
 
 _LOGGER = logging.getLogger(__name__)
 
-PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR,
-                             Platform.SENSOR,
-                             Platform.BUTTON,
-                             Platform.SWITCH,
-                             Platform.TEXT]
+PLATFORMS: list[Platform] = Platform.SENSOR
+                             #[#Platform.BINARY_SENSOR,
+                             #Platform.SENSOR,
+                             #Platform.BUTTON,
+                             #Platform.SWITCH,
+                             #Platform.TEXT]
 
 type RouterConfigEntry = ConfigEntry[RuntimeData]
 

+ 1 - 10
custom_components/odido_klikklaar/api.py

@@ -42,9 +42,6 @@ class RouterAPI:
         payload['Input_Account'] = self.user
         payload['Input_Passwd'] = base64.b64encode(
             self.pwd.encode('utf-8')).decode('utf-8')
-        
-        _LOGGER.warning(str(payload))
-        _LOGGER.warning(f'{API_SCHEMA}://{self.host}{API_LOGIN_PATH}')
 
         try:
 
@@ -61,8 +58,6 @@ class RouterAPI:
             raise RouterAPIAuthError('Username or password incorrect.')
 
         if response.ok:
-            _LOGGER.warning(await response.text())
-
             try:
                 data = await response.json()
 
@@ -93,14 +88,13 @@ class RouterAPI:
                     from exception
             
             if response.status == 401:
-                raise RouterAPIAuthError('Unauthenticated request. Did the username or password change')
+                raise RouterAPIAuthError('Unauthenticated request. Did the username or password change?')
 
             if response.ok:
                 try:
                     data: dict = await response.json()
 
                     if data.get(KEY_RESULT, None) == VAL_SUCCES:
-                        _LOGGER.warning(data.get(KEY_OBJECT, [{}]))
                         return data.get(KEY_OBJECT, [{}])[0]
                     else:
                         raise RouterAPIInvalidResponse(f'Response returned error')
@@ -112,9 +106,6 @@ class RouterAPI:
                 raise RouterAPIConnectionError(
                     f'Error retrieving API. Status: {response.status}')
 
-        
-
-
     @property
     def controller_name(self) -> str:
         """Return the name of the controller."""

+ 5 - 5
custom_components/odido_klikklaar/coordinator.py

@@ -4,6 +4,7 @@ from dataclasses import dataclass
 from datetime import timedelta
 import logging
 import asyncio
+import traceback as tb
 
 from homeassistant.config_entries import ConfigEntry
 from homeassistant.const import (
@@ -74,6 +75,8 @@ class RouterCoordinator(DataUpdateCoordinator):
             verify_ssl=False
         )
 
+        session.cookie_jar._unsafe = True
+
         # Initialise your api here
         self.api = RouterAPI(host=self.host,
                              user=self.user,
@@ -98,15 +101,11 @@ class RouterCoordinator(DataUpdateCoordinator):
                     *[self.api.async_query_api(oid=endpoint) for endpoint in endpoints],
                     return_exceptions=True)
                 
-                _LOGGER.debug(results)
-                
                 data = {
                     endpoints[i]: results[i]
-                    for i in len(endpoints)
+                    for i in range(len(endpoints))
                 }
 
-                _LOGGER.debug(data)
-                
                 info = data[EP_DEVICESTATUS]['DeviceInfo']
 
                 self.device_info = DeviceInfo(
@@ -128,6 +127,7 @@ class RouterCoordinator(DataUpdateCoordinator):
             raise UpdateFailed(err) from err
         except Exception as err:
             # This will show entities as unavailable by raising UpdateFailed exception
+            _LOGGER.error(''.join(tb.format_exception(None, err, err.__traceback__)))
             _LOGGER.error(err)
             raise UpdateFailed(f"Error communicating with API: {err}") from err