Giter VIP home page Giter VIP logo

pygrocy's Issues

Get product by Barcode

First of all, very cool project, it seems to make very straight forward to integrate grocy with other systems.

I would like to add/consume products by scanning their barcodes unfortunately I haven't found a way to retrieve the product_id by giving the barcode, is it that possible?

In the grocy-pyscanner they do it by a get request, so it is possible bu I haven't found how to do it in pygrocy.
Thanks a lot!

Misnaming in enum

Should be who-least-did-first

WHO_DID_LEAST_DID_FIRST = 'who-did-least-did-first'

Traceback (most recent call last):
File "/config/custom_components/grocy/init.py", line 227, in async_update_chores
] = await self.hass.async_add_executor_job(wrapper)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/grocy/init.py", line 223, in wrapper
return self.client.chores(True)
File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 461, in chores
chore.get_details(self._api_client)
File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 243, in get_details
self._init_from_ChoreDetailsResponse(details)
File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 221, in _init_from_ChoreDetailsResponse
self._assignment_type = Chore.AssignmentType(chore_data.assignment_type)
File "/usr/local/lib/python3.8/enum.py", line 304, in call
return cls.new(cls, value)
File "/usr/local/lib/python3.8/enum.py", line 595, in new
raise exc
File "/usr/local/lib/python3.8/enum.py", line 579, in new
result = cls.missing(value)
File "/usr/local/lib/python3.8/enum.py", line 608, in missing
raise ValueError("%r is not a valid %s" % (value, cls.name))
ValueError: 'who-least-did-first' is not a valid AssignmentType

Return values inconsistent between API call methods

When implementing stuff in grocy-telegram-bot using the remove_product_in_shopping_list() and add_product() methods of pygrocy I stumbled over the fact that the first does return the HTTP response but the latter does not. This is a problem, especially since you do not use the response.raise_for_status() method, because errors happening on the API side will just get lost, even if the developer was cautious enough to check the method result.

I don't know if you have a plan on how to deal with this going forward, but imho pygrocy should never return any HTTP related data back to the developer using the library since that would negate the whole point of an abstraction layer.

In a different project I was involved with we always used the raise_for_status() method. Imho a little restructuring would greatly benefit the readability and simplicity of the API call related methods. Have a look at the _do_request method here which allowed us to turn all of the API call methods into one-liners.

PS: I know you are currently busy, so I don't expect you to do anything. A little heads up would be great though 🀞

404 errors and unresponsive sensors after configuring integration in HA

I have set up Grocy as an HA-Addon and wanted to use the lovelace-grocy-chores-card which needs the grocy_chores sensor.

I installed this integration through HACS, and I was finally able to configure the integration by using my internal HA url https://10.0.2.3:9192/grocy/public/api/ even though I use a duckdns domain through the HA NGINX proxy manager.

The issue I am getting is that the new Grocy sensors are all showing as unknown. If I check the API key it shows that the integration is connecting ok.

image

I checked the logs and this is what it shows:

2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.config_flow] Step user
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.config_flow] Testing credentials
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.config_flow] Testing of credentials returned: 
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.config_flow] True
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.setup] Setting up grocy
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.setup] Setup of domain grocy took 0.0 seconds
2021-02-25 20:34:08 INFO (MainThread) [custom_components.grocy] 
-------------------------------------------------------------------
Grocy
Version: v2.2.2
This is a custom integration!
If you have any issues with this you need to open an issue here:
https://github.com/custom-components/grocy/issues
-------------------------------------------------------------------

2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 0.027 seconds
2021-02-25 20:34:08 WARNING (MainThread) [homeassistant.components.binary_sensor] BinarySensorDevice is deprecated, modify GrocyBinarySensor to extend BinarySensorEntity
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.grocy
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.grocy
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.EXPIRED_PRODUCTS binary sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.EXPIRING_PRODUCTS binary sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.MISSING_PRODUCTS binary sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.OVERDUE_CHORES binary sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.OVERDUE_TASKS binary sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.CHORES sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.MEAL_PLAN sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.SHOPPING_LIST sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.STOCK sensor
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.TASKS sensor
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.grocy entity: binary_sensor.grocy_expiring_products
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Not adding entity Grocy expiring products because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.grocy entity: binary_sensor.grocy_missing_products
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Not adding entity Grocy missing products because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.grocy entity: binary_sensor.grocy_overdue_chores
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Not adding entity Grocy overdue chores because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.grocy entity: binary_sensor.grocy_overdue_tasks
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Not adding entity Grocy overdue tasks because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.grocy entity: sensor.grocy_chores
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Not adding entity Grocy chores because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.grocy entity: sensor.grocy_meal_plan
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Not adding entity Grocy meal plan because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.grocy entity: sensor.grocy_shopping_list
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Not adding entity Grocy shopping list because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.grocy entity: sensor.grocy_stock
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Not adding entity Grocy stock because it's disabled
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.grocy entity: sensor.grocy_tasks
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.sensor] Not adding entity Grocy tasks because it's disabled
2021-02-25 20:34:08 ERROR (MainThread) [custom_components.grocy] Update of Expired_products failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:34:08 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 0.080 seconds
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.grocy entity: binary_sensor.grocy_expired_products
2021-02-25 20:34:08 INFO (MainThread) [homeassistant.components.binary_sensor] Not adding entity Grocy expired products because it's disabled

I have manually enabled the sensors, but the sensors still show as unknown.

2021-02-25 20:41:09 INFO (MainThread) [homeassistant.config_entries] Reloading configuration entries because disabled_by changed in entity registry: 
2021-02-25 20:41:09 DEBUG (MainThread) [custom_components.grocy] Unloading with state loaded
2021-02-25 20:41:09 DEBUG (MainThread) [custom_components.grocy] Unloaded? True
2021-02-25 20:41:09 INFO (MainThread) [custom_components.grocy] 
-------------------------------------------------------------------
Grocy
Version: v2.2.2
This is a custom integration!
If you have any issues with this you need to open an issue here:
https://github.com/custom-components/grocy/issues
-------------------------------------------------------------------

2021-02-25 20:41:09 INFO (SyncWorker_35) [custom_components.authenticated.sensor] New successful login from known IP (172.30.33.10)
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 0.359 seconds
2021-02-25 20:41:10 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.grocy
2021-02-25 20:41:10 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.grocy
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.EXPIRED_PRODUCTS binary sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.EXPIRING_PRODUCTS binary sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.MISSING_PRODUCTS binary sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.OVERDUE_CHORES binary sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.binary_sensor] Adding GrocyEntityType.OVERDUE_TASKS binary sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.CHORES sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.MEAL_PLAN sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.SHOPPING_LIST sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.STOCK sensor
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy.sensor] Adding GrocyEntityType.TASKS sensor
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Expired_products failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Expiring_products failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Missing_products failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Overdue_chores failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Overdue_tasks failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Chores failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Meal_plan failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Shopping_list failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Stock failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 ERROR (MainThread) [custom_components.grocy] Update of Tasks failed with 404 Client Error: Not Found for url: https://10.0.2.3:9192/grocy/public/api/:9192/api/system/db-changed-time
2021-02-25 20:41:10 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 0.637 seconds

Clearly, I have done something wrong and I really believe that the api url is not right, but it is the only one I can get the integration to configure with.

Any help to find the error would be greatly appreciated.
Thank you

Dependabot can't evaluate your Python dependency files

Dependabot can't evaluate your Python dependency files.

As a result, Dependabot couldn't check whether any of your dependencies are out-of-date.

The error Dependabot encountered was:

InstallationError("Invalid requirement: 'requests=2.21.0'\n= is not a valid operator. Did you mean == ?",)

You can mention @dependabot in the comments below to contact the Dependabot team.

Lovelace not accessible

Describe the bug
I cannot access the UI of Home Assistant.
In the home-assistant.log I found lots of errors like this:

2021-03-08 12:21:42 ERROR (MainThread) [homeassistant.components.websocket_api.messages] Unable to serialize to JSON. Bad data found at $.event(event: state_changed).data.new_state(state: binary_sensor.grocy_missing_products).attributes.missing[0].product_barcodes[0]=<pygrocy.grocy_api_client.ProductBarcode object at 0xa7bcac40>(<class 'pygrocy.grocy_api_client.ProductBarcode'>
2021-03-08 12:21:42 WARNING (Recorder) [homeassistant.components.recorder] State is not JSON serializable: <state binary_sensor.grocy_missing_products=on; missing=[{'name': 'My product name', 'id': 5, 'product_group_id': None, 'available_amount': None, 'best_before_date': None, 'barcodes': ['20456887'], 'product_barcodes': [<pygrocy.grocy_api_client.ProductBarcode object at 0xa7bcac40>], 'amount_missing': 1.0, 'is_partly_in_stock': False}], friendly_name=Grocy missing products, icon=GrocyEntityIcon.MISSING_PRODUCTS @ 2021-03-08T12:21:42.740123+02:00>
2021-03-08 12:21:47 ERROR (MainThread) [homeassistant.components.http.view] Unable to serialize to JSON: Object of type ProductBarcode is not JSON serializable

The log file grows to 1GB and maybe more.

Expected behavior
Being able to use the lovelace UI as before.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the main URL of Home Assistant OR open the Home Assistant mobile app
  2. A blank page is displayed forever with the message "loading data"

What is your installed versions of Home Assistant, Grocy and this integration?
Home Assistant core-2021.3.2
Grocy v3.0.1
Grocy integration v3.0.1

How do you have Grocy installed? Add-on or external?
add-on
Have you added debugging to the log, and what does the log say?
no
JSON service data (if related to using a service)
n/a

Additional context
I had to hard reboot my Raspberry Pi and then disable quickly the Grocy integration add-on.
If not doing that quickly after reboot, I have the same issue.

Change base url and add port

Hi.

What do you think about changing base url like : https://{HOST}:{PORT}
removing /api/ (I saw some confusion from users)
(Default port for Grocy is 9192, can optional)

Regards :)

Various exceptions when stock features disabled

I tried to disable some of the stock features I don't need.

# Sub feature flags
Setting('FEATURE_FLAG_STOCK_PRICE_TRACKING', false);
Setting('FEATURE_FLAG_STOCK_LOCATION_TRACKING', false);
Setting('FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING', true);
Setting('FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING', true);
Setting('FEATURE_FLAG_STOCK_PRODUCT_FREEZING', false);
Setting('FEATURE_FLAG_SHOPPINGLIST_MULTIPLE_LISTS', false);
Setting('FEATURE_FLAG_CHORES_ASSIGNMENTS', false);

But this leads to various exceptions when reading the expired products:

Traceback (most recent call last):
  ...
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy.py", line 179, in expired_products
    item.get_details(self._api_client)
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy.py", line 24, in get_details
    details = api_client.get_product(self.product_id)
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 322, in get_product
    return ProductDetailsResponse(parsed_json)
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 231, in __init__
    self._location = LocationData(parsed_json.get('location'))
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 52, in __init__
    self._id = parse_int(parsed_json.get('id'))
AttributeError: 'NoneType' object has no attribute 'get'

And

Traceback (most recent call last):
  ...
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy.py", line 199, in chores
    raw_chores = self._api_client.get_chores()
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 328, in get_chores
    return [CurrentChoreResponse(chore) for chore in parsed_json]
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 328, in <listcomp>
    return [CurrentChoreResponse(chore) for chore in parsed_json]
  File "/usr/local/lib/python3.7/site-packages/pygrocy/grocy_api_client.py", line 156, in __init__
    self._chore_id = parse_int(parsed_json.get('chore_id'), None)
AttributeError: 'str' object has no attribute 'get'

change assertions in test to unittest ones

as noted in #72 currently most assertions arent being done with the assertions of the unittest package. All assertions should get replaced by the assertions available in this package.

Better error messages

In ha with the component I only get these error messages, no matter what the reason for the 400 is.

requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://192.168.1.78:9192/api/objects/tasks

Grocy is however also sending an error_message, like this:

"{\"error_message\":\"SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: tasks.name\"}"

It would be awesome to get these in the error message from the lib too.

Consider grocy version

We already speak about it.
I think we have to take care of Grocy version : db blueprint is changing across versions and it can break end-user usages.

Keep in touch :)

utils tests miss changes in functionality

While playing with MutPy I found out that the following mutations don't lead to failing tests:

   - [#   1] COI utils:
--------------------------------------------------------------------------------
   1: import iso8601
   2:
   3:
   4: def parse_date(input_value):
-  5:     if input_value is None:
+  5:     if not (input_value is None):
   6:         return None
   7:     return iso8601.parse_date(input_value)
   8:
   9:
--------------------------------------------------------------------------------
[0.00575 s] survived
   - [#   2] COI utils:
--------------------------------------------------------------------------------
   7:     return iso8601.parse_date(input_value)
   8:
   9:
  10: def parse_int(input_value, default_value=None):
- 11:     if input_value is None:
+ 11:     if not (input_value is None):
  12:         return default_value
  13:     try:
  14:         return int(input_value)
  15:     except ValueError:
--------------------------------------------------------------------------------
[0.00661 s] survived
   - [#   3] COI utils:
--------------------------------------------------------------------------------
  16:         return default_value
  17:
  18:
  19: def parse_float(input_value, default_value=None):
- 20:     if input_value is None:
+ 20:     if not (input_value is None):
  21:         return default_value
  22:     try:
  23:         return float(input_value)
  24:     except ValueError:
--------------------------------------------------------------------------------
[0.00899 s] survived
   - [#   4] EHD utils:
--------------------------------------------------------------------------------
  12:         return default_value
  13:     try:
  14:         return int(input_value)
  15:     except ValueError:
- 16:         return default_value
+ 16:         raise
  17:
  18:
  19: def parse_float(input_value, default_value=None):
  20:     if input_value is None:
--------------------------------------------------------------------------------
[0.00770 s] survived
   - [#   5] EHD utils:
--------------------------------------------------------------------------------
  21:         return default_value
  22:     try:
  23:         return float(input_value)
  24:     except ValueError:
- 25:         return default_value
+ 25:         raise
--------------------------------------------------------------------------------
[0.00714 s] survived
   - [#   6] EXS utils:
--------------------------------------------------------------------------------
  12:         return default_value
  13:     try:
  14:         return int(input_value)
  15:     except ValueError:
- 16:         return default_value
+ 16:         pass
  17:
  18:
  19: def parse_float(input_value, default_value=None):
  20:     if input_value is None:
--------------------------------------------------------------------------------
[0.00712 s] survived
   - [#   7] EXS utils:
--------------------------------------------------------------------------------
  21:         return default_value
  22:     try:
  23:         return float(input_value)
  24:     except ValueError:
- 25:         return default_value
+ 25:         pass
--------------------------------------------------------------------------------

With product location disabled nothing works

You can disable location tracking in the grocy addon with stock_location_tracking: false.
If that is configured I noticed pygrocy will not be able to handle a shopping list call with items without location in it. Location should perhaps be optional.

complete abstraction on top of server data classes

Currently, some methods in Grocy return response objects and some methods return objects independent of the server representation. In this issue, all methods in Grocy should be changed to return a representation of an entity which is independent of the representation on the server side. It may be needed to create additional classes to achieve this.

Task without due date gives error

Add a check for due date before parsing

Traceback (most recent call last):
  File "/config/custom_components/grocy/__init__.py", line 268, in async_update_tasks
    ] = await self.hass.async_add_executor_job(self.client.tasks)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy.py", line 591, in tasks
    raw_tasks = self._api_client.get_tasks()
  File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 649, in get_tasks
    return [TaskResponse(data) for data in parsed_json]
  File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 649, in <listcomp>
    return [TaskResponse(data) for data in parsed_json]
  File "/usr/local/lib/python3.8/site-packages/pygrocy/grocy_api_client.py", line 458, in __init__
    self.due_date = parse_date(parsed_json.get("due_date"))
  File "/usr/local/lib/python3.8/site-packages/pygrocy/utils.py", line 10, in parse_date
    return iso8601.parse_date(input_value)
  File "/usr/local/lib/python3.8/site-packages/iso8601/iso8601.py", line 195, in parse_date
    raise ParseError("Unable to parse date string %r" % datestring)
iso8601.iso8601.ParseError: Unable to parse date string ''

Missing data in CurrentVolatilStockResponse._missing_products

Hi!

First of all many thanks for pygrocy, I have been using it for a while and it helped me a lot!

I think I got a parse error when I try to get the missing products using grocy.missing_products()

If I check the JSON I See:

"missing_products": [
        {
            "id": "7",
            "name": "XXXX",
            "amount_missing": "1",
            "is_partly_in_stock": "1"
        },
        {
            "id": "8",
            "name": "YYYY",
            "amount_missing": "1",
            "is_partly_in_stock": "1"
        },
        {
            "id": "75",
            "name": "ZZZZ",
            "amount_missing": "1",
            "is_partly_in_stock": "1"
        }
    ]

But diving in CurrentStockResponse is expecting antother property names:

self._product_id = parse_int(parsed_json.get('product_id'))
self._amount = parse_float(parsed_json.get('amount'))
self._best_before_date = parse_date(parsed_json.get('best_before_date'))
self._amount_opened = parse_float(parsed_json.get('amount_opened'))

Do we might need a new class to represent missing products?

If so, I can try to open a PR with that change.

Change id property names to "id" instread of "something_id"

Hey there, great library!

I'm using your library to build a telegram bot to interact with grocy. So far it works great! πŸ‘
However, when dealing with entities of different types it is cumbersome that they all have different names for their id property. Would it be possible to rename all those properties (product_id, chore_id etc.) to just id? Is the grocy API giving the info out this way or did you choose to do this for some reason?

Thx

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.