Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wine Drink Date #18

Open
RedOctoberSUI opened this issue May 6, 2022 · 7 comments
Open

Wine Drink Date #18

RedOctoberSUI opened this issue May 6, 2022 · 7 comments

Comments

@RedOctoberSUI
Copy link

What a great integration, thank you very much! Not a bug, more a very kind request: Any chance we can get the "Drink by" data? After all, this is what most people use CT for :)

Thank you very much!

@rwez
Copy link

rwez commented Mar 22, 2023

True. This I would like to see too, if at all possible.

@pmaere
Copy link

pmaere commented Apr 2, 2023

I'd like to add that with the list of bottles that you have. Will need some help on quality assurance. Anyone interested?

@rwez
Copy link

rwez commented Apr 2, 2023

what can I do to help ?

@RedOctoberSUI
Copy link
Author

RedOctoberSUI commented Apr 2, 2023 via email

@pmaere
Copy link

pmaere commented Apr 3, 2023

what can I do to help ?

I figured out yesterday that basically all the data of your cellar should be available. The question is how to get it in home assistant. You can add groups, but I actually want just a list of bottles with their characteristics.
I'm very limited in time, so if I can get something working on my HA instance, I might forward the changes for someone to perfect and do the PR on github.
If I find the time...

@pmaere
Copy link

pmaere commented Apr 17, 2023

Ok, i got this to work.

First, you need to change the following class in your init file:

class WineCellarData:
    """Get the latest data and update the states."""

    def __init__(self, username, password):
        """Init the Canary data object."""

        # self._api = Api(username, password, timeout)

        # self._locations_by_id = {}
        # self._readings_by_device_id = {}
        self._username = username
        self._password = password
        

    def get_reading(self, key):
      return self._data[key]

    def get_readings(self):
      return self._data

    @Throttle(MIN_TIME_BETWEEN_UPDATES)
    def update(self, **kwargs):
      data = {}
      username = self._username
      password = self._password


      client = cellartracker.CellarTracker(username, password)
      list = client.get_inventory()
      df = pd.DataFrame(list)
      df[["Price","Valuation"]] = df[["Price","Valuation"]].apply(pd.to_numeric)
      
      group_data = df.groupby(["iWine"]).agg({'Wine': ['count', 'first'], 'Valuation': ['sum', 'mean'], 'Appellation': 'first','Vintage': 'first', 'Color': 'first', 'BeginConsume':'first','EndConsume':'first'})
      group_data.columns = ['_'.join(col).strip() if col[1] else col[0] for col in group_data.columns.values]
      for row_main, item_main in group_data.iterrows():
          # the name represents the group
          name = item_main['Wine_first'] + '_' + item_main['Vintage_first']
          data[name] = {}
          data[name][row_main] = {"count": item_main['Wine_count'], "value_total": item_main['Valuation_sum'],
                             "value_avg": item_main['Valuation_mean'], "%": 1}
          data[name][row_main]["Wine Name"] = item_main['Wine_first']
          data[name][row_main]["Vintage"] = item_main['Vintage_first']
          data[name][row_main]["Colour"] = item_main['Color_first']
          data[name][row_main]["Appellation"] = item_main['Appellation_first']
          data[name][row_main]["Best after"] = item_main['BeginConsume_first']
          data[name][row_main]["Best before"] = item_main['EndConsume_first']
#          data[name][row_main]["Wine"] = item_main['Wine_first']
 
      
#      groups = ['Varietal', 'Country', 'Vintage', 'Producer', 'Type', 'Wine']


#      for group in groups:
#        group_data = df.groupby(group).agg({'iWine':'count','Valuation':['sum','mean']})
#        group_data.columns = group_data.columns.droplevel(0)
#        group_data["%"] = 1
#        group_data["%"] = (group_data['count']/group_data['count'].sum() ) * 100
#        group_data.columns = ["count", "value_total", "value_avg", "%"]
#        data[group] = {}
#        for row, item in group_data.iterrows():
#          data[group][row] = item.to_dict()
#          data[group][row]["sub_type"] = row



      data["total_bottles"] = len(df)
      data["total_value"] = df['Valuation'].sum()
      data["average_value"] = df['Valuation'].mean()
      self._data = data

Then, I've changed this property in sensor.py

@property
    def name(self):
        """Return the name of the sensor."""
        if(self._sub_type):
            return "cellar_tracker." + self._sensor_type.lower()# + "." + self._slug.lower()
        else:
            return "cellar_tracker." + self._sensor_type.lower()

Then, add this to your dashboard:


type: vertical-stack
cards:
  - type: glance
    entities:
      - entity: sensor.cellar_tracker_total_bottles
  - type: custom:auto-entities
    filter:
      include:
        - attributes:
            Colour: Red
    card:
      type: custom:flex-table-card
      title: Rood
      clickable: true
      columns:
        - name: Name
          data: Wine Name
        - name: Vintage
          data: Vintage
        - name: Colour
          data: Colour
        - name: Count
          data: count
        - name: Value
          data: value_avg
          modify: >-
            if(parseFloat(x).toFixed(0) == 0) {""}
            else{parseFloat(x).toFixed(0)+"€"}
        - name: Best after
          data: Best after
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
        - name: Best before
          data: Best before
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
      sort_by:
        - Colour
        - Vintage-
  - type: custom:auto-entities
    filter:
      include:
        - attributes:
            Colour: White
    card:
      type: custom:flex-table-card
      title: Wit
      clickable: true
      columns:
        - name: Name
          data: Wine Name
        - name: Vintage
          data: Vintage
        - name: Colour
          data: Colour
        - name: Count
          data: count
        - name: Value
          data: value_avg
          modify: >-
            if(parseFloat(x).toFixed(0) == 0) {""}
            else{parseFloat(x).toFixed(0)+"€"}
        - name: Best after
          data: Best after
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
        - name: Best before
          data: Best before
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
      sort_by:
        - Colour
        - Vintage-
  - type: custom:auto-entities
    filter:
      include:
        - attributes:
            Colour: Rosé
    card:
      type: custom:flex-table-card
      title: Rosé
      clickable: true
      columns:
        - name: Name
          data: Wine Name
        - name: Vintage
          data: Vintage
        - name: Colour
          data: Colour
        - name: Count
          data: count
        - name: Value
          data: value_avg
          modify: >-
            if(parseFloat(x).toFixed(0) == 0) {""}
            else{parseFloat(x).toFixed(0)+"€"}
        - name: Best after
          data: Best after
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
        - name: Best before
          data: Best before
          modify: if(x.length == 0){""} else{parseFloat(x).toFixed(0)}
      sort_by:
        - Colour
        - Vintage-

To get a list of all your wines, sorted by Red, White, Rosé, with attributes like drink date, vintage, value in the list.

image

@soggypete
Copy link

soggypete commented May 17, 2023

@pmaere Thank you for the code. Getting in each bottle looks great and I've managed to alter my code to do the same.

However, I would also like to get groups of countries/colours in, as it's interesting to see at a glance the percentage of wines from france vs portugal for example.

Furthermore, when I remove a wine from cellar tracker it doesn't seem to remove the sensor. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants