Closed DarwinsBuddy closed 10 months ago
Attention: 8 lines
in your changes are missing coverage. Please review.
Comparison is base (
49c0cc2
) 29.60% compared to head (45064dc
) 29.33%.
Files | Patch % | Lines |
---|---|---|
custom_components/wnsm/statistics_sensor.py | 0.00% | 5 Missing :warning: |
custom_components/wnsm/base_sensor.py | 0.00% | 3 Missing :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
interesting! maybe that works, but I have to test that... The interesting thing is that we also import the state statistics, but maybe they are not overwritten if the state is zero? Eventually I know too little about the HA internals :D
interesting! maybe that works, but I have to test that... The interesting thing is that we also import the state statistics, but maybe they are not overwritten if the state is zero? Eventually I know too little about the HA internals :D
I can't answer that, but if the change does not break anything. (i.e. the statistics sensor keeps importing data successively), the warning would be gone and thus potential future issues :upside_down_face:
Nothing to complain about the code, I switched to that branch now and let it run for a few days. But I'll guess it's fine!
I get this error now:
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: homeassistant.helpers.entity Source: custom_components/wnsm/statistics_sensor.py:81 Integration: WienerNetzeSmartmeter (documentation, issues) First occurred: 01:57:11 (6 occurrences) Last logged: 06:57:11
Update for sensor.xx_statistics fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 554, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in async_device_update
await coro
File "/config/custom_components/wnsm/statistics_sensor.py", line 81, in async_update
_sum = Decimal(last_inserted_stat[self._id][0]["sum"])
TypeError: conversion from NoneType to Decimal is not supported
Not sure how the sum got None all of a sudden? Maybe the switch of the sensor type caused that? Looks like this fix is not backwards compatible with old measurements - or @DarwinsBuddy did that worked for you and my setup is just a bit weird?
@DarwinsBuddy I removed the intgration and deleted the statistics from the database to start from scratch. In that case, it works and the _statistics
sensor shows 0kWh.
Do you understand what's going on when there is already data and the sensor is switched? Otherwise the only chance would be to remove the statistics and start all over. With the import feature that would not be a great loss though.
I think removing and regenerating the history is definitely an option. though I am not sure how to achieve this after the upgrade. I know of that one service built in to hassio which is easy to call at least: purge entities.
but I'd have to research if we could call it from within our custom component. if not we can directly use the recorder I guess?
still what's left is too check somehow when it's been updated to the next version and do it only then.
I got the error again - this time on the freshly imported data. I guess setting the state to anything else than None is a bad idea :(
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 554, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in async_device_update
await coro
File "/config/custom_components/wnsm/statistics_sensor.py", line 81, in async_update
_sum = Decimal(last_inserted_stat[self._id][0]["sum"])
TypeError: conversion from NoneType to Decimal is not supported
My suspicion is, that the statistics module overwrites something when the state is set to zero and thus the last state set by the add statistics is overwritten...
After reading https://github.com/DarwinsBuddy/WienerNetzeSmartmeter/issues/119 I wondered what the difference in set up is for live vs. statistics sensor.
I remember, that @reox had troubles setting the state of the statistics entity of a smart meter to something not
None
. This presumably leads to the reported warning.In order to fix this I tried out setting the statistics sensor to
measurement
(since it's not quitetotal_increasing
) and set its value to0 kWh
, s.t. it has an entry in the entity registry of home assistant (which was not the case prior to that).The warning in the energy dashboard is gone.
@reox Can you potentially confirm that I didn't break anything else with this change?