diff --git a/app.py b/app.py index 03ccff9..2b4755d 100644 --- a/app.py +++ b/app.py @@ -35,19 +35,26 @@ class UnifiAPI: url = f"{self.base_url}/proxy/network/v2/api/site/{self.site_id}/device" response = self.session.get(url, headers=self.headers) response.raise_for_status() - devices = response.json() - return [{ - 'name': device['name'], - 'ip': device['ip'], - 'type': device['type'], - 'connection_type': 'fiber' if device.get('uplink', {}).get('media') == 'sfp' else 'copper', - 'critical': True if device['type'] in ['udm-pro', 'switch'] else False, - 'device_id': device['mac'] - } for device in devices] + devices_data = response.json() + + # Add debug logging + logger.debug(f"Raw device data: {devices_data}") + + # Handle the response structure correctly + devices = [] + for device in devices_data: + devices.append({ + 'name': device.get('name', 'Unknown'), + 'ip': device.get('ip', '0.0.0.0'), + 'type': device.get('type', 'unknown'), + 'connection_type': 'fiber' if device.get('uplink', {}).get('media') == 'sfp' else 'copper', + 'critical': True if device.get('type') in ['udm-pro', 'switch'] else False, + 'device_id': device.get('mac') + }) + return devices except Exception as e: logger.error(f"Error fetching devices: {e}") return [] - def get_device_details(self, device_id): try: url = f"{self.base_url}/proxy/network/v2/api/site/{self.site_id}/device/{device_id}"