Anrolosia / Shopping-List-with-Grocy

A Shopping list integration with Grocy for Home Assistant
MIT License
41 stars 1 forks source link

Quantity missing as attribute #30

Closed saya6k closed 1 year ago

saya6k commented 1 year ago

Hi, Anrolosia!

Can you add qty_missing as attribute of individual sensor, 0 when there is enough and have value when product is missing?

In that way I can track which product is missing and dynamically trace them.

Thanks for your great work.

Anrolosia commented 1 year ago

Hello @saya6k , I will take a look at that as soon as possible :) Thank you

Anrolosia commented 1 year ago

Quick question for you @saya6k : Do you want me to use the "Minimum stock amount" field in grocy, and define a boolean (True/False) called qty_missing. This boolean should be true if the quantity in stock in less than the minimum defined for that product. Is that correct?

saya6k commented 1 year ago

Well, in my opinion, I want each sensor to have all attributes grocy provide, such as numbers minimum_amount and qty_in_stock_aggregated(I manage shoppinglist without sub-product, but now I can't get parent product to work), quantity missing, string: default_unit and boolean is_missing.

But anyway, I think I desperately need 2 attributes now:

Anrolosia commented 1 year ago

Thanks for your feedback.

Could you check your API Rest explorer (https:///api#/Generic%20entity%20interactions/get_objects__entity and test the products entity? This is an example of the fields I have, I just want to be sure it's the same on your side.

{
    "id": "1",
    "name": "Name",
    "description": "",
    "product_group_id": "",
    "active": "1",
    "location_id": "2",
    "shopping_location_id": "1",
    "qu_id_purchase": "2",
    "qu_id_stock": "2",
    "qu_factor_purchase_to_stock": "10.0",
    "min_stock_amount": "7",
    "default_best_before_days": "1",
    "default_best_before_days_after_open": "0",
    "default_best_before_days_after_freezing": "0",
    "default_best_before_days_after_thawing": "0",
    "picture_file_name": "kzqnnsdzwydib2aq687jg625195100030.jpg",
    "enable_tare_weight_handling": "0",
    "tare_weight": "0.0",
    "not_check_stock_fulfillment_for_recipes": "0",
    "parent_product_id": null,
    "calories": "0",
    "cumulate_min_stock_amount_of_sub_products": "0",
    "due_type": "1",
    "quick_consume_amount": "1.0",
    "hide_on_stock_overview": "0",
    "default_stock_label_type": "0",
    "should_not_be_frozen": "0",
    "row_created_timestamp": "2022-11-04 06:29:32",
    "treat_opened_as_out_of_stock": "1",
    "no_own_stock": "0",
    "default_consume_location_id": "",
    "move_on_open": "0"
  }
saya6k commented 1 year ago

I got this. I revised since first code was stock, not products. First entry is parent product and second is child product.

[
  {
    "id": 1,
    "name": "[우유]",
    "description": "",
    "product_group_id": 2,
    "active": 1,
    "location_id": 2,
    "shopping_location_id": "",
    "qu_id_purchase": 9,
    "qu_id_stock": 9,
    "qu_factor_purchase_to_stock": 1,
    "min_stock_amount": 0,
    "default_best_before_days": 45,
    "default_best_before_days_after_open": 7,
    "default_best_before_days_after_freezing": 0,
    "default_best_before_days_after_thawing": 0,
    "picture_file_name": null,
    "enable_tare_weight_handling": 0,
    "tare_weight": 0,
    "not_check_stock_fulfillment_for_recipes": 0,
    "parent_product_id": null,
    "calories": 0,
    "cumulate_min_stock_amount_of_sub_products": 1,
    "due_type": 2,
    "quick_consume_amount": 1,
    "hide_on_stock_overview": 0,
    "default_stock_label_type": 0,
    "should_not_be_frozen": 0,
    "row_created_timestamp": "2023-05-21 21:48:09",
    "treat_opened_as_out_of_stock": 1,
    "no_own_stock": 1,
    "default_consume_location_id": "",
    "move_on_open": 0
  },
  {
    "id": 88,
    "name": "리스테린 헬씨브라이트",
    "description": "",
    "product_group_id": 1,
    "active": 1,
    "location_id": 5,
    "shopping_location_id": "",
    "qu_id_purchase": 5,
    "qu_id_stock": 18,
    "qu_factor_purchase_to_stock": 1000,
    "min_stock_amount": 0,
    "default_best_before_days": 730,
    "default_best_before_days_after_open": 365,
    "default_best_before_days_after_freezing": 0,
    "default_best_before_days_after_thawing": 0,
    "picture_file_name": null,
    "enable_tare_weight_handling": 0,
    "tare_weight": 0,
    "not_check_stock_fulfillment_for_recipes": 0,
    "parent_product_id": 65,
    "calories": 0,
    "cumulate_min_stock_amount_of_sub_products": 0,
    "due_type": 2,
    "quick_consume_amount": 1,
    "hide_on_stock_overview": 1,
    "default_stock_label_type": 0,
    "should_not_be_frozen": 0,
    "row_created_timestamp": "2023-10-16 14:29:33",
    "treat_opened_as_out_of_stock": 0,
    "no_own_stock": 0,
    "default_consume_location_id": 6,
    "move_on_open": 0
  },
]
Anrolosia commented 1 year ago

I just pushed version 0.11.0, where I included those fields in HA.

Could you test if it answers your request?

saya6k commented 1 year ago

I updated to 0.11.0 but still same. I'm using HA 2023.10.3 and Grocy add-on 0.19.1(Grocy v3, not v4 yet).

group: 반찬/장류
list_count: 0
location: 냉장실
product_id: 16
product_image: ''
qty_in_stock: '0'
qu_factor_purchase_to_stock: '1.0'
topic: shopping-list-with-grocy/products/shopping_list_with_grocy_product_v1_16/state
userfields: {}
icon: mdi:cart
friendly_name: '[두부]'
Anrolosia commented 1 year ago

Hello @saya6k ,

Hummm, have you trigger a refresh of your products? This is what you should have: image

saya6k commented 1 year ago

Ohh, now I got result. Good.