Skip to content

Commit

Permalink
Fixes for auth api v4 (#146)
Browse files Browse the repository at this point in the history
* Don't use user_id, make it optional

* No need to get user_id for tokens

* Remove user_id from the README.md

* Update README.md

* Bump version to 5.5.0

* Update sensor.py
  • Loading branch information
tjorim authored Nov 23, 2024
1 parent c939d1d commit c13ae79
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This is to be executed outside of Home Assistant, i.e. on your local machine.

1. Install required packages.
- [Python >=3.8](https://www.python.org/downloads/)
- [tgtg-python](https://github.com/ahivert/tgtg-python) library: In a command line, type `pip install tgtg>=0.11.0` or `pip install --upgrade tgtg` if you already have it.
- [tgtg-python](https://github.com/ahivert/tgtg-python) library: In a command line, type `pip install tgtg==0.18.0` or `pip install --upgrade tgtg` if you already have it.
1. Run the [tgtg_get_tokens](./tgtg_get_tokens.py) script to get access and refresh token. Save these for later.

#### 1b. Docker
Expand Down Expand Up @@ -69,7 +69,6 @@ sensor:
# 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
Expand All @@ -81,12 +80,9 @@ sensor:
- 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](./tgtg_get_tokens.py) script!
`access_token`, `refresh_token` and `cookie` can be retrieved using the [tgtg_get_tokens](./tgtg_get_tokens.py) script!

### How to get item_id

Expand Down
2 changes: 1 addition & 1 deletion custom_components/tgtg/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/Chouffy/home_assistant_tgtg/issues",
"requirements": ["tgtg==0.18.0"],
"version": "5.4.3"
"version": "5.5.0"
}
6 changes: 2 additions & 4 deletions custom_components/tgtg/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
DOMAIN = "tgtg"
CONF_ITEM = "item"
CONF_REFRESH_TOKEN = "refresh_token"
CONF_USER_ID = "user_id"
CONF_COOKIE = "cookie"
CONF_USER_AGENT = "user_agent"
ATTR_ITEM_ID = "item_id"
Expand All @@ -38,8 +37,8 @@
{
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("user_id"): cv.string,
vol.Optional(CONF_EMAIL): vol.Email(),
vol.Optional(CONF_ITEM, default=""): cv.ensure_list,
vol.Optional(CONF_USER_AGENT, default=""): cv.string,
Expand All @@ -61,7 +60,6 @@ def setup_platform(
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]

Expand All @@ -71,7 +69,6 @@ def setup_platform(
tgtg_client = TgtgClient(
access_token=access_token,
refresh_token=refresh_token,
user_id=user_id,
cookie=cookie,
user_agent=user_agent,
)
Expand Down Expand Up @@ -184,6 +181,7 @@ def extra_state_attributes(self) -> dict | None:
data[ATTR_LOGO_URL] = self.tgtg_answer["item"]["logo_picture"]["current_url"]
if "cover_picture" in self.tgtg_answer["item"]:
data[ATTR_COVER_URL] = self.tgtg_answer["item"]["cover_picture"]["current_url"]

if "pickup_interval" in self.tgtg_answer:
if "start" in self.tgtg_answer["pickup_interval"]:
data[ATTR_PICKUP_START] = self.tgtg_answer["pickup_interval"]["start"]
Expand Down
1 change: 0 additions & 1 deletion tgtg_get_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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("")
Expand Down

0 comments on commit c13ae79

Please sign in to comment.