custom-components / grocy

Custom Grocy integration for Home Assistant
Apache License 2.0
156 stars 48 forks source link

item.day is already a date #172

Closed ludeeus closed 2 years ago

ludeeus commented 2 years ago

https://github.com/SebRut/pygrocy/blob/v1.0.0/pygrocy/data_models/meal_items.py#L103 https://github.com/SebRut/pygrocy/blob/v1.0.0/pygrocy/grocy_api_client.py#L36

Fixes #171

firstof9 commented 2 years ago

Thanks! I just started digging into this, you beat me to the punch. :beers:

firstof9 commented 2 years ago

Just tested this looks like another error has popped up.

2022-01-25 14:49:14 ERROR (MainThread) [custom_components.grocy] Update of Chores failed with 1 validation error for CurrentChoreResponse
next_estimated_execution_time
  none is not an allowed value (type=type_error.none.not_allowed)

2022-01-25 14:50:54 ERROR (MainThread) [custom_components.grocy] Update of Meal_plan failed with 1 validation error for MealPlanSectionResponse
sort_number
  value is not a valid integer (type=type_error.integer)

Not sure about the Chores one.

Figured it out the section number in Grocy has to be set.

firstof9 commented 2 years ago

The sensor doesn't populate here's the debug output:

2022-01-25 15:14:11 DEBUG (MainThread) [custom_components.grocy] Finished fetching grocy data in 111.195 seconds (success: True)
2022-01-25 15:14:11 DEBUG (MainThread) [custom_components.grocy.sensor] Data for sensor.grocy_meal_plan: [<custom_components.grocy.helpers.MealPlanItem object at 0x7ff83e182e20>, <custom_components.grocy.helpers.MealPlanItem object at 0x7ff8415abca0>, <custom_components.grocy.helpers.MealPlanItem object at 0x7ff84573f250>, <custom_components.grocy.helpers.MealPlanItem object at 0x7ff8411d8550>, <custom_components.grocy.helpers.MealPlanItem object at 0x7ff84a343dc0>]
2022-01-25 15:16:31 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 134, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 265, in _async_refresh
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in _async_write_ha_state
    self.device_state_attributes is not None
  File "/config/custom_components/grocy/entity.py", line 143, in device_state_attributes
    return json.loads(json.dumps(data, cls=GrocyJSONEncoder))
  File "/usr/local/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/local/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/config/custom_components/grocy/json_encode.py", line 26, in default
    return json.JSONEncoder.default(self, o)
  File "/usr/local/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type date is not JSON serializable
ludeeus commented 2 years ago

That's unrelated to this change, lastest beta release contains a similar fix, if you don't figure it out open an issue for it

ludeeus commented 2 years ago

https://github.com/custom-components/grocy/pull/175 will not fix your issue, but will help identifying it