Skip to content

Commit 5610948

Browse files
authored
Merge pull request #48 from tjorim/main
Bump tgtg to 0.14.0 and self to 5.0.0
2 parents 0d00945 + 0ce164d commit 5610948

File tree

7 files changed

+34
-23
lines changed

7 files changed

+34
-23
lines changed

.github/dependabot.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"

.github/workflows/hacs.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
validate:
1111
runs-on: "ubuntu-latest"
1212
steps:
13-
- uses: "actions/checkout@v2"
13+
- uses: "actions/checkout@v3"
1414
- name: HACS validation
1515
uses: "hacs/action@main"
1616
with:

.github/workflows/hassfest.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ jobs:
1010
validate:
1111
runs-on: "ubuntu-latest"
1212
steps:
13-
- uses: "actions/checkout@v2"
13+
- uses: "actions/checkout@v3"
1414
- uses: home-assistant/actions/hassfest@master

README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# TooGoodToGo items stock as a sensor in Home Assistant
22

3-
⚠ There's an [on-going issue](https://github.com/Chouffy/home_assistant_tgtg/issues/37) that prevents retrieving the `tgtg` data.
4-
This module will probably won't work for you right now, unlessit is resolved on the upstream module - see [this issue](https://github.com/ahivert/tgtg-python/issues/205).
5-
6-
---
7-
83
This aim to show the stock of one or multiple [TooGoodToGo](https://toogoodtogo.com/) item using the [tgtg-python](https://github.com/ahivert/tgtg-python) library.
94
Sensor data can be used afterward to generate notifications, history graphs, ... share your best examples in the [Discussion tab](https://github.com/Chouffy/home_assistant_tgtg/discussions)!
105

@@ -28,13 +23,14 @@ Sensor data can be used afterward to generate notifications, history graphs, ...
2823
sensor:
2924
- platform: tgtg
3025

26+
# Optional: email so you know which account is used
27+
email: 'Your TGTG mail'
28+
3129
# Mandatory: tokens for authentication - see the tgtg_get_tokens.py script
3230
access_token: "abc123"
3331
refresh_token: "abc123"
34-
user_id: "123"
35-
36-
# Optional: email so you know which account is used
37-
username: 'Your TGTG mail'
32+
user_id: "123456"
33+
cookie: "datadome=..."
3834

3935
# Optional: Refresh the stock every 15 minutes
4036
scan_interval: 900
@@ -51,7 +47,7 @@ sensor:
5147

5248
```
5349

54-
`access_token`, `refresh_token` and `user_id` can be retrieved using the [tgtg_get_tokens](./tgtg_get_tokens.py) script!
50+
`access_token`, `refresh_token`, `user_id` and `cookie` can be retrieved using the [tgtg_get_tokens](./tgtg_get_tokens.py) script!
5551

5652
### How to get item_id
5753

custom_components/tgtg/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"domain": "tgtg",
33
"name": "TooGooToGo",
4-
"version": "4.2.2",
4+
"version": "5.0.0",
55
"documentation": "https://github.com/Chouffy/home_assistant_tgtg",
66
"issue_tracker": "https://github.com/Chouffy/home_assistant_tgtg/issues",
77
"codeowners": ["@chouffy"],
8-
"requirements": ["tgtg>=0.13.1"],
8+
"requirements": ["tgtg==0.14.0"],
99
"iot_class": "cloud_polling"
1010
}

custom_components/tgtg/sensor.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
from homeassistant.components.sensor import SensorEntity, PLATFORM_SCHEMA
99
from homeassistant.core import HomeAssistant
10-
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
10+
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL
1111
from homeassistant.helpers.entity_platform import AddEntitiesCallback
1212
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
1313
from homeassistant.helpers import config_validation as cv
1414

1515
DOMAIN = "tgtg"
1616
CONF_ITEM = "item"
17-
CONF_ACCESS_TOKEN = "access_token"
1817
CONF_REFRESH_TOKEN = "refresh_token"
1918
CONF_USER_ID = "user_id"
19+
CONF_COOKIE = "cookie"
2020
CONF_USER_AGENT = "user_agent"
2121
ATTR_ITEM_ID = "Item ID"
2222
ATTR_ITEM_ID_URL = "Item URL"
@@ -30,11 +30,12 @@
3030

3131
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
3232
{
33-
vol.Optional(CONF_USERNAME): cv.string,
33+
vol.Required(CONF_ACCESS_TOKEN): cv.string,
34+
vol.Required(CONF_REFRESH_TOKEN): cv.string,
35+
vol.Required(CONF_USER_ID): cv.string,
36+
vol.Required(CONF_COOKIE): cv.string,
37+
vol.Optional(CONF_EMAIL): vol.Email(),
3438
vol.Optional(CONF_ITEM, default=""): cv.ensure_list,
35-
vol.Optional(CONF_ACCESS_TOKEN, default=""): cv.string,
36-
vol.Optional(CONF_REFRESH_TOKEN, default=""): cv.string,
37-
vol.Optional(CONF_USER_ID, default=""): cv.string,
3839
vol.Optional(CONF_USER_AGENT, default=""): cv.string,
3940
}
4041
)
@@ -50,11 +51,12 @@ def setup_platform(
5051
) -> None:
5152
"""Set up the sensor platform."""
5253

53-
username = config[CONF_USERNAME]
54+
email = config[CONF_EMAIL]
5455
item = config[CONF_ITEM]
5556
access_token = config[CONF_ACCESS_TOKEN]
5657
refresh_token = config[CONF_REFRESH_TOKEN]
5758
user_id = config[CONF_USER_ID]
59+
cookie = config[CONF_COOKIE]
5860
user_agent = config[CONF_USER_AGENT]
5961

6062
global tgtg_client
@@ -64,6 +66,7 @@ def setup_platform(
6466
access_token=access_token,
6567
refresh_token=refresh_token,
6668
user_id=user_id,
69+
cookie=cookie,
6770
user_agent=user_agent,
6871
)
6972

tgtg_get_tokens.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Before running this, make sure that python3, pip and tgtg are installed!
2-
# In a command line: pip install tgtg>=0.10.0
2+
# In a command line: pip install tgtg==0.14.0
33

44
from tgtg import TgtgClient
55

@@ -18,10 +18,11 @@
1818
print("")
1919
print("sensor:")
2020
print(" - platform: tgtg")
21-
print(" username: '" + email + "'")
21+
print(" email: '" + email + "'")
2222
print(" access_token: '" + tgtgClient.access_token + "'")
2323
print(" refresh_token: '" + tgtgClient.refresh_token + "'")
2424
print(" user_id: '" + tgtgClient.user_id + "'")
25+
print(" cookie: '" + tgtgClient.cookie + "'")
2526
print(" scan_interval: 900")
2627
print("")
2728
input("Press enter to continue ...")

0 commit comments

Comments
 (0)