style: apply Ruff formatting
All checks were successful
Test blackout notifier / test (push) Successful in 4s
Hourly blackout check / check (push) Successful in 5s

This commit is contained in:
Meghdad
2026-07-22 03:20:01 +03:30
parent 42687ee651
commit ea03d84901
4 changed files with 7 additions and 16 deletions

View File

@@ -114,14 +114,11 @@ class EitaaClient:
try: try:
body = response.json() body = response.json()
except requests.JSONDecodeError as error: except requests.JSONDecodeError as error:
raise ExternalServiceError( raise ExternalServiceError(f"Eitaa returned invalid JSON for chat {chat_id}") from error
f"Eitaa returned invalid JSON for chat {chat_id}"
) from error
if not isinstance(body, dict) or body.get("ok") is not True: if not isinstance(body, dict) or body.get("ok") is not True:
description = body.get("description") if isinstance(body, dict) else None description = body.get("description") if isinstance(body, dict) else None
raise ExternalServiceError( raise ExternalServiceError(
f"Eitaa rejected the message for chat {chat_id}: " f"Eitaa rejected the message for chat {chat_id}: {description or 'unknown error'}"
f"{description or 'unknown error'}"
) )

View File

@@ -88,16 +88,13 @@ def _bill_chat_map(raw_routes: str) -> dict[str, tuple[str, ...]]:
malformed.append(route) malformed.append(route)
continue continue
if not bill_id.isdecimal(): if not bill_id.isdecimal():
raise ConfigurationError( raise ConfigurationError(f"BILL_CHAT_MAP bill IDs must be decimal: {bill_id}")
f"BILL_CHAT_MAP bill IDs must be decimal: {bill_id}"
)
chat_ids = routes.setdefault(bill_id, []) chat_ids = routes.setdefault(bill_id, [])
if chat_id not in chat_ids: if chat_id not in chat_ids:
chat_ids.append(chat_id) chat_ids.append(chat_id)
if malformed: if malformed:
raise ConfigurationError( raise ConfigurationError(
"BILL_CHAT_MAP entries must use BILL_ID:CHAT_ID format: " "BILL_CHAT_MAP entries must use BILL_ID:CHAT_ID format: " + ", ".join(malformed)
+ ", ".join(malformed)
) )
if not routes: if not routes:
raise ConfigurationError("BILL_CHAT_MAP must contain at least one route") raise ConfigurationError("BILL_CHAT_MAP must contain at least one route")

View File

@@ -91,9 +91,7 @@ class OutageService:
previous = Outage.from_dict(record["snapshot"]) previous = Outage.from_dict(record["snapshot"])
if record["status"] == "cancelled": if record["status"] == "cancelled":
if self._notify( if self._notify(chat_ids, reactivated_outage_message(bill_id, outage, now), result):
chat_ids, reactivated_outage_message(bill_id, outage, now), result
):
records[event_id] = _record(outage, now) records[event_id] = _record(outage, now)
result.state_changed = True result.state_changed = True
continue continue
@@ -126,9 +124,7 @@ class OutageService:
if record["missing_checks"] == 0: if record["missing_checks"] == 0:
record["missing_checks"] = 1 record["missing_checks"] = 1
result.state_changed = True result.state_changed = True
elif self._notify( elif self._notify(chat_ids, cancelled_outage_message(bill_id, previous, now), result):
chat_ids, cancelled_outage_message(bill_id, previous, now), result
):
record["status"] = "cancelled" record["status"] = "cancelled"
record["missing_checks"] = 2 record["missing_checks"] = 2
record["notified_at"] = now.isoformat() record["notified_at"] = now.isoformat()

View File

@@ -59,6 +59,7 @@ def test_config_rejects_malformed_routes(
with pytest.raises(ConfigurationError, match="BILL_ID:CHAT_ID"): with pytest.raises(ConfigurationError, match="BILL_ID:CHAT_ID"):
Config.from_env() Config.from_env()
def test_legacy_single_chat_configuration_is_still_supported( def test_legacy_single_chat_configuration_is_still_supported(
monkeypatch: pytest.MonkeyPatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None: