Tmbao / amberelectric-usages

MIT License
5 stars 1 forks source link

Invalid statistic_id #4

Closed lwhgeorge closed 6 months ago

lwhgeorge commented 6 months ago

Hi @Tmbao, I'm getting this 'Invalid statistic_id' error after adding it to integration. I was able to seelct NMI and see it got initialised for a sec, then failed.

Is there any step I have missed?

2024-02-19 09:47:03.288 DEBUG (MainThread) [custom_components.amberelectric_usages] Fetched new Amber data: [{'duration': 30.0, 'spot_per_kwh': 7.44951, 'per_kwh': 14.8836, 'date': datetime.date(2024, 1, 22), 'nem_time': datetime.datetime(2024, 1, 22, 0, 30, tzinfo=tzoffset(None, 36000)), .......
2024-02-19 09:47:03.409 DEBUG (MainThread) [custom_components.amberelectric_usages] Updating amberelectric_usages:HomeAddress_usages_e1
2024-02-19 09:47:03.435 ERROR (MainThread) [custom_components.amberelectric_usages] Unexpected error fetching amberelectric_usages data: Invalid statistic_id
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 313, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/amberelectric_usages/coordinator.py", line 82, in _async_update_data
    await self._insert_usage_statistic(usages_by_hour_by_channel)
  File "/config/custom_components/amberelectric_usages/coordinator.py", line 132, in _insert_usage_statistic
    async_add_external_statistics(self._hass, metadata, statistics)
  File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 2239, in async_add_external_statistics
    raise HomeAssistantError("Invalid statistic_id")
homeassistant.exceptions.HomeAssistantError: Invalid statistic_id
2024-02-19 09:47:03.446 DEBUG (MainThread) [custom_components.amberelectric_usages] Finished fetching amberelectric_usages data in 4.235 seconds (success: False)

Version: HACS Integration version: 1.34.0

Core: 2024.2.2 Supervisor: 2024.01.1 Operating System: 11.5 Frontend: 20240207.1

Tmbao commented 6 months ago

Hi @lwhgeorge can you try again with your Home name in lower cases

https://github.com/home-assistant/core/blob/85864e77acbb1772223927a4614311a9a9c92598/homeassistant/core.py#L183

I think the core regex matcher doesn't let you put upper case characters into the object name. I'll update the implementation to make sure that your home name is in lower cases in upcoming releases

lwhgeorge commented 6 months ago

yes, the lower case worked, thanks very much!