ソースを参照

Fix set_price float coercion causing silent Booking.com API failure

set_price on both clients accepted floats despite an int signature.
_BookingClient.set_price serialized via str(price), turning 132.0 into
"132.0" — a string Booking's inventory API silently discards, leaving
the price null on the next calendar read. _AirbnbClient passed the
float directly as a JSON number (less likely to break but still wrong).

Coerce to int(round(price)) at the top of each set_price implementation
so the boundary is enforced regardless of caller type. Also fix the
test to use integer arithmetic (v - 1 not v - 1.00).
ZiB 4 ヶ月 前
親
コミット
94d36420b4

+ 4 - 0
room_cal/config-all.json

@@ -60,6 +60,10 @@
       "door_code": ""
     }
   },
+  "chat": {
+    "default_datetime_format": "%a, %b %-d @ %-I %p",
+    "templates": {}
+  },
   "global": {
     "taxes": {
       "sales": 0.157

+ 1 - 0
room_cal/service_api/_airbnb.py

@@ -355,6 +355,7 @@ class _AirbnbClient:
     )
 
   async def set_price(self, d: str, price: int) -> None:
+    price = int(round(price))
     if is_stale('airbnb'):
       raise AirbnbAuthError(f'Airbnb credentials are stale — run: {_AUTH_HINT}')
     if (cached := self._cache.get(d)) and cached.price == price:

+ 1 - 0
room_cal/service_api/_booking.py

@@ -643,6 +643,7 @@ class _BookingClient:
       await self._msg_gql('postFreeTextMessage', _POST_FREE_TEXT_MUTATION, payload)
 
   async def set_price(self, d: str, price: int, occupancy: int = 2) -> None:
+    price = int(round(price))
     if is_stale('booking'):
       raise BookingAuthError(f'Booking.com credentials are stale — run: {_AUTH_HINT}')
     if _is_past(d):

+ 1 - 1
tests/test_services.py

@@ -25,7 +25,7 @@ async def test_price_roundtrip():
   if target is None:
     pytest.skip("No available priced date found in the next 90 days")
 
-  await api.set_prices(target, {k: v - 1.00 for k, v in originals.items()})
+  await api.set_prices(target, {k: v - 1 for k, v in originals.items()})
 
   updated = await api.get_prices(target)
   for key, original in originals.items():