Skip to content

Commit

Permalink
Add demand rate lookups (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Aug 26, 2021
1 parent b442c56 commit 37e8e47
Show file tree
Hide file tree
Showing 5 changed files with 1,398 additions and 1 deletion.
27 changes: 27 additions & 0 deletions openeihttp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ def current_rate(self) -> float:

return rate

@property
def current_demand_rate(self) -> float:
"""Return the current rate."""
assert self._data is not None
weekend = False
now = datetime.datetime.today()
month = now.month - 1
hour = now.hour
if now.weekday() > 4:
weekend = True
table = "demandweekdayschedule"
if weekend:
table = "demandweekendschedule"

lookup_table = self._data[table]
rate_structure = lookup_table[month][hour]

rate = self._data["demandratestructure"][rate_structure][0]["rate"]

return rate

@property
def demand_unit(self) -> str:
"""Return the demand rate unit."""
assert self._data is not None
return self._data["demandrateunit"]

@property
def rate_name(self) -> str:
"""Return the rate name."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "0.1.3"
VERSION = "0.1.4"


setup(
Expand Down
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def mock_plandata(requests_mock):
)


@pytest.fixture(name="demand_plandata_mock")
def mock_demand_plandata(requests_mock):
"""Mock the status reply."""
requests_mock.get(
"https://api.openei.org/utility_rates?version=latest&format=json&api_key=fakeAPIKey&lat=1&lon=1&sector=Residential&detail=full&getpage=574613aa5457a3557e906f5b",
text=load_fixture("plan_demand_data.json"),
)


@pytest.fixture(name="lookup_mock_404")
def mock_lookup_404(requests_mock):
"""Mock the status reply."""
Expand Down
Loading

0 comments on commit 37e8e47

Please sign in to comment.