Formatting
This commit is contained in:
@@ -18,10 +18,21 @@ from xml.etree import ElementTree as ET
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, IntEnum
|
||||
|
||||
from alpine_bits_python.alpine_bits_helpers import PhoneTechType, create_res_notif_push_message, create_res_retrieve_response
|
||||
from alpine_bits_python.alpine_bits_helpers import (
|
||||
PhoneTechType,
|
||||
create_res_notif_push_message,
|
||||
create_res_retrieve_response,
|
||||
)
|
||||
|
||||
|
||||
from .generated.alpinebits import OtaNotifReportRq, OtaNotifReportRs, 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
|
||||
@@ -61,12 +72,12 @@ class AlpineBitsActionName(Enum):
|
||||
OTA_PING = ("action_OTA_Ping", "OTA_Ping:Handshaking")
|
||||
OTA_READ = ("action_OTA_Read", "OTA_Read:GuestRequests")
|
||||
OTA_HOTEL_AVAIL_NOTIF = ("action_OTA_HotelAvailNotif", "OTA_HotelAvailNotif")
|
||||
OTA_HOTEL_RES_NOTIF_GUEST_REQUESTS = ( ## Push Action for Guest Requests
|
||||
OTA_HOTEL_RES_NOTIF_GUEST_REQUESTS = ( ## Push Action for Guest Requests
|
||||
"action_OTA_HotelResNotif_GuestRequests",
|
||||
"OTA_HotelResNotif:GuestRequests",
|
||||
)
|
||||
OTA_HOTEL_NOTIF_REPORT = (
|
||||
"action_OTA_Read", # if read is supported this is also supported
|
||||
"action_OTA_Read", # if read is supported this is also supported
|
||||
"OTA_NotifReport:GuestRequests",
|
||||
)
|
||||
OTA_HOTEL_DESCRIPTIVE_CONTENT_NOTIF_INVENTORY = (
|
||||
@@ -268,7 +279,6 @@ class ServerCapabilities:
|
||||
|
||||
self.capability_dict = {"versions": list(versions_dict.values())}
|
||||
|
||||
|
||||
# filter duplicates in actions for each version
|
||||
for version in self.capability_dict["versions"]:
|
||||
seen_actions = set()
|
||||
@@ -283,7 +293,8 @@ class ServerCapabilities:
|
||||
for version in self.capability_dict["versions"]:
|
||||
if version["version"] == "2024-10":
|
||||
version["actions"] = [
|
||||
action for action in version["actions"]
|
||||
action
|
||||
for action in version["actions"]
|
||||
if action.get("action") != "action_OTA_Ping"
|
||||
]
|
||||
|
||||
@@ -298,7 +309,6 @@ class ServerCapabilities:
|
||||
self.create_capabilities_dict()
|
||||
return self.capability_dict
|
||||
|
||||
|
||||
def get_supported_actions(self) -> List[str]:
|
||||
"""Get list of all supported action names."""
|
||||
return list(self.action_registry.keys())
|
||||
@@ -395,7 +405,6 @@ class PingAction(AlpineBitsAction):
|
||||
# Create successful ping response with matched capabilities
|
||||
capabilities_json_str = dump_json_for_xml(matching_capabilities)
|
||||
|
||||
|
||||
warning = OtaPingRs.Warnings.Warning(
|
||||
status=WarningStatus.ALPINEBITS_HANDSHAKE,
|
||||
type_value="11",
|
||||
@@ -404,8 +413,6 @@ class PingAction(AlpineBitsAction):
|
||||
|
||||
warning_response = OtaPingRs.Warnings(warning=[warning])
|
||||
|
||||
|
||||
|
||||
client_response_echo_data = dump_json_for_xml(echo_data_client)
|
||||
|
||||
response_ota_ping = OtaPingRs(
|
||||
@@ -510,7 +517,9 @@ class ReadAction(AlpineBitsAction):
|
||||
HttpStatusCode.UNAUTHORIZED,
|
||||
)
|
||||
|
||||
if not validate_hotel_authentication(client_info.username, client_info.password, hotelid, self.config):
|
||||
if not validate_hotel_authentication(
|
||||
client_info.username, client_info.password, hotelid, self.config
|
||||
):
|
||||
return AlpineBitsResponse(
|
||||
f"Error: Unauthorized Read Request for this specific hotel {hotelname}. Check credentials",
|
||||
HttpStatusCode.UNAUTHORIZED,
|
||||
@@ -525,8 +534,6 @@ class ReadAction(AlpineBitsAction):
|
||||
|
||||
# query all reservations for this hotel from the database, where start_date is greater than or equal to the given start_date
|
||||
|
||||
|
||||
|
||||
stmt = (
|
||||
select(Reservation, Customer)
|
||||
.join(Customer, Reservation.customer_id == Customer.id)
|
||||
@@ -547,8 +554,6 @@ class ReadAction(AlpineBitsAction):
|
||||
)
|
||||
stmt = stmt.filter(~Reservation.id.in_(subquery))
|
||||
|
||||
|
||||
|
||||
result = await dbsession.execute(stmt)
|
||||
reservation_customer_pairs: list[tuple[Reservation, Customer]] = (
|
||||
result.all()
|
||||
@@ -601,9 +606,7 @@ class NotifReportReadAction(AlpineBitsAction):
|
||||
warnings = notif_report.warnings
|
||||
notif_report_details = notif_report.notif_details
|
||||
|
||||
success_message = OtaNotifReportRs(
|
||||
version="7.000", success=""
|
||||
)
|
||||
success_message = OtaNotifReportRs(version="7.000", success="")
|
||||
|
||||
if client_info.client_id is None:
|
||||
return AlpineBitsResponse(
|
||||
@@ -622,12 +625,14 @@ class NotifReportReadAction(AlpineBitsAction):
|
||||
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:
|
||||
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:
|
||||
|
||||
if dbsession is None:
|
||||
return AlpineBitsResponse(
|
||||
"Error: Something went wrong", HttpStatusCode.INTERNAL_SERVER_ERROR
|
||||
@@ -635,20 +640,18 @@ class NotifReportReadAction(AlpineBitsAction):
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
return AlpineBitsResponse(
|
||||
response_xml, HttpStatusCode.OK
|
||||
)
|
||||
|
||||
|
||||
class PushAction(AlpineBitsAction):
|
||||
"""Creates the necessary xml for OTA_HotelResNotif:GuestRequests"""
|
||||
@@ -671,7 +674,6 @@ class PushAction(AlpineBitsAction):
|
||||
|
||||
xml_push_request = create_res_notif_push_message(request_xml)
|
||||
|
||||
|
||||
config = SerializerConfig(
|
||||
pretty_print=True, xml_declaration=True, encoding="UTF-8"
|
||||
)
|
||||
@@ -682,8 +684,6 @@ class PushAction(AlpineBitsAction):
|
||||
|
||||
return AlpineBitsResponse(xml_push_request, HttpStatusCode.OK)
|
||||
|
||||
|
||||
|
||||
|
||||
class AlpineBitsServer:
|
||||
"""
|
||||
@@ -740,7 +740,9 @@ class AlpineBitsServer:
|
||||
# Find the action by request name
|
||||
action_enum = AlpineBitsActionName.get_by_request_name(request_action_name)
|
||||
|
||||
_LOGGER.info(f"Handling request for action: {request_action_name} with action enum: {action_enum}")
|
||||
_LOGGER.info(
|
||||
f"Handling request for action: {request_action_name} with action enum: {action_enum}"
|
||||
)
|
||||
if not action_enum:
|
||||
return AlpineBitsResponse(
|
||||
f"Error: Unknown action {request_action_name}",
|
||||
@@ -748,7 +750,7 @@ class AlpineBitsServer:
|
||||
)
|
||||
|
||||
# Check if we have an implementation for this action
|
||||
|
||||
|
||||
if action_enum not in self._action_instances:
|
||||
return AlpineBitsResponse(
|
||||
f"Error: Action {request_action_name} is not implemented",
|
||||
@@ -769,7 +771,6 @@ class AlpineBitsServer:
|
||||
# Special case for ping action - pass server capabilities
|
||||
|
||||
if action_enum == AlpineBitsActionName.OTA_HOTEL_RES_NOTIF_GUEST_REQUESTS:
|
||||
|
||||
action_instance: PushAction
|
||||
if request_xml is None or not isinstance(request_xml, tuple):
|
||||
return AlpineBitsResponse(
|
||||
@@ -777,16 +778,21 @@ class AlpineBitsServer:
|
||||
HttpStatusCode.BAD_REQUEST,
|
||||
)
|
||||
return await action_instance.handle(
|
||||
action=request_action_name, request_xml=request_xml, version=version_enum, client_info=client_info
|
||||
action=request_action_name,
|
||||
request_xml=request_xml,
|
||||
version=version_enum,
|
||||
client_info=client_info,
|
||||
)
|
||||
|
||||
|
||||
if action_enum == AlpineBitsActionName.OTA_PING:
|
||||
return await action_instance.handle(
|
||||
action=request_action_name, request_xml=request_xml, version=version_enum, server_capabilities=self.capabilities, client_info=client_info
|
||||
action=request_action_name,
|
||||
request_xml=request_xml,
|
||||
version=version_enum,
|
||||
server_capabilities=self.capabilities,
|
||||
client_info=client_info,
|
||||
)
|
||||
else:
|
||||
|
||||
return await action_instance.handle(
|
||||
action=request_action_name,
|
||||
request_xml=request_xml,
|
||||
@@ -848,5 +854,3 @@ class AlpineBitsServer:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user