Giter Site home page Giter Site logo

chouffy / home_assistant_tgtg Goto Github PK

View Code? Open in Web Editor NEW
62.0 5.0 18.0 132 KB

TooGoodToGo items stock as sensor in Home Assistant

License: MIT License

Python 89.59% Dockerfile 8.39% Shell 2.02%
toogoodtogo home-assistant home-assistant-integration python3

home_assistant_tgtg's Introduction

Too Good To Go items stock as a sensor in Home Assistant

This aim to show the stock of one or multiple Too Good To Go item using the tgtg-python library.
Sensor data can be used afterward to generate notifications, history graphs, ... share your best examples in the Discussion tab!

Features

  • Fetch each item stock defined
  • Authenticate using tokens
  • Retrieve all favorites instead of a manual list of item_id if no item: are defined
  • Retrieve additional information as attributes, if available:
    • Item ID
    • Price and original value
    • Pick-up start and end time
    • Sold-out time
    • Orders placed (if above 0, then below attributes also appear)
      • Total quantity ordered (total from 1 or more orders placed)
      • Pickup window changed (true/false)
      • Cancel-until time
  • Dashboard card example

Installation

Two steps are required:

  1. Get access tokens, either manually or via Docker
  2. Install the integration

1. Get access tokens

First you'll need to get access tokens for this integration to work.
This is to be executed outside of Home Assistant, i.e. on your local machine.

1a. Python

  1. Install required packages.
    • Python >=3.8
    • tgtg-python library: In a command line, type pip install tgtg>=0.11.0 or pip install --upgrade tgtg if you already have it.
  2. Run the tgtg_get_tokens script to get access and refresh token. Save these for later.

1b. Docker

This is work in progress.

You only need Docker installed. There is no need to clone the repo because Docker can build from an external URL.

docker build https://github.com/Chouffy/home_assistant_tgtg.git#main --tag "homeassistant_tgtg_tokens:latest"
docker run --rm -it homeassistant_tgtg_tokens

2. Installation via HACS

  1. Search for TooGoodToGo in the Integration tab of HACS
  2. Click Install
  3. Copy over the tokens in /config/configuration.yaml retrieved in 1.
  4. Restart the Home Assistant server
    • ⚠ Each time you add/remove a favorite in the TGTG app, restart your Home Assistant. Favorites are only updated at boot!

Configuration option

sensor:
  - platform: tgtg

    # Optional: email so you know which account is used
    email: "Your TGTG mail"

    # Mandatory: tokens for authentication - see the tgtg_get_tokens.py script
    access_token: "abc123"
    refresh_token: "abc123"
    user_id: "123456"
    cookie: "datadome=..."

    # Optional: Refresh the stock every 15 minutes
    scan_interval: 900

    # Optional, use defined items ID instead to get your favorites
    item:
      # item_id 1
      - 1234
      # item_id 2
      - 5678

    # Optional: user agent - by default, the latest one is retrieved from the Google Play store
    #user_agent: "TGTG/22.2.1 Dalvik/2.1.0 (Linux; U; Android 9; SM-G955F Build/PPR1.180610.011)"

access_token, refresh_token, user_id and cookie can be retrieved using the tgtg_get_tokens script!

How to get item_id

Check the tgtg_get_favorites_item_id script!

  1. Set up email/password
  2. Run it
  3. Copy the full output in the configuration.yaml for the item section

Dashboard card example

Here is an example for a card on your Home Assistant dashboard created by @wallieboy and updated by @Sarnog in #73.
Make sure you install the custom auto-entities and multiple-entity-row cards as well.

type: custom:auto-entities
card:
  type: entities
  title: TGTG Surprise Bags
filter:
  template: |-
    {% for state in states.sensor -%}
      {%- if state.state|float(default=0) >= 1  and 'sensor.tgtg_' in state.entity_id %}
      {%- if state_attr(state.entity_id, 'pickup_start') is not none -%}
        {{
          {
            'entity': state.entity_id,
            'name': state.attributes.friendly_name[5:],
            'type': "custom:multiple-entity-row",
            'unit': false,
            'secondary_info': 'Pickup on ' + state.attributes.pickup_start[8:10] + "-" + state.attributes.pickup_start[5:7] + ' between '+ state.attributes.pickup_start[11:16] + ' and ' + state.attributes.pickup_end[11:16] + ', € '+  state.attributes.item_price[:-3],
            'tap_action': {
              'action': 'url',
              'url_path': state.attributes.item_url}
            }
        }},
      {%- endif -%}
      {%- endif -%}
    {%- endfor %}

image

Q&A

  • It was working before, but now all Too Good To Go sensors are "not available"
    • Try to update your tokens using the script and restart Home Assistant
  • I have a sensor that shows now as unavailable when there's no stock
    • Try add it manually using Item ID - See this issue
  • The tgtg integration won't start, all my sensors are unavailable and I have a list of manually defined items ID

home_assistant_tgtg's People

Contributors

azcn2503 avatar chouffy avatar chris24walsh avatar daviddesloovere avatar dependabot[bot] avatar goegol avatar huizebruin avatar simphide avatar tjorim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

home_assistant_tgtg's Issues

Connection pool is full/Captcha 403 error

System Health details

System Information

version core-2023.5.1
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 6.1.25
arch x86_64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 5000
Installed Version 1.32.1
Stage running
Available Repositories 1350
Downloaded Repositories 36
HACS Data ok
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 10.1
update_channel stable
supervisor_version supervisor-2023.04.1
agent_version 1.5.1
docker_version 23.0.3
disk_total 62.3 GB
disk_used 21.6 GB
healthy true
supported true
board ova
supervisor_api ok
version_api ok
installed_addons Home Assistant Google Drive Backup (0.110.4), Samba share (10.0.1), File editor (5.6.0), Terminal & SSH (9.7.0), Portainer (2.0.0), Mosquitto broker (6.2.1), WireGuard (0.8.0), AdGuard Home (4.8.6), TimescaleDB (2.1.1), Duck DNS (1.15.0), NGINX Home Assistant SSL proxy (3.4.2), SQLite Web (3.7.1), Studio Code Server (5.5.7), pgAdmin4 (2.1.1), Zigbee2MQTT (1.30.4-1), ESPHome (2023.4.4), Advanced SSH & Web Terminal (14.1.0), Frigate NVR Proxy (1.3), chrony (2.5.0), DSMR Reader (1.10.1), Vaultwarden (Bitwarden) (0.19.3)
Dashboards
dashboards 4
resources 19
views 21
mode storage
Recorder
oldest_recorder_run 27 april 2023 om 16:09
current_recorder_run 5 mei 2023 om 15:58
estimated_db_size 1904.34 MiB
database_engine sqlite
database_version 3.40.1
Spotify
api_endpoint_reachable ok

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

From 2023.5 i have this error in my log.
Gladly I still get updates.

Working with HA in a VM in Proxmox

Reproduction steps

...

Debug logs

Deze fout is ontstaan door een aangepaste integratie.

Logger: urllib3.connectionpool
Source: custom_components/tgtg/sensor.py:189
Integration: tgtg (documentation, issues)
First occurred: 16:01:12 (80 occurrences)
Last logged: 16:22:12

Connection pool is full, discarding connection: apptoogoodtogo.com. Connection pool size: 10

Diagnostics dump

No response

Notification Template

Hi, first of all thanks for the Integration. This is not really a Issue but unfortunately there is no discussion part in this github.
I made this automation to notify me whenever a store I like has new items. I am just curious if you have a better way of doing it instead of listing all entity_id's. If not I just wanted to share because I would have liked a template :).

alias: tgtg notify
trigger:
  - platform: state
    entity_id:
      - sensor.long
      - sensor.list
      - sensor.of
      - sensor.all
      - sensor.tgtg
      - sensor.stores
action:

#send notification if stock changes from 0 or unavailable to >=1
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.to_state.state | float >= 1 }}'
          - condition: template
            value_template: >-
              {{ trigger.from_state.state | float == 0 or
              trigger.from_state.state == "unavailable" }}
        sequence:
            #change notification method
          - service: notify.mobile_app_iphone
            data_template:
              message: '''{{ trigger.from_state.attributes.friendly_name }}'''
              #you don't need the tag if you don't use a Iphone and want to delete messages
              data:
                tag: '''{{ trigger.from_state.attributes.friendly_name }}'''
    default: []

#this is only possible with Iphone I think
#delete notification if stock changes back to 0
  - choose: 
      - conditions:
          - condition: template
            value_template: '{{ trigger.to_state.state | float == 0 }}'
        sequence:
          - service: notify.mobile_app_iphone
            data:
              message: clear_notification
              data:
                tag: '''{{ trigger.from_state.attributes.friendly_name }}'''
    default: []
mode: parallel
max: 10

problem whit update sensor

System Health details

System Information

version core-2024.1.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 6.1.63-haos-raspi
arch aarch64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4848
Installed Version 1.33.0
Stage running
Available Repositories 1445
Downloaded Repositories 42
Home Assistant Cloud
logged_in true
subscription_expiration 31 mei 2024 02:00
relayer_connected true
relayer_region eu-central-1
remote_enabled true
remote_connected true
alexa_enabled false
google_enabled true
remote_server eu**.nabu.casa
certificate_status ready
instance_id
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 11.4
update_channel stable
supervisor_version supervisor-2023.12.1
agent_version 1.6.0
docker_version 24.0.7
disk_total 228.5 GB
disk_used 18.6 GB
healthy true
supported true
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Samba share (12.2.0), Node-RED (17.0.3), Home Assistant Google Drive Backup (0.112.1), Spotify Connect (0.13.0), ESPHome (2023.12.7), Studio Code Server (5.15.0), Mosquitto broker (6.4.0), Zigbee2MQTT (1.35.1-1), Z-Wave JS (0.4.3), Dutch gas prices (2023.10.15.1), InfluxDB (5.0.0), SQLite Web (4.1.0)
Dashboards
dashboards 5
resources 24
views 14
mode storage
Recorder
oldest_recorder_run 7 januari 2024 14:13
current_recorder_run 16 januari 2024 11:59
estimated_db_size 1880.18 MiB
database_engine sqlite
database_version 3.41.2
Spotify
api_endpoint_reachable ok

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

sensor wil not update, see log for more details

Reproduction steps

i dit nothing different than whit other sensors witch do work.

Debug logs

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:898 
First occurred: 16 januari 2024 12:04:51 (374 occurrences) 
Last logged: 19:19:52

Update for sensor.tgtg_wim_blom_ambachtsbakker_hasselt_verrassingspakket fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
                       ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/http/client.py", line 1378, in getresponse
    response.begin()
  File "/usr/local/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 799, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 467, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 462, in _make_request
    httplib_response = conn.getresponse()
                       ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/http/client.py", line 1378, in getresponse
    response.begin()
  File "/usr/local/lib/python3.11/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 898, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1218, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tgtg/sensor.py", line 211, in update
    self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tgtg/__init__.py", line 277, in get_item
    response = self.session.post(
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Diagnostics dump

No response

Price in attributes: 0 missing

As the TGTG price and Original value in the sensor attributes are no clean numbers, I cannot add a 0 to it (e.g. when the price is 10,50 EUR, the result is 10.5 EUR). I would like to have the 2nd digit behind the comma added, or to make it a clean number so that I can do it myself in my automation.

Item ID: 523323
Item URL: https://share.toogoodtogo.com/item/523323
TGTG Price: 3.5 EUR
Original value: 10.5 EUR
Pickup start: 2023-02-02T19:00:00Z
Pickup stop: 2023-02-02T19:25:00Z
unit_of_measurement: pcs
icon: mdi:storefront-outline

Import favorites items instead of manually define them

For me the whole configuration is not clearly described.
For instance I do not have a password for my account.
When I login with the TGTG iPhone app I use my email address.
Then I get an email with a login button and numeric code to login.
Is this numeric code (one-time-password?) the password that I should use?

Update:
I tried to use that numeric code with the "get items" script but it doesn't work, that gives an authentication failure.
But I got an email that I tried to logon from different device and that email also contained a link to reset password. After resetting and using that password it worked.

I also do not understand why my favourites are not used by default.
The upstream component seems to support that.
Instead I need to use a python script to get these. That is not user friendly at all (it only works for developers that are familiair with running python scripts). I would expect that I can just pick the items when I setup the configuration preferably in the Home Assistant UI.

How to get the api secrets as alternative for username and password is not well documented.

I am in the Netherlands BTW

[Need Help] Manage unknown or incorrect items ID

First of all, I do thank you for this add-on that is really great.
I configured the add-on using Manual list of items because i was having unavailable items.
but since today, I have two issues actually :

  • I added new items in my manual list that are not showing up as sensors. I don’t understand why. I restarted many times et tryed to reinstall the add-on. Nothing seems to work.
  • even if I use manual list, some items are not available. I don’t understand why neither.

Thank you in advance for your precious help.

[active bug] Setup of sensor platform fails

First of all: Thanks for this great integration!
Since yesterday, the tgtg platform can't setup sensors for me anymore. The stack trace indicates the API does require to solve a captcha, which can't be served obviously.

My first instinct would be the API is applying a rate limit, but I have an update_interval of 90 seconds, which imo is far from enough to warrant rate limiting.

So my second guess is TGTG changed their API and the integration needs to be updated, hence this issue.

Any help is much appreciated!

Stack trace:

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tgtg/sensor.py", line 67, in setup_platform
    add_entities([TGTGSensor(each_item_id)])
  File "/config/custom_components/tgtg/sensor.py", line 87, in __init__
    self.update()
  File "/config/custom_components/tgtg/sensor.py", line 180, in update
    self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 244, in get_item
    self.login()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 121, in login
    self._refresh_token()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 111, in _refresh_token
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'<html><head><title>apptoogoodtogo.com</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script>var dd={\'cid\':\'AHrlqAAAAAMAVhFJaKj7JkABIAMA8v8p7wALcUZE2qeLnQ==\',\'hsh\':\'1D42C2CA6131C526E09F294FE96F94\',\'t\':\'fe\',\'r\':\'b\',\'s\':35558,\'e\':\'6177e810c7ac55bdd21d8debfd47fb4b86161caf13e44a73112e4d839a8b6ccd\',\'host\':\'geo.captcha-delivery.com\'}</script><script src="https://ct.captcha-delivery.com/c.js"></script></body></html>\n')

Error 410 on first installation: "code":"ENTITY_DISABLED","message":"Entity ItemId(1234) is not active"

System Health details

System Information

version core-2023.7.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.4
os_name Linux
os_version 6.1.21-v8
arch aarch64
timezone Europe/Warsaw
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4716
Installed Version 1.32.1
Stage running
Available Repositories 1273
Downloaded Repositories 20
Airly
can_reach_server ok
requests_remaining 7
requests_per_day 100
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
GIOŚ
can_reach_server pending
Home Assistant Supervisor
host_os Home Assistant OS 10.3
update_channel stable
supervisor_version supervisor-2023.07.1
agent_version 1.5.1
docker_version 23.0.6
disk_total 116.5 GB
disk_used 15.2 GB
healthy true
supported true
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Terminal & SSH (9.7.1), File editor (5.6.0), Node-RED (14.4.1), RPC Shutdown (2.4), Mosquitto broker (6.2.1), Spotify Connect (0.12.4), Grocy (0.19.1), Home Assistant Google Drive Backup (0.111.1), AdGuard Home (4.8.12), ESPHome (2023.7.0), Zigbee2MQTT (1.32.1-1), Matter Server (4.8.3), Music Assistant BETA (2.0.0b59)
Dashboards
dashboards 7
resources 1
views 19
mode storage
Recorder
oldest_recorder_run 23 maja 2023 12:11
current_recorder_run 23 lipca 2023 00:13
estimated_db_size 1403.11 MiB
database_engine sqlite
database_version 3.41.2
Spotify
api_endpoint_reachable pending

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

Integration cannot set up.

Reproduction steps

  1. Setup integration using data from tgtg.py script

Please note this is a brand new account.

Debug logs

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tgtg/sensor.py", line 76, in setup_platform
    add_entities([TGTGSensor(each_item_id)])
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tgtg/sensor.py", line 96, in __init__
    self.update()
  File "/config/custom_components/tgtg/sensor.py", line 189, in update
    self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tgtg/__init__.py", line 287, in get_item
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (410, b'{"errors":[{"code":"ENTITY_DISABLED","message":"Entity ItemId(1234) is not active"}]}')

Diagnostics dump

No response

Docker container for tgtg_get_tokens

Would be great if we could just run a docker command to fire this up.
I will probably try this for myself. If I get anywhere I can post the docker file.
You would need build scripts to create the image, copy the tgtg_get_tokens script and upload to docker hub (or github packages).

Please enable JS and disable any ad blocker

Hi,

I get this error: see below

  • Installed version 4.2.2
  • no adblocker in use
  • HA version: 2023.1.6
raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'<html><head><title>apptoogoodtogo.com</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script data-cfasync="false">var dd={\'rt\':\'c\',\'cid\':\'********==\',\'hsh\':\'********\',\'t\':\'fe\',\'r\':\'b\',\'s\':35558,\'e\':\'********\',\'host\':\'geo.captcha-delivery.com\'}</script><script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script></body></html>\n')

Sensors show as unavailable

Hello
Some time ago sensor.tgtg became inaccessible.
There was this error in the logs
image
How can I fix this error?

Attribute 'item_price' is suddenly missing.

System Health details

System Information

version core-2023.12.4
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 5.4.0-169-generic
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4817
Installed Version 1.33.0
Stage running
Available Repositories 1367
Downloaded Repositories 27
AccuWeather
can_reach_server ok
remaining_requests 22
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Dashboards
dashboards 5
resources 17
views 25
mode storage
Recorder
oldest_recorder_run December 6, 2023 at 8:07 PM
current_recorder_run January 5, 2024 at 2:16 PM
estimated_db_size 718.14 MiB
database_engine mysql
database_version 11.2.2
Spotify
api_endpoint_reachable ok

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

I am getting an error, that no item price is returned anymore (also see the following screenshot):
image

I have already genrated a new token and have restarted home assistant but the attribute is still missing.

Reproduction steps

  1. Just take a look at the sensors.

Debug logs

-

Diagnostics dump

No response

HA doesnt finish checking config before restart

System Health details

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

after pasting in the config into a yaml file, HA doesnt finish checking the config before restart. The spinning icon never stops. Removing the config, it works as normal again.

Logging into terminal and forcing a reboot. fingers crossed.
EDIT: after forcing a reboot, the check config now works again. Maybe a full reboot was needed for the integration to settle?

  • platform: tgtg
    email: "[email protected]"
    access_token: "xxx"
    refresh_token: "xxx"
    user_id: "xxx"
    cookie: "xxx"
    scan_interval: 900

Reproduction steps

  1. Install TGTG via HACS
  2. reboot
  3. paste yaml config
    ...

Debug logs

-

Diagnostics dump

getting tokens by docker not working

System Health details

not relevant to HA

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

when running
docker build https://github.com/Chouffy/home_assistant_tgtg.git#main --tag "homeassistant_tgtg_tokens:latest"
on ubuntu 20
it fails with

_Collecting ruamel.yaml==0.15.72
  Downloading ruamel.yaml-0.15.72.tar.gz (309 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 309.9/309.9 KB 5.0 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 211, in <module>
          pkg_data = _package_data(__file__.replace('setup.py', '__init__.py'))
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 184, in _package_data
          data = literal_eval("".join(lines))
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 156, in literal_eval
          return _convert(node_or_string)
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 95, in _convert
          if isinstance(node, Str):
      NameError: name 'Str' is not defined
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
WARNING: You are using pip version 22.0.4; however, version 23.0.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
The command '/bin/sh -c python -m pip install -r requirements.txt' returned a non-zero code: 1_

Reproduction steps

  1. docker build https://github.com/Chouffy/home_assistant_tgtg.git#main --tag "homeassistant_tgtg_tokens:latest"

Debug logs

Collecting ruamel.yaml==0.15.72
  Downloading ruamel.yaml-0.15.72.tar.gz (309 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 309.9/309.9 KB 5.0 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'error'
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 211, in <module>
          pkg_data = _package_data(__file__.replace('setup.py', '__init__.py'))
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 184, in _package_data
          data = literal_eval("".join(lines))
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 156, in literal_eval
          return _convert(node_or_string)
        File "/tmp/pip-install-jw9mfj8a/ruamel-yaml_1fa05d8779c546a68d69b4b677d28004/setup.py", line 95, in _convert
          if isinstance(node, Str):
      NameError: name 'Str' is not defined
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
WARNING: You are using pip version 22.0.4; however, version 23.0.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
The command '/bin/sh -c python -m pip install -r requirements.txt' returned a non-zero code: 1

Diagnostics dump

No response

TGTG API Error 410 during startup

System Health details

System Information

version core-2023.11.0
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 6.1.59
arch x86_64
timezone Europe/Amsterdam
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4469
Installed Version 1.33.0
Stage running
Available Repositories 1324
Downloaded Repositories 30
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 11.1
update_channel stable
supervisor_version supervisor-2023.10.1
agent_version 1.6.0
docker_version 24.0.6
disk_total 30.8 GB
disk_used 17.2 GB
healthy true
supported true
board ova
supervisor_api ok
version_api ok
installed_addons Zigbee2MQTT (1.33.2-1), File editor (5.6.0), Mosquitto broker (6.3.1), Terminal & SSH (9.7.1), ESPHome (2023.10.6)
Dashboards
dashboards 3
resources 26
views 15
mode storage
Recorder
oldest_recorder_run 31 oktober 2023 om 08:21
current_recorder_run 4 november 2023 om 09:45
estimated_db_size 1062.96 MiB
database_engine sqlite
database_version 3.41.2

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

Sensors fail to work

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tgtg/sensor.py", line 77, in setup_platform
    add_entities([TGTGSensor(each_item_id)])
                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tgtg/sensor.py", line 97, in __init__
    self.update()
  File "/config/custom_components/tgtg/sensor.py", line 190, in update
    self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/tgtg/__init__.py", line 287, in get_item
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (410, b'{"errors":[{"code":"ENTITY_DISABLED"}]}')

Reproduction steps

Config:

sensor:
  - platform: tgtg
    email: !secret tgtg_username
    access_token: !secret tgtg_access_token
    refresh_token: !secret tgtg_refresh_token
    user_id: !secret tgtg_user_id
    cookie: !secret tgtg_cookie
    scan_interval: 180
    item:
      - xxxxx  # this contains actual IDs in my config. All the secrets also exist
      
  1. Restart Home Assistant
  2. The error will show up in the logs

I think this might be related to a new version of Home Assistant, because the problem started occurring after updating to 2023.11

Debug logs

Too big to paste, 15MB of data.

Diagnostics dump

No response

TGTG Login Not Working

I was logged in and the scanner was working, when i logged out to try a thing the token refreshed and with the same credentials i wasn't able to log in, i get TGTG configuration error, i also noticed that they don't use the password anymore, just the emailed code so i think it needs to be reworked
image

Cookies attribute missing

Tried to re-activate my (Dutch) TGTG integration, but ran into this issue:
Traceback (most recent call last): File "/home/esilverentand/tgtg_get_tokens.py", line 25, in <module> print(" cookie: '" + tgtgClient.cookie + "'") AttributeError: 'TgtgClient' object has no attribute 'cookie'
Downloaded the latest version of tgtg_get_tokens.py
Other data is found by the script

Unavailable entity

System Health details

System Information

version core-2023.3.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.10
os_name Linux
os_version 5.15.84-v8
arch aarch64
timezone Europe/Paris
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4865
Installed Version 1.31.0
Stage running
Available Repositories 1248
Downloaded Repositories 21
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 9.5
update_channel stable
supervisor_version supervisor-2023.03.1
agent_version 1.4.1
docker_version 20.10.22
disk_total 916.2 GB
disk_used 46.2 GB
healthy true
supported true
board rpi4-64
supervisor_api ok
version_api ok
installed_addons Samba share (10.0.0), Duck DNS (1.15.0), Terminal & SSH (9.6.1), ESPHome (2023.2.4), Zigbee2MQTT (1.30.2-1), motionEye (0.18.0), File editor (5.5.0), Mosquitto broker (6.1.3), ADS-B Multi-Portal Feeder (1.20.0)
Dashboards
dashboards 2
resources 15
views 13
mode storage
Recorder
oldest_recorder_run 12 mars 2023 à 10:37
current_recorder_run 15 mars 2023 à 19:38
estimated_db_size 39.57 MiB
database_engine sqlite
database_version 3.38.5

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

Since a few days, all the entity are unavailable and I get an error in the log. I've tried to reconnect by uninstalling and install again but nothing change. I don't really understand the meaning of the log. M'y configuration in yaml is exactly the same that python file gave to me. Thanks!

Reproduction steps

  1. Install tgtg integration
  2. Configure in configuration.yaml

...

Debug logs

Logger: homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:78
Integration: Capteur (documentation, issues)
First occurred: 19:38:37 (1 occurrences)
Last logged: 19:38:37

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tgtg/sensor.py", line 78, in setup_platform
    tgtgReply = tgtg_client.get_items()
  File "/usr/local/lib/python3.10/site-packages/tgtg/__init__.py", line 240, in get_items
    self.login()
  File "/usr/local/lib/python3.10/site-packages/tgtg/__init__.py", line 149, in login
    self._refresh_token()
  File "/usr/local/lib/python3.10/site-packages/tgtg/__init__.py", line 135, in _refresh_token
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'{"url":"https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMA1YnS04aHwZMA_5ewAw==&cid=1Jii7ZI_jXQxjr-XZRQ9OBcVRQxkH6ou81BsZMRZUEVTUWoJNfVuflue-oAzS-lbS2~Os5Y1~I91WQ-1gXmQ_zc2UaOAjwQsBTUp-2to8510PupRnRcj7c3OV-1mUOfy&referer=https%3A%2F%2Fapptoogoodtogo.com%2Fapi%2Fauth%2Fv3%2Ftoken%2Frefresh&hash=1D42C2CA6131C526E09F294FE96F94&t=fe&s=35558&e=4556d843f49a065b85ed7f6a8988a29c3c1e23d27bb436b5af7bcf65b71f8fec"}')

Diagnostics dump

No response

not every item is available.

The problem is that not every tgtg item is available.
Below is the error message in the log:

Logger: homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:186
Integration: Sensor (documentation, issues)
First occurred: 11:21:44 (1 occurrences)
Last logged: 11:21:44

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/tgtg/sensor.py", line 73, in setup_platform
add_entities([TGTGSensor(each_item_id)])
File "/config/custom_components/tgtg/sensor.py", line 93, in init
self.update()
File "/config/custom_components/tgtg/sensor.py", line 186, in update
self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 273, in get_item
raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (410, b'{"errors":[{"code":"ENTITY_DISABLED","message":"Entity ItemId(56298) is not active"}]}')

API returns 404

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

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

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.

Component does not run

Hello,

First of all, thank you for the good work you've been doing with the integration !

I installed the latest update to solve the 403 error I've been having for months, but the integration doesn't seem to launch.
I renewed my tokens using the script and updated the config accordingly, but it doesn't work even after several reboots.
I have nothing in the system journal, no tgtg entities.

Am I missing something ?

Product amounts unavailable

Hi there, what a great idea for addon!

Sadly I'm experiencing the same thing you talked about in the Q&A, but even after I added items manually I'm still getting Unavailable.

image

I'm running HA in docker.

the only log:

2022-02-09 14:08:58 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration tgtg which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

HA Automation trigger.to_state.attribute spacing instead of underscore

Hello,

Thanks voor the good integration, works perfect !
I have one problem with trigger state.

Some state attributes have spacing instead of underscore between words.
That means that my automation not giving the correct info, it give me error.
I use folllowing : {{trigger.to_state.attributes.TGTG Price}} , its not working because of spacing between TGTG and Price.

Following is working: {{trigger.to_state.attributes.friendly_name}}, it has the underscore between friendly and name.

Example attributes of sensor:
Item ID: '75581'
Item URL: https://share.toogoodtogo.com/item/75581
TGTG Price: 4.99 EUR
Original value: 14.99 EUR
unit_of_measurement: pcs
icon: mdi:storefront-outline
friendly_name: TGTG 't Bakkershuys

The attributes with underscores are working but I cant get the attributes with spacing instead of underscore,=.

Is there a simple tip or trick to get them in my automation?
Example: {{ trigger.to_state.attributes.TGTG Price}}

Hope the here from you.
Already Thanks,

Favorites limited to 25?

Hi,

I implemented your component yesterday, looks great. When I showed my wife, she added some more favorites to our TooGoodToGo app, which now has about 35 favorites (it was like 22).

After a reboot of HomeAssistant I see that some previous working sensors are now gone, and the amount of working sensors is 25. It looks like a hard limit, and by adding more than 25 favorites, some existing disappeared and some new do not show up.

Is the limit 25? If yes, is it possible to increase the limit?

Implement the ability to dynamically disable the sensor (preferably with a rate)

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

Sometimes I don't need TGTG to be active, why keep polling. Sometimes I would like to poll it more frequently.

Describe the solution you'd like

I would like to have the ability to set the polling to a very high or a lower interval. On the sensor configuration something like a slider that I can set with an automation.

Describe alternatives you've considered

Updating the config and manually restarting and

Additional context

None.

Something wrong with the latest update?

I have updated this component via hacs, so I would assume it would be automatic.

But I now get this:

Traceback (most recent call last):
  File "/home/skinkie/.local/lib/python3.10/site-packages/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/lib/python3.10/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 65, in setup_platform
    tgtg_client = TgtgClient(
TypeError: TgtgClient.__init__() got an unexpected keyword argument 'cookie'

[Improvement] Manage user_agent in a smarter way

  • Situation: user_agent is either defined:
    1. in tgtg module
    2. in this module, as a default one - see this in the code
    3. in this module, as a user configured string
  • Complication: this user_agent will change over time, as TGTG update their app and depreciate older ones
  • Improvement needed: how to make this sustainable? tell users how to look for it and update themselves the config?

If anybody has ideas, I'm listening :)

Unable to get this working

Hi guys, HA nooby here, I have the component installed via HACS, i've added to my configuration.yarl after running the py scripts etc..

I've added a custom sensor before and been fine, but for some reason I can't seem to get this one going - I get nothing in HA at all, no entitity or sensor at all - i've done the custom ID's etc, just wondering if there's anything obvious i'm missing?

I'm running HA via Truenas Scale - all files are downloaded in the custom component folder seemingly fine.

error after restarting HA

Logger: homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:186
Integration: Sensor (documentation, issues)
First occurred: 10:18:56 (1 occurrences)
Last logged: 10:18:56

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/tgtg/sensor.py", line 73, in setup_platform
add_entities([TGTGSensor(each_item_id)])
File "/config/custom_components/tgtg/sensor.py", line 93, in init
self.update()
File "/config/custom_components/tgtg/sensor.py", line 186, in update
self.tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 262, in get_item
self.login()
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 139, in login
self._refresh_token()
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 129, in _refresh_token
raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'<title>apptoogoodtogo.com</title><style>#cmsg{animation: A 1.5s;}@Keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style>

Please enable JS and disable any ad blocker

<script data-cfasync="false">var dd={'rt':'c','cid':'AHrlqAAAAAMAO6flr6g6whAA9rTuBw==','hsh':'1D42C2CA6131C526E09F294FE96F94','t':'fe','r':'b','s':35558,'e':'bf9fe76e3a1cf80d26a431ff0ff9f1c744ae00fd1d9fe2db0516c82ca0f7e91f','host':'geo.captcha-delivery.com'}</script><script data-cfasync="false" src="https://ct.captcha-delivery.com/c.js"></script>\n')

Implement update(self) as a service to trigger manual updates

Hi,

Thank you for this integration.

I am trying to find a way to manually trigger the checks. Does this integration provide this type of service/event?
With time, I came to know the best time to get an item. I would like to optimize the intervals of check for specific store.

Regards, AD.

Doesn't work anymore in 2022.2.3.0b1

Log:

INFO:homeassistant.util.package:Attempting install of tgtg>=0.11.0
ERROR:homeassistant.util.package:Unable to install package tgtg>=0.11.0: warning: missing-index-doctype
× The package index page being used does not have a proper HTML doctype declaration.
╰─> Problematic URL: https://wheels.home-assistant.io/alpine-3.14/amd64/
note: This is an issue with the page at the URL mentioned above.
hint: You might need to reach out to the owner of that package index, to get this fixed. See https://github.com/pypa/pip/issues/10825 for context.
ERROR: Cannot install tgtg==0.11.0 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
INFO:homeassistant.util.package:Attempting install of tgtg>=0.11.0
ERROR:homeassistant.util.package:Unable to install package tgtg>=0.11.0: warning: missing-index-doctype
× The package index page being used does not have a proper HTML doctype declaration.
╰─> Problematic URL: https://wheels.home-assistant.io/alpine-3.14/amd64/
note: This is an issue with the page at the URL mentioned above.
hint: You might need to reach out to the owner of that package index, to get this fixed. See https://github.com/pypa/pip/issues/10825 for context.
ERROR: Cannot install tgtg==0.11.0 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
INFO:homeassistant.util.package:Attempting install of tgtg>=0.11.0
ERROR:homeassistant.util.package:Unable to install package tgtg>=0.11.0: warning: missing-index-doctype
× The package index page being used does not have a proper HTML doctype declaration.
╰─> Problematic URL: https://wheels.home-assistant.io/alpine-3.14/amd64/
note: This is an issue with the page at the URL mentioned above.
hint: You might need to reach out to the owner of that package index, to get this fixed. See https://github.com/pypa/pip/issues/10825 for context.
ERROR: Cannot install tgtg==0.11.0 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
Failed config
  General Errors: 
    - Platform error sensor.tgtg - Requirements for tgtg not found: ['tgtg>=0.11.0'].

Seems to be related, (and I quote, because it doesn't mean a lot lot to me) to hard pin on requests here: https://github.com/ahivert/tgtg-python/blob/master/pyproject.toml#L11

(Captch?) Error during startup

I am experiencing the following error during Home Assistant startup. Could it be that it is requesting a Captcha response now to prevent this kind of integration?

Logger: homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:69
Integration: Sensor ([documentation](https://www.home-assistant.io/integrations/sensor), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+sensor%22))
First occurred: 10:28:27 (1 occurrences)
Last logged: 10:28:27

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tgtg/sensor.py", line 69, in setup_platform
    tgtgReply = tgtg_client.get_items()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 211, in get_items
    self.login()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 121, in login
    self._refresh_token()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 111, in _refresh_token
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'<html><head><title>apptoogoodtogo.com</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script>var dd={\'cid\':\'AHrlqAAAAAMASz11yZGnomMBKgKkaqsXAAF4H05OUfi8_A==\',\'hsh\':\'1D42C2CA6131C526E09F294FE96F94\',\'t\':\'fe\',\'r\':\'b\',\'s\':35558,\'e\':\'0f8d99b29500025d4e6d59b9f1758e231521a0c6e81bdcd5686e3e08f827e7de\',\'host\':\'geo.captcha-delivery.com\'}</script><script src="https://ct.captcha-delivery.com/c.js"></script></body></html>\n')

Configuration error when asking HA to restart - [email] is an invalid option

I've upgraded to the latest version and rerun the script for my config and pasted it in, but now my ha won't restart.

The system cannot restart because the configuration is not valid: Invalid config for [sensor.tgtg]: [email] is an invalid option for [sensor.tgtg]. Check: sensor.tgtg->email. (See ?, line ?).

Get tokens fails because of a captcha

System Health details

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

Reproduction steps

run the get tokens py

Debug logs

python3 tgtg_get_tokens.py 
Type your email linked to your TGTG account: [email protected]
Using version 23.4.12
Traceback (most recent call last):
  File "/root/tgtg_get_tokens.py", line 13, in <module>
    tgtgClient.get_credentials()
  File "/usr/local/lib/python3.10/dist-packages/tgtg/__init__.py", line 90, in get_credentials
    self.login()
  File "/usr/local/lib/python3.10/dist-packages/tgtg/__init__.py", line 181, in login
    raise TgtgLoginError(response.status_code, response.content)
tgtg.exceptions.TgtgLoginError: (403, b'{"url":"https://geo.captcha-delivery.com/captcha/?initialCid=AHrlqAAAAAMAdRgF1adAg_gA2WmLtw==&cid=86PDjw6-EpSxHPjvbU43ToKotX~i8HHzU1h2qr4e-FnmR_iSetqOR-6lSkG2eLprcf~cI8nfz7tzYKidv-OTGGfKhYlmg7yQaRlfYwVm8bL-r56HapF5Z-c6uGd1336&referer=https%3A%2F%2Fapptoogoodtogo.com%2Fapi%2Fauth%2Fv3%2FauthByEmail&hash=1D42C2CA6131C526E09F294FE96F94&t=fe&s=35587&e=6b1d5728fb084e8d880c6e0c40adab58986febb54699b2c4d83229fa46fd6df9"}')

Diagnostics dump

No response

problem just after installing Home Assistant 2023.1.2

Hello,
i just updated my HA from the last 2022 version directly to the 2023.1.2
since then, in the UI, all my TGTG are "not available" => it seems related to the new HA release (?)
i joined the logged error
Thanks in advance for your help :-)


Home Assistant 2023.1.2
Supervisor 2022.12.1
Operating System 9.4
Interface utilisateur : 20230104.0 - latest


Détails du journal (ERREUR)
Logger: homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:75
Integration: Capteur (documentation, issues)
First occurred: 06:19:55 (1 occurrences)
Last logged: 06:19:55

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 289, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/tgtg/sensor.py", line 75, in setup_platform
tgtgReply = tgtg_client.get_items()
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 229, in get_items
self.login()
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 139, in login
self._refresh_token()
File "/usr/local/lib/python3.10/site-packages/tgtg/init.py", line 129, in _refresh_token
raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (401, b'{"errors":[{"code":"UNAUTHORIZED","message":"Invalid token for: SoteriaRenewTokenRequest(clientIp=85.201.162.62, clientUserAgent=TGTG/22.12.1 Dalvik/2.1.0 (Linux; U; Android 10; SM-G935F Build/NRD90M), initiatedByUserId=null, permissions=0,5,12411195,0)"}]}')

Markdown card for on the dashboard

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

Hello,

Is there any way to create a markdown card or something like that, that fills automaticly with all the tgtg sensors, and displays only the sensors, that are active. Ofcourse i would love to see this with the attributes showen as well.

Example:

(only showen when 'available (status > 0, and not sold-out)', otherwise hidden):

'Happy Snacks (attr friendly_name)'
'10 (attr status)' pcs 'magic snack boxes (attr item_url)'
From: '€20,- (attr original_value)', for: '€5,- (attr item_price)'
Pickup from: '20:00 (attr pickup_start)' - '23:00 (attr pickup_end)'

Describe the solution you'd like

Maybe anybody can do something with auto-entities mod and/or markdown card?
I tried, but can't figure it out. I'm lacking skills for this.

Describe alternatives you've considered

Not have it showen on my dashboard... :-/

Additional context

(only showen when 'available (status > 0, and not sold-out )', otherwise hidden):

'Happy Snacks (attr friendly_name)'
'10 (attr status)' pcs 'magic snack boxes (attr item_url)'
From: '€20,- (attr original_value)', for: '€5,- (attr item_price)'
Pickup from: '20:00 (attr pickup_start)' - '23:00 (attr pickup_end)'

Error 403

I’m getting this error when logging in:

Logger:
homeassistant.components.sensor
Source: custom_components/tgtg/sensor.py:113 
Integration: Sensor (documentation, issues) 
First occurred: 9:15:52 PM (1 occurrences) 
Last logged: 9:15:52 PM

Error while setting up tgtg platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tgtg/sensor.py", line 63, in setup_platform
    add_entities([TGTGSensor(each_item_id)])
  File "/config/custom_components/tgtg/sensor.py", line 81, in __init__
    self.update()
  File "/config/custom_components/tgtg/sensor.py", line 113, in update
    tgtg_answer = tgtg_client.get_item(item_id=self.item_id)
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 180, in get_item
    self.login()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 106, in login
    self._refresh_token()
  File "/usr/local/lib/python3.9/site-packages/tgtg/__init__.py", line 91, in _refresh_token
    raise TgtgAPIError(response.status_code, response.content)
tgtg.exceptions.TgtgAPIError: (403, b'<html><head><title>apptoogoodtogo.com</title><style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style></head><body style="margin:0"><p id="cmsg">Please enable JS and disable any ad blocker</p><script>var dd={\'cid\':\'AHrlqAAAAAMAhDZvcVAoZ5oBKhA3gReKAABmQr8Yv76uRg==\',\'hsh\':\'1D42C2CA6131C526E09F294FE96F94\',\'t\':\'fe\',\'r\':\'b\',\'s\':35560,\'host\':\'geo.captcha-delivery.com\'}</script><script src="https://ct.captcha-delivery.com/c.js"></script></body></html>\n')

error while running tgtg_get_tokens script linked to new cookies attribute

When running the tgtg_get_tokens to generate the new tokens, In addition to the new tokens, I also get the follwing error. Any ideas what I am doing wrong here?

Traceback (most recent call last):
  File "C:\Users\xxxxx\Downloads\home_assistant_tgtg-5.0.0\tgtg_get_tokens.py", line 25, in <module>
    print("    cookie: '" + tgtgClient.cookie + "'")
AttributeError: 'TgtgClient' object has no attribute 'cookie'

Is scan_interval used?

I don't see any reference to scan_interval in the code, and also don't see my items updated.
What's going on here?

Unavailable sensors also not getting id

System Health details

System Information

version core-2023.5.2
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 5.19.0-41-generic
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
GitHub API Calls Remaining 4993
Installed Version 1.32.1
Stage running
Available Repositories 1289
Downloaded Repositories 21
HACS Data ok
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Dashboards
dashboards 4
resources 14
views 7
mode storage
Recorder
oldest_recorder_run May 1, 2023 at 1:00 PM
current_recorder_run May 10, 2023 at 6:10 PM
estimated_db_size 115.11 MiB
database_engine sqlite
database_version 3.40.1

Checklist

  • I have enabled debug logging for my installation.
  • I have filled out the issue template to the best of my ability.
  • This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • This issue is not a duplicate issue of currently previous issues..

Describe the issue

Hello Chouffy,
first of all thank you so much for your great integration! My girlfriend and I are very happy about getting a chance with the bags now :D

Unfortunately there is something weird happening now with some sensors of mine.
I had it configured without any special item IDs in the config and some sensors started showing as "unavailable".
I got a new token from your script and replaced the old one in my config, but the result was the same.
Next i tried the method of getting the item IDs through your script, but unfortunately the "unavalable" sensors didn't show up in the list:

item:
# ERGO Gourmet - Nürnberg (Mittag (VYTAL Mehrwegsystem))
- 980868
# Bean's coffee & more
- 52430
# Grand Zhang (Sushi Abends)
- 763621
# Grand Zhang (Buffet Abends)
- 755005
# 994 GINZA - Sushi | Izakaya (Überraschungstüte)
- 834205
# 994 GINZA - Sushi | Izakaya (Überraschungstüte (Groß))
- 841690
# Der Beck - Schwabacher Straße
- 344514
# Aral mit REWE To Go - Herrnstraße 27 Fürth (Vegetarisches Mittagsangebot)
- 849914
# Galeria Markthalle - Nürnberg (Obst & Gemüse)
- 807027
# Flink - Fürth (Obst und Gemüse)
- 827081
# Flink - Fürth (Ready to Eat)
- 685116
# Flink - Fürth (Überraschungstüte)
- 685114
# Früchte Fürther Freiheit
- 587630
# Flink - Johannis (Obst und Gemüse)
- 831828
# Aral mit REWE To Go - Nürnberger Straße 131 Fürth (Abendangebot)
- 835539
# Aral mit REWE To Go - Nürnberger Straße 126 Fürth (Abendangebot)
- 840710
# Kantine Wolke 7 (Überraschungstüte)
- 1046693
# Kantine Wolke 7 (Vegetarische Überraschungstüte)
- 1050321
# E center Schuler - Fürth (Obst & Gemüse)
- 463
# Suppenkaspar Fürth
- 342765

In the Screenshot you can see, that the missing IDs match the unavailable sensors.

tgtg_bug

In this screenshot you can see, that the item exists in the Tgtg App and was even available today, which it hasn't been in homeassistant for some time.

tgtg_krumelchen

Dropping the homeassistant.log here:
homeassistant.log

Reproduction steps

  1. Install the tgtg integration via Hacs as instructed in the readme
  2. Try to get item ids through the script
  3. Only get the ones that are also available in HomeAssistant

I am not sure what else might be relevant as I didn't really do anything out of the ordinary.

Debug logs

Github told me this comment was too long, so i appended the debug log to the issue.

Diagnostics dump

No response

Favourites missing after restart

Hello,
thank you for your work on this integration!
I have the problem, that I add new favourites in the TGTG-app and after a restart they are not showing up. They are even missing if I check the favourites using the python script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.