Fixed having multiple contracts with multiple zps
When switching provider and contract holder a new contract number is given but the zaehlpunkt stays the same. The old one is set to inactive, but is still in the system, if the contracted is not fully deleted. This leads to a situation where the same zaehlpunkt is listed twice under different contracts, once active, once inactive. Currently the updates don't fully check for inactive zaehlpunkte, if the same zaehlpunkt is listed twice. This fix checks all contracts and if the zaehlpunkt is active before adding it, so it gets the correct customer id for retrieving all the data.
I had to revert this PR as I spotted some potential flaws afterwards. @tschoerk maybe you could look over them one more time?
Codecov Report
Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
Project coverage is 81.25%. Comparing base (
02015a3) to head (d2edc27).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| custom_components/wnsm/api/client.py | 50.00% | 2 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #262 +/- ##
=======================================
Coverage 81.25% 81.25%
=======================================
Files 5 5
Lines 288 288
=======================================
Hits 234 234
Misses 54 54
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Sorry for late answer had to have a closer look at it. The problem was that each zaehlpunkt is only checked once each update and for each check it calls /zaehlpunkte to see if the zaehlpunktnumber is still active. That's why it has to be checked in all loops, in client and base_sensor to make sure the active one is returned. I agree that this is not elegant, but since the stored zaehlpunkt is checked every update, it needs to make sure to return the correct one. I agree though, since it has so many changes for such an edge case, I think it's fine to close.