|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import logging |
6 | | -from typing import Any, Callable |
| 6 | +from collections.abc import Callable |
| 7 | +from typing import Any |
7 | 8 |
|
8 | 9 | import httpx |
9 | | - |
10 | | -from openadr3.api import success, body |
| 10 | +from openadr3.api import success |
11 | 11 |
|
12 | 12 | from openadr3_client.base import BaseClient |
13 | 13 | from openadr3_client.notifications import ( |
@@ -83,16 +83,16 @@ def register(self, ven_name: str) -> VenClient: |
83 | 83 | vid = existing["id"] |
84 | 84 | log.info("VEN found, reusing: name=%s id=%s", ven_name, vid) |
85 | 85 | else: |
86 | | - resp = self.api.create_ven({ |
87 | | - "objectType": "VEN_VEN_REQUEST", |
88 | | - "venName": ven_name, |
89 | | - }) |
| 86 | + resp = self.api.create_ven( |
| 87 | + { |
| 88 | + "objectType": "VEN_VEN_REQUEST", |
| 89 | + "venName": ven_name, |
| 90 | + } |
| 91 | + ) |
90 | 92 | resp.raise_for_status() |
91 | 93 | vid = resp.json().get("id") |
92 | 94 | if not vid: |
93 | | - raise RuntimeError( |
94 | | - f"VEN registration failed: {resp.status_code} {resp.text}" |
95 | | - ) |
| 95 | + raise RuntimeError(f"VEN registration failed: {resp.status_code} {resp.text}") |
96 | 96 | log.info("VEN registered: name=%s id=%s", ven_name, vid) |
97 | 97 | self._ven_id = vid |
98 | 98 | self._ven_name = ven_name |
@@ -135,9 +135,7 @@ def vtn_supports_mqtt(self) -> bool: |
135 | 135 | return False |
136 | 136 | # VTN-RI returns a list of notifier dicts with "transport" field |
137 | 137 | if isinstance(notifiers, list): |
138 | | - return any( |
139 | | - n.get("transport", "").upper() == "MQTT" for n in notifiers |
140 | | - ) |
| 138 | + return any(n.get("transport", "").upper() == "MQTT" for n in notifiers) |
141 | 139 | # Or it might be a dict with transport info |
142 | 140 | return "mqtt" in str(notifiers).lower() |
143 | 141 |
|
@@ -213,16 +211,20 @@ def subscribe( |
213 | 211 | all_topics.extend(topics) |
214 | 212 | elif isinstance(channel, WebhookChannel): |
215 | 213 | # Create a VTN subscription pointing to the webhook |
216 | | - self.api.create_subscription({ |
217 | | - "clientName": self._ven_name or "ven-client", |
218 | | - "programID": program_id, |
219 | | - "objectOperations": [{ |
220 | | - "objects": objects, |
221 | | - "operations": operations, |
222 | | - "callbackUrl": channel.callback_url, |
223 | | - "bearerToken": channel._receiver.bearer_token, |
224 | | - }], |
225 | | - }) |
| 214 | + self.api.create_subscription( |
| 215 | + { |
| 216 | + "clientName": self._ven_name or "ven-client", |
| 217 | + "programID": program_id, |
| 218 | + "objectOperations": [ |
| 219 | + { |
| 220 | + "objects": objects, |
| 221 | + "operations": operations, |
| 222 | + "callbackUrl": channel.callback_url, |
| 223 | + "bearerToken": channel._receiver.bearer_token, |
| 224 | + } |
| 225 | + ], |
| 226 | + } |
| 227 | + ) |
226 | 228 |
|
227 | 229 | return all_topics |
228 | 230 |
|
|
0 commit comments