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

feat: Expose new rate structure property #81

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

stabbylambda
Copy link
Contributor

I have a gnarly template in my home assistant config to reverse-calculate the rate name from the current cost, which is kind of a bummer because Jinja floats absolutely suck.

{% set rates = state_attr('sensor.san_diego_gas_electric_co_current_energy_rate', 'all_rates') | map('round', 3) | list %}
{% set current = states('sensor.san_diego_gas_electric_co_current_energy_rate') | round(3) %}
{% set i = rates.index(current) %}
{% set d = {
  0: "on peak",
  1: "off peak",
  2: "super off peak",
  3: "on peak",
  4: "off peak",
  5: "super off peak",
} %}

{{ d.get(i) }}

While I'm sure this template could be better (I'm no Jinja master), I can't see any way around the gross map('round', 3) call except to expose the index of the selected rate structure. SDG&E's EV-TOU-2 plan has both Summer and Winter periods for On, Off, and Super Off Peak periods.

This PR adds the current_rate_structure from firstof9/python-openei#182 to Home Assistant.

@stabbylambda stabbylambda marked this pull request as ready for review November 1, 2024 21:42
@firstof9
Copy link
Owner

firstof9 commented Nov 1, 2024

Can you add to the test_sensors.py to check the sensor output to make sure it's returning what you're expecting?

@stabbylambda
Copy link
Contributor Author

You want me to write tests?! Nonsense. It works on my machine, after all. 😄

@firstof9
Copy link
Owner

firstof9 commented Nov 1, 2024

Please rebase, I fixed the issue pytest found.

@firstof9 firstof9 added the enhancement New feature or request label Nov 1, 2024
Copy link

codecov bot commented Nov 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.69%. Comparing base (bd795e9) to head (e4a9646).
Report is 4 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
- Coverage   94.96%   94.69%   -0.27%     
==========================================
  Files           5        5              
  Lines         397      396       -1     
==========================================
- Hits          377      375       -2     
- Misses         20       21       +1     
Files with missing lines Coverage Δ
custom_components/openei/const.py 100.00% <ø> (ø)

@firstof9 firstof9 merged commit 606ed0d into firstof9:master Nov 1, 2024
7 checks passed
@stabbylambda stabbylambda deleted the rate-structure branch November 1, 2024 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants