import requests import logging logger = logging.getLogger(__name__) DEBUG_DATA = { "id": 2224, "comment": None, "start_voltage": 3.6, "battery_id": 91, "cell_type_id": 16, "state": "Unvermessen", "remaining_capacity": None, "soh": None, "created_at": "2025-01-04T11:53:01.820Z", "updated_at": "2025-01-04T11:53:01.820Z", "cell_type": { "id": 16, "name": "INR18650-35E", "comment": "", "manufacturer": "Samsung", "capacity": 3450, "nominal_voltage": 3.7, "max_voltage": 4.2, "min_voltage": 2.5, "created_at": "2024-11-05T15:39:15.107Z", "updated_at": "2024-11-05T15:39:19.564Z" } } class HTTPService: def __init__(self, config: dict): self.config = config self.debug = config['http'].get('debug', False) self.base_url = config['http'].get('server_url') self.endpoint = config['http'].get('endpoint') self.username = config['http'].get('username') self.password = config['http'].get('password') def fetch_cell_info(self, cell_id): if self.debug: return DEBUG_DATA url = f"{self.base_url}/{self.endpoint}/{cell_id}/" # Basic Authentication (if required) auth = (self.username, self.password) # Headers headers = { "Accept": "application/json" } # Making the GET request response = requests.get(url, auth=auth, headers=headers) # Check if the request was successful if response.status_code == 200: return response.json() # Return parsed JSON else: raise ConnectionError(f"Info for cell {cell_id} could not be retreived: {response.status_code}")