Export discovered devices to JSON file Args: filepath: Path to save the JSON file Returns: Success status
(self, filepath: str)
| 1450 | return {} |
| 1451 | |
| 1452 | def export_devices_to_json(self, filepath: str) -> bool: |
| 1453 | """ |
| 1454 | Export discovered devices to JSON file |
| 1455 | Args: |
| 1456 | filepath: Path to save the JSON file |
| 1457 | Returns: Success status |
| 1458 | """ |
| 1459 | try: |
| 1460 | devices = self.get_discovered_devices() |
| 1461 | |
| 1462 | # Convert to serializable format |
| 1463 | export_data = { |
| 1464 | 'timestamp': time.time(), |
| 1465 | 'scan_duration': time.time() - self.scan_start_time if self.scan_start_time else 0, |
| 1466 | 'device_count': len(devices), |
| 1467 | 'devices': devices |
| 1468 | } |
| 1469 | |
| 1470 | with open(filepath, 'w') as f: |
| 1471 | json.dump(export_data, f, indent=2, default=str) |
| 1472 | |
| 1473 | self.logger.info(f"Exported {len(devices)} devices to {filepath}") |
| 1474 | return True |
| 1475 | |
| 1476 | except Exception as e: |
| 1477 | self.logger.error(f"Error exporting devices to JSON: {e}") |
| 1478 | return False |
| 1479 | |
| 1480 | # Convenience functions for easy usage |
| 1481 | def quick_scan(duration: int = 10, logger=None) -> Dict[str, Dict[str, Any]]: |
nothing calls this directly
no test coverage detected