diff --git a/app.py b/app.py index cf70f99..ef8c846 100644 --- a/app.py +++ b/app.py @@ -50,42 +50,22 @@ class UnifiAPI: self.session = requests.Session() self.session.verify = False self.headers = { - 'Authorization': f'Bearer {config["unifi"]["api_key"]}', - 'Accept': 'application/json', - 'Content-Type': 'application/json' + 'X-API-KEY': config['unifi']['api_key'], + 'Accept': 'application/json' } - self.site_id = self.get_site_id() - - def get_site_id(self): - url = f"{self.base_url}/proxy/network/api/self/sites" - response = self.session.get(url, headers=self.headers) - response.raise_for_status() - sites = response.json()['data'] - return sites[0]['_id'] + self.site_id = "default" # Use default site for now def get_all_devices(self): - url = f"{self.base_url}/proxy/network/api/s/{self.site_id}/stat/device" + 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() - return response.json()['data'] - + return response.json()['data'] + def get_device_details(self, device_id): - url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices/{device_id}" + url = f"{self.base_url}/proxy/network/v2/api/site/{self.site_id}/device/{device_id}" response = self.session.get(url, headers=self.headers) response.raise_for_status() - logger.debug(f"Device details response: {response.text}") - data = response.json() - return { - 'state': data['state'], - 'firmware': { - 'version': data['firmwareVersion'], - 'updatable': data.get('firmwareUpdatable', False) - }, - 'network': { - 'ip': data['ipAddress'], - 'mac': data['macAddress'] - } - } + return response.json()['data'] def get_device_diagnostics(self, device): details = self.get_device_details(device['ip'])