Chouffy / home_assistant_tgtg

TooGoodToGo items stock as sensor in Home Assistant
MIT License
65 stars 18 forks source link

API returns 404 #102

Open skinkie opened 7 months ago

skinkie commented 7 months ago

System Health details

System Information

version core-2024.1.3
installation_type Unknown
dev false
hassio false
docker false
user skinkie
virtualenv false
python_version 3.11.4
os_name Linux
os_version 6.1.51-0-rpi
arch aarch64
timezone Europe/Amsterdam
config_dir /home/skinkie/.homeassistant
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4915 Installed Version | 1.33.0 Stage | running Available Repositories | 1379 Downloaded Repositories | 5
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Dashboards dashboards | 1 -- | -- resources | 1 views | 5 mode | storage
Recorder oldest_recorder_run | January 11, 2024 at 9:17 AM -- | -- current_recorder_run | January 18, 2024 at 10:10 AM estimated_db_size | 580.99 MiB database_engine | sqlite database_version | 3.44.2

Checklist

Describe the issue

TGTG api returns 404

Reproduction steps

  1. Start ha
  2. Observe log.

Debug logs

2024-01-18 10:10:44.864 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/home/skinkie/.local/lib/python3.11/site-packages/homeassistant/helpers/entity_platform.py", line 360, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/skinkie/.homeassistant/custom_components/tgtg/sensor.py", line 81, in setup_platform
    add_entities([TGTGSensor(each_item_id)])
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/skinkie/.homeassistant/custom_components/tgtg/sensor.py", line 102, in __init__
    self.update()
  File "/home/skinkie/.homeassistant/custom_components/tgtg/sensor.py", line 212, in update
    self.tgtg_orders = tgtg_client.get_active()["orders"]
                       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/skinkie/.homeassistant/deps/lib/python3.11/site-packages/tgtg/__init__.py", line 426, in get_active
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (404, b'')

Diagnostics dump

I guess if it fails to start you cannot reach this point.

skinkie commented 7 months ago

With some hacking I disabled the orders in two places. That allows for starting the integration.

Cafun commented 6 months ago

So, I'm currious.. What did you do to make it work again?

skinkie commented 6 months ago
--- sensor.py
+++ /home/skinkie/.homeassistant/custom_components/tgtg/sensor.py
@@ -188,6 +188,7 @@

         orders_placed = 0
         total_quantity_ordered = 0
+        """
         for order in self.tgtg_orders:
             if "item_id" in order:
                 if order["item_id"] == str(self.item_id):
@@ -198,6 +199,7 @@
                         data[ATTR_PICKUP_WINDOW_CHANGED] = order["pickup_window_changed"]
                     if "cancel_until" in order:
                         data[ATTR_CANCEL_UNTIL] = order["cancel_until"]
+        """
         data[ATTR_ORDERS_PLACED] = orders_placed
         if total_quantity_ordered > 0:
             data[ATTR_TOTAL_QUANTITY_ORDERED] = total_quantity_ordered
@@ -209,7 +211,7 @@
         """
         global tgtg_client
         self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
-        self.tgtg_orders = tgtg_client.get_active()["orders"]
+        # self.tgtg_orders = tgtg_client.get_active()["orders"]

         self.store_name = self.tgtg_answer["display_name"]
         self.item_qty = self.tgtg_answer["items_available"]
JackPoint commented 6 months ago

Can you submit this as a PR? That would help everyone

skinkie commented 6 months ago

Can you submit this as a PR? That would help everyone

This is not a fix. This is hack to ignore orders.