Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix consumption update for live sensor of second zaehlpunkt #233

Closed
wants to merge 0 commits into from

Conversation

tschoerk
Copy link
Collaborator

@tschoerk tschoerk commented May 21, 2024

When updating the consumption data for the second zaehlerpunkt, the base meter readings don't have the information for this zaehlerpunkt, since it's not the "default" zaehlerpunkt. So the live sensor tries to get the information by checking the consumption data for yesterday to update the sensor with this value. This second method has several bugs though, which this pull request aims to fix.

This should resolve #227

Copy link

codecov bot commented Aug 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.06%. Comparing base (02015a3) to head (5f6e847).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   81.25%   85.06%   +3.81%     
==========================================
  Files           5        5              
  Lines         288      288              
==========================================
+ Hits          234      245      +11     
+ Misses         54       43      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tschoerk tschoerk marked this pull request as ready for review August 6, 2024 07:53
@tschoerk
Copy link
Collaborator Author

tschoerk commented Aug 6, 2024

Both live sensors receive the meter readings the same way now by calling the historical data API with the value type METER_READ which returns the meter reading for each day. The latest value is then used to update the live sensor. This can be done with one or more zaehlpunkte and all return the same value type now, which is the total usage/feeding since implementation of the zaehlpunkt. This fixes the problems with the live sensor on a second zaehlpunkt as well as makes the output uniform.

custom_components/wnsm/base_sensor.py Outdated Show resolved Hide resolved
custom_components/wnsm/live_sensor.py Outdated Show resolved Hide resolved
Copy link
Owner

@DarwinsBuddy DarwinsBuddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rebase onto master?
This project follows the pattern of a linear history. 🙃

)
return
self._available = True
self._updatets = datetime.now().strftime("%d.%m.%Y %H:%M:%S")
except TimeoutError as e:
self._available = False
_LOGGER.warning("Error retrieving data from smart meter api - Timeout: %s" % e)
_LOGGER.warning(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these line breaks coming from your setup, or is this a too strict reformatting config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which line breaks do you mean? I tried to kept the formatting mostly as it was before, let me know if I missed something. So in this case the multiline warning was kept in the same style as before.

)
if yesterdays_sum > 0:
self._state = yesterdays_sum
else:
_LOGGER.error("Unable to load consumption")
_LOGGER.error(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these line breaks coming from your setup, or is this a too strict reformatting config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@@ -301,7 +343,7 @@ def test_verbrauch_raw(requests_mock: Mocker):
customer_id = "123456789"
valid_verbrauch_raw_response = verbrauch_raw_response()
expect_login(requests_mock)
expect_history(requests_mock, enabled(zaehlpunkt())['zaehlpunktnummer'])
expect_history(requests_mock, customer_id, enabled(zaehlpunkt())['zaehlpunktnummer'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these line breaks coming from your setup, or is this a too strict reformatting config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which line breaks do you mean here? I have some auto formatting in my setup, but it's fairly limited.

@DarwinsBuddy
Copy link
Owner

@tschoerk I fear you've created another merge commit instead of rebasing the branch onto master. 😬

@tschoerk
Copy link
Collaborator Author

tschoerk commented Oct 4, 2024

@tschoerk I fear you've created another merge commit instead of rebasing the branch onto master. 😬

Sorry not too experienced with git. What to do, to fix this?

@DarwinsBuddy
Copy link
Owner

DarwinsBuddy commented Oct 4, 2024

  1. git checkout DarwinsBuddy main
  2. git pull
  3. git checkout tschoerk bugfix/loadConsumption
  4. git rebase --onto main
  5. resolve all conflicts one commit at a time by
    5.1. resolving
    5.2. git rebase --continue
    5.3. repeat 5.1. until all conflicts are resolved
  6. git push --force-with-lease

!Be careful! Do point 6 after you've successfully confirmed, that this branch is working as you'd expect it, otherwise throw away the branch, check it out anew and rebase again.

This should resolve all conflicts and remove all merge commits that you've introduced

@s00500
Copy link

s00500 commented Oct 6, 2024

Just tested this PR and it seems to work! I was bothered by this issue forever now... 😅

@tschoerk
Copy link
Collaborator Author

tschoerk commented Oct 7, 2024

Sorry, I probably did something wrong here. I rebased following your instructions and now all my commits in my branch are gone and it's just like main, because I am stupid and did not check properly.
I will create a new branch with the changes, just so it's kept for future reference. Let me know how to best proceed. Sorry for the inconvenience.

@tschoerk tschoerk deleted the bugfix/loadConsumption branch October 7, 2024 08:16
@tschoerk tschoerk restored the bugfix/loadConsumption branch October 7, 2024 08:16
@DarwinsBuddy
Copy link
Owner

@tschoerk no worries. when I did my first rebase I also messed it up. :) So that's part of the journey

Maybe something that helps
https://saraford.net/2017/04/21/how-to-visualize-a-rebase-in-the-git-visualization-tool-111/

Just file a new PR with the changes applied. :)

@s00500
Copy link

s00500 commented Oct 7, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple contracts causes issue with live sensor
3 participants