Chouffy / home_assistant_tgtg

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

Attribute 'item_price' is suddenly missing. #99

Closed simphide closed 8 months ago

simphide commented 8 months ago

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

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

simphide commented 8 months ago

If I see it correctly the item_price gets determined from the field ["item"]["price_including_taxes"]["minor_units"]

if "price_including_taxes" in self.tgtg_answer["item"]:
                data[ATTR_PRICE] = (
                    str(
                        int(
                            self.tgtg_answer["item"]["price_including_taxes"][
                                "minor_units"
                            ]
                        )
                        / pow(
                            10,
                            int(
                                self.tgtg_answer["item"]["price_including_taxes"][
                                    "decimals"
                                ]
                            ),
                        )
                    )
                    + " "
                    + self.tgtg_answer["item"]["price_including_taxes"]["code"]
                )

Looking at the raw response from the TGTG library it should be ["item"]["item_price"]["minor_units"]. image

tjorim commented 8 months ago

Thank you for the information, the API must have changed. It could be helpful for people to also report upstream. Their readme still mentions price_including_taxes as well: https://github.com/ahivert/tgtg-python/blob/master/README.md.

simphide commented 8 months ago

I have created a pull request. Thank you for the fast feedback!