-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added ability to apply weightings to rates from external source…
…s for use with target rate and rolling target rate sensors (4 hours 30 minutes dev time)
- Loading branch information
1 parent
8b94c7d
commit 9350c3f
Showing
22 changed files
with
667 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Setup dependencies | ||
description: Sets up required dependencies | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Install dependencies | ||
run: sudo apt install libffi-dev libncurses5-dev zlib1g zlib1g-dev libssl-dev libreadline-dev libbz2-dev libsqlite3-dev | ||
shell: bash | ||
- name: asdf_install | ||
uses: asdf-vm/actions/install@v3 | ||
- name: Install Python modules | ||
run: | | ||
pip install -r requirements.test.txt | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
custom_components/octopus_energy/storage/rate_weightings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import logging | ||
from homeassistant.helpers import storage | ||
|
||
from pydantic import BaseModel | ||
|
||
from ..utils.weightings import RateWeighting | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
class RateWeightings(BaseModel): | ||
weightings: list[RateWeighting] | ||
|
||
async def async_load_cached_rate_weightings(hass, mpan: str) -> list[RateWeighting]: | ||
store = storage.Store(hass, "1", f"octopus_energy.{mpan}_rate_weightings") | ||
|
||
try: | ||
data = await store.async_load() | ||
if data is not None: | ||
_LOGGER.debug(f"Loaded cached rate weightings for {mpan}") | ||
return RateWeightings.parse_obj(data).weightings | ||
except: | ||
return None | ||
|
||
async def async_save_cached_rate_weightings(hass, mpan: str, weightings: list[RateWeighting]): | ||
if weightings is not None: | ||
store = storage.Store(hass, "1", f"octopus_energy.{mpan}_rate_weightings") | ||
await store.async_save(RateWeightings(weightings=weightings).dict()) | ||
_LOGGER.debug(f"Saved rate weightings data for {mpan}") |
Oops, something went wrong.