diff --git a/openeihttp/__init__.py b/openeihttp/__init__.py index f2dc717..19bf626 100644 --- a/openeihttp/__init__.py +++ b/openeihttp/__init__.py @@ -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.""" diff --git a/setup.py b/setup.py index e3f9daa..3878a4d 100644 --- a/setup.py +++ b/setup.py @@ -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( diff --git a/tests/conftest.py b/tests/conftest.py index de4b140..3b44599 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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§or=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.""" diff --git a/tests/fixtures/plan_demand_data.json b/tests/fixtures/plan_demand_data.json new file mode 100644 index 0000000..376c475 --- /dev/null +++ b/tests/fixtures/plan_demand_data.json @@ -0,0 +1,1330 @@ +{ + "items": [ + { + "label": "5cacc9d15457a31d537780e2", + "uri": "https://openei.org/apps/IURDB/rate/view/5cacc9d15457a31d537780e2", + "sector": "Residential", + "energyweekendschedule": [ + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + ], + "demandratestructure": [ + [ + { + "rate": 0 + } + ], + [ + { + "rate": 8.4, + "adj": 0.838 + } + ], + [ + { + "rate": 8.4, + "adj": 0.838 + } + ] + ], + "supersedes": "5cacc9ae5457a3c6517780e2", + "demandrateunit": "kW", + "eiaid": 803, + "revisions": [ + 1554806129, + 1554806379 + ], + "energyratestructure": [ + [ + { + "rate": 0.07798, + "adj": 0.005741, + "unit": "kWh" + } + ], + [ + { + "rate": 0.11017, + "adj": 0.005741, + "unit": "kWh" + } + ], + [ + { + "rate": 0.1316, + "adj": 0.005741, + "unit": "kWh" + } + ] + ], + "startdate": 1554102000, + "energyweekdayschedule": [ + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ] + ], + "demandcomments": "Adjustments = Lost Fixed Cost Recovery Mechanism", + "fixedchargeunits": "$/month", + "utility": "Arizona Public Service Co", + "servicetype": "Bundled", + "description": "This rate schedule is available to all residential Customers, including Partial Requirements\r\nCustomers with an on-site distributed generation system.", + "name": "Residential Service (Saver Choice Plus) R-2", + "is_default": false, + "source": "https://www.aps.com/library/rates/SaverChoicePlus.pdf", + "demandweekendschedule": [ + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ] + ], + "energycomments": "Adjustments = Renewable Energy Adjustment charge + Transmission Cost adjustment + Environmental Improvement surcharge + Demand Side Management adjustment + Power Supply adjustment + Tax Expense Adjuster Mechanism", + "approved": true, + "demandweekdayschedule": [ + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 2, + 2, + 2, + 2, + 2, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ], + [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 1, + 0, + 0, + 0, + 0 + ] + ], + "dgrules": "Net Billing Instantaneous", + "country": "USA", + "fixedchargefirstmeter": 12.99, + "demandunits": "kW", + "sourceparent": "https://www.aps.com/en/residential/accountservices/serviceplans/Pages/saver-choice-max.aspx?src=RB" + } + ] +} \ No newline at end of file diff --git a/tests/test_init.py b/tests/test_init.py index 584b289..3d517fe 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -162,6 +162,37 @@ def test_get_rate_data_weekend(test_rates, plandata_mock): assert status == 0.06118 +@freeze_time("2021-08-14 13:20:00") +def test_get_rate_data_weekend_demand(test_rates, demand_plandata_mock): + """Test rate schedules.""" + test_rates.update() + status = test_rates.current_demand_rate + assert status == 0 + + +@freeze_time("2021-08-13 10:21:34") +def test_get_rate_data_demand(test_rates, demand_plandata_mock): + """Test rate schedules.""" + test_rates.update() + status = test_rates.current_demand_rate + assert status == 0 + + +@freeze_time("2021-08-13 17:20:00") +def test_get_rate_data_2_demand(test_rates, demand_plandata_mock): + """Test rate schedules.""" + test_rates.update() + status = test_rates.current_demand_rate + assert status == 8.4 + + +def test_get_demand_unit(test_rates, demand_plandata_mock): + """Test rate schedules.""" + test_rates.update() + status = test_rates.demand_unit + assert status == "kW" + + def test_get_distributed_generation(test_rates, plandata_mock): """Test rate schedules.""" test_rates.update()