Barebones notif works. Doing nothing with warnings at the moment. Not sure what I can do exept log the things

This commit is contained in:
Jonas Linter
2025-10-01 11:23:54 +02:00
parent 9f289e4750
commit 579db2231f

View File

@@ -8,6 +8,7 @@ handshaking functionality with configurable supported actions and capabilities.
import asyncio
from datetime import datetime
from zoneinfo import ZoneInfo
import difflib
import json
import inspect
@@ -20,7 +21,7 @@ from enum import Enum, IntEnum
from alpine_bits_python.alpine_bits_helpers import PhoneTechType, create_xml_from_db
from .generated.alpinebits import OtaPingRq, OtaPingRs, WarningStatus, OtaReadRq
from .generated.alpinebits import OtaNotifReportRq, OtaNotifReportRs, OtaPingRq, OtaPingRs, WarningStatus, OtaReadRq
from xsdata_pydantic.bindings import XmlSerializer
from xsdata.formats.dataclass.serializers.config import SerializerConfig
from abc import ABC, abstractmethod
@@ -556,26 +557,74 @@ class NotifReportReadAction(AlpineBitsAction):
action: str,
request_xml: str,
version: Version,
client_info: AlpineBitsClientInfo,
dbsession=None,
username=None,
password=None,
server_capabilities=None,
) -> AlpineBitsResponse:
"""Handle read requests."""
return AlpineBitsResponse(
f"Error: Action {action} not implemented", HttpStatusCode.BAD_REQUEST
notif_report = XmlParser().from_string(request_xml, OtaNotifReportRq)
# we can't check hotel auth here, because this action does not contain hotel info
warnings = notif_report.warnings
notif_report_details = notif_report.notif_details
success_message = OtaNotifReportRs(
version="7.000", success=""
)
if client_info.client_id is None:
return AlpineBitsResponse(
"ERROR:no valid client id provided", HttpStatusCode.BAD_REQUEST
)
class GuestRequestsAction(AlpineBitsAction):
"""Unimplemented action - will not appear in capabilities."""
config = SerializerConfig(
pretty_print=True, xml_declaration=True, encoding="UTF-8"
)
serializer = XmlSerializer(config=config)
response_xml = serializer.render(
success_message, ns_map={None: "http://www.opentravel.org/OTA/2003/05"}
)
def __init__(self):
self.name = AlpineBitsActionName.OTA_HOTEL_RES_NOTIF_GUEST_REQUESTS
self.version = Version.V2024_10
if warnings is None and notif_report_details is None:
return AlpineBitsResponse(
response_xml, HttpStatusCode.OK
) # Nothing to process
elif notif_report_details is not None and notif_report_details.hotel_notif_report is None:
return AlpineBitsResponse(
response_xml, HttpStatusCode.OK
) # Nothing to process
else:
# Note: This class doesn't override the handle method, so it won't be discovered
if dbsession is None:
return AlpineBitsResponse(
"Error: Something went wrong", HttpStatusCode.INTERNAL_SERVER_ERROR
)
timestamp = datetime.now(ZoneInfo("UTC"))
for entry in notif_report_details.hotel_notif_report.hotel_reservations.hotel_reservation: # type: ignore
unique_id = entry.unique_id.id
acked_request = AckedRequest(
unique_id=unique_id, client_id=client_info.client_id, timestamp=timestamp
)
dbsession.add(acked_request)
await dbsession.commit()
return AlpineBitsResponse(
response_xml, HttpStatusCode.OK
)
class AlpineBitsServer:
"""