barleybobs / homeassistant-ecowater-softener

A Homeassistant custom component to integrate Ecowater water softeners
https://github.com/barleybobs/homeassistant-ecowater-softener
MIT License
33 stars 10 forks source link

Wrong date format d/m/Y instead of m/d/Y #42

Closed shivan closed 1 year ago

shivan commented 1 year ago

Hi,

I get the following error, seems it uses the wrong date format. Can this be configured anywhere?

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/ecowater_softener/coordinator.py", line 64, in _async_update_data
    data[OUT_OF_SALT_ON] = datetime.strptime(data_json['out_of_salt'], '%d/%m/%Y').strftime('%Y-%m-%d')
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/_strptime.py", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '01/13/2024' does not match format '%d/%m/%Y'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/ecowater_softener/coordinator.py", line 83, in _async_update_data
    raise UpdateFailed(f"Error communicating with API: {e}")
homeassistant.helpers.update_coordinator.UpdateFailed: Error communicating with API: time data '01/13/2024' does not match format '%d/%m/%Y'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/entity_platform.py", line 362, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/ecowater_softener/sensor.py", line 107, in async_setup_entry
    await coordinator.async_config_entry_first_refresh()
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 258, in async_config_entry_first_refresh
    raise ex
homeassistant.exceptions.ConfigEntryNotReady: Error communicating with API: time data '01/13/2024' does not match format '%d/%m/%Y'
shivan commented 1 year ago

Sorry, my fault. This can be configured at the initialization of the plugin. Works now.