Skip to content

Commit 73e926c

Browse files
committed
fix: add trpc-accept header for POST requests
It seems to be required now.
1 parent ec8ef9f commit 73e926c

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

custom_components/proteus_api/proteus_api.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ def __init__(
6060
self.tenant = tenant
6161
self._session = None
6262

63-
def get_headers(self) -> dict[str, str]:
63+
def get_headers(self, *, for_post: bool = False) -> dict[str, str]:
6464
"""Build HTTP headers for the next request.
6565
6666
Includes CSRF header if session is open.
6767
"""
6868
result = {
6969
"Content-Type": "application/json",
7070
"Origin": "https://proteus.deltagreen.cz",
71+
"Accept": "*/*",
7172
}
73+
if for_post:
74+
result["trpc-accept"] = "application/jsonl"
7275
if self._session is not None:
7376
result["x-proteus-csrf"] = self._session.cookie_jar.filter_cookies(
7477
API_BASE_URL
@@ -215,6 +218,7 @@ def _parse_data(self, raw_data: dict[str, Any]) -> dict[str, Any]:
215218
_LOGGER.error("Missing data: %s", raw_data)
216219
return {}
217220
try:
221+
# _LOGGER.debug("Parsed data: %s", raw_data)
218222
parsed = {}
219223

220224
# Basic info
@@ -287,14 +291,21 @@ async def update_manual_control(self, control_type: str, state: str) -> bool:
287291
}
288292
}
289293
_LOGGER.debug(
290-
"Toggling manual control for %s to %s", self.inverter_id, state
294+
"Toggling manual control %s for %s to %s: %s",
295+
control_type,
296+
self.inverter_id,
297+
state,
298+
payload,
291299
)
292300

293301
async with client.post(
294302
f"{API_BASE_URL}{API_CONTROL_ENDPOINT}?batch=1",
295303
json=payload,
296-
headers=self.get_headers(),
304+
headers=self.get_headers(for_post=True),
297305
) as response:
306+
data = await response.text()
307+
_LOGGER.debug("Response data: %s", data)
308+
298309
return response.status == 200
299310

300311
except Exception:
@@ -319,8 +330,10 @@ async def update_control_enabled(self, enabled: bool) -> bool:
319330
async with client.post(
320331
f"{API_BASE_URL}{API_ENABLED_ENDPOINT}?batch=1",
321332
json=payload,
322-
headers=self.get_headers(),
333+
headers=self.get_headers(for_post=True),
323334
) as response:
335+
data = await response.text()
336+
_LOGGER.debug("Response data: %s", data)
324337
return response.status == 200
325338

326339
except Exception:
@@ -345,8 +358,10 @@ async def update_control_mode(self, mode: str) -> bool:
345358
async with client.post(
346359
f"{API_BASE_URL}{API_MODE_ENDPOINT}?batch=1",
347360
json=payload,
348-
headers=self.get_headers(),
361+
headers=self.get_headers(for_post=True),
349362
) as response:
363+
data = await response.text()
364+
_LOGGER.debug("Response data: %s", data)
350365
return response.status == 200
351366

352367
except Exception:
@@ -373,8 +388,10 @@ async def update_flexibility_mode(self, mode: list[str]) -> bool:
373388
async with client.post(
374389
f"{API_BASE_URL}{API_FLEXIBILITY_ENDPOINT}?batch=1",
375390
json=payload,
376-
headers=self.get_headers(),
391+
headers=self.get_headers(for_post=True),
377392
) as response:
393+
data = await response.text()
394+
_LOGGER.debug("Response data: %s", data)
378395
return response.status == 200
379396

380397
except Exception:

0 commit comments

Comments
 (0)