Skip to content

Commit

Permalink
Merge pull request #48 from tjorim/main
Browse files Browse the repository at this point in the history
Bump tgtg to 0.14.0 and self to 5.0.0
  • Loading branch information
Chouffy committed Jan 31, 2023
2 parents 0d00945 + 0ce164d commit 5610948
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion .github/workflows/hacs.yaml
Expand Up @@ -10,7 +10,7 @@ jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/checkout@v3"
- name: HACS validation
uses: "hacs/action@main"
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hassfest.yaml
Expand Up @@ -10,5 +10,5 @@ jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- uses: "actions/checkout@v3"
- uses: home-assistant/actions/hassfest@master
16 changes: 6 additions & 10 deletions README.md
@@ -1,10 +1,5 @@
# TooGoodToGo items stock as a sensor in Home Assistant

⚠ There's an [on-going issue](https://github.com/Chouffy/home_assistant_tgtg/issues/37) that prevents retrieving the `tgtg` data.
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).

---

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.
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)!

Expand All @@ -28,13 +23,14 @@ Sensor data can be used afterward to generate notifications, history graphs, ...
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: "123"

# Optional: email so you know which account is used
username: 'Your TGTG mail'
user_id: "123456"
cookie: "datadome=..."

# Optional: Refresh the stock every 15 minutes
scan_interval: 900
Expand All @@ -51,7 +47,7 @@ sensor:

```

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

### How to get item_id

Expand Down
4 changes: 2 additions & 2 deletions custom_components/tgtg/manifest.json
@@ -1,10 +1,10 @@
{
"domain": "tgtg",
"name": "TooGooToGo",
"version": "4.2.2",
"version": "5.0.0",
"documentation": "https://github.com/Chouffy/home_assistant_tgtg",
"issue_tracker": "https://github.com/Chouffy/home_assistant_tgtg/issues",
"codeowners": ["@chouffy"],
"requirements": ["tgtg>=0.13.1"],
"requirements": ["tgtg==0.14.0"],
"iot_class": "cloud_polling"
}
17 changes: 10 additions & 7 deletions custom_components/tgtg/sensor.py
Expand Up @@ -7,16 +7,16 @@

from homeassistant.components.sensor import SensorEntity, PLATFORM_SCHEMA
from homeassistant.core import HomeAssistant
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_EMAIL
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.helpers import config_validation as cv

DOMAIN = "tgtg"
CONF_ITEM = "item"
CONF_ACCESS_TOKEN = "access_token"
CONF_REFRESH_TOKEN = "refresh_token"
CONF_USER_ID = "user_id"
CONF_COOKIE = "cookie"
CONF_USER_AGENT = "user_agent"
ATTR_ITEM_ID = "Item ID"
ATTR_ITEM_ID_URL = "Item URL"
Expand All @@ -30,11 +30,12 @@

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_USERNAME): cv.string,
vol.Required(CONF_ACCESS_TOKEN): cv.string,
vol.Required(CONF_REFRESH_TOKEN): cv.string,
vol.Required(CONF_USER_ID): cv.string,
vol.Required(CONF_COOKIE): cv.string,
vol.Optional(CONF_EMAIL): vol.Email(),
vol.Optional(CONF_ITEM, default=""): cv.ensure_list,
vol.Optional(CONF_ACCESS_TOKEN, default=""): cv.string,
vol.Optional(CONF_REFRESH_TOKEN, default=""): cv.string,
vol.Optional(CONF_USER_ID, default=""): cv.string,
vol.Optional(CONF_USER_AGENT, default=""): cv.string,
}
)
Expand All @@ -50,11 +51,12 @@ def setup_platform(
) -> None:
"""Set up the sensor platform."""

username = config[CONF_USERNAME]
email = config[CONF_EMAIL]
item = config[CONF_ITEM]
access_token = config[CONF_ACCESS_TOKEN]
refresh_token = config[CONF_REFRESH_TOKEN]
user_id = config[CONF_USER_ID]
cookie = config[CONF_COOKIE]
user_agent = config[CONF_USER_AGENT]

global tgtg_client
Expand All @@ -64,6 +66,7 @@ def setup_platform(
access_token=access_token,
refresh_token=refresh_token,
user_id=user_id,
cookie=cookie,
user_agent=user_agent,
)

Expand Down
5 changes: 3 additions & 2 deletions tgtg_get_tokens.py
@@ -1,5 +1,5 @@
# Before running this, make sure that python3, pip and tgtg are installed!
# In a command line: pip install tgtg>=0.10.0
# In a command line: pip install tgtg==0.14.0

from tgtg import TgtgClient

Expand All @@ -18,10 +18,11 @@
print("")
print("sensor:")
print(" - platform: tgtg")
print(" username: '" + email + "'")
print(" email: '" + email + "'")
print(" access_token: '" + tgtgClient.access_token + "'")
print(" refresh_token: '" + tgtgClient.refresh_token + "'")
print(" user_id: '" + tgtgClient.user_id + "'")
print(" cookie: '" + tgtgClient.cookie + "'")
print(" scan_interval: 900")
print("")
input("Press enter to continue ...")

0 comments on commit 5610948

Please sign in to comment.