From 606ed0d56d1cec2fc7dafba1c78d8226173af486 Mon Sep 17 00:00:00 2001 From: David Stone Date: Fri, 1 Nov 2024 15:15:56 -0700 Subject: [PATCH] feat: Expose new rate structure property (#81) * Expose new rate structure property * Add tests --- custom_components/openei/const.py | 5 +++++ custom_components/openei/manifest.json | 2 +- requirements_tests.txt | 4 ++-- tests/conftest.py | 1 + tests/test_init.py | 6 +++--- tests/test_sensors.py | 5 +++++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/custom_components/openei/const.py b/custom_components/openei/const.py index 38c1bf2..9c67f69 100644 --- a/custom_components/openei/const.py +++ b/custom_components/openei/const.py @@ -68,6 +68,11 @@ name="Plan Name", icon="mdi:tag", ), + "current_rate_structure": SensorEntityDescription( + key="current_rate_structure", + name="Current Rate Structure", + icon="mdi:tag", + ), "all_rates": SensorEntityDescription( key="all_rates", name="All Listed Rates", diff --git a/custom_components/openei/manifest.json b/custom_components/openei/manifest.json index 32a1508..4a52ffe 100644 --- a/custom_components/openei/manifest.json +++ b/custom_components/openei/manifest.json @@ -7,6 +7,6 @@ "documentation": "https://github.com/firstof9/ha-openei", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/firstof9/ha-openei/issues", - "requirements": ["python-openei==0.1.23"], + "requirements": ["python-openei==0.1.24"], "version": "0.1.6" } diff --git a/requirements_tests.txt b/requirements_tests.txt index 2e5b9d2..bb5f188 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -1,5 +1,5 @@ -r requirements_dev.txt -python-openei==0.1.22 +python-openei==0.1.24 pytest pytest-cov pytest-homeassistant-custom-component @@ -9,4 +9,4 @@ flake8 mypy pydocstyle isort -pylint \ No newline at end of file +pylint diff --git a/tests/conftest.py b/tests/conftest.py index ccfc803..a98d45a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -50,6 +50,7 @@ def mock_api(): '"Fake Utility Co": [{"name": "Fake Plan Name", "label": "randomstring"}]' ) mock_api.return_value.all_rates = [0.24477, 0.007] + mock_api.return_value.current_rate_structure = 4 yield mock_api diff --git a/tests/test_init.py b/tests/test_init.py index f071202..e4e20c3 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -28,7 +28,7 @@ async def test_setup_entry(hass, mock_sensors, mock_api): await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 @@ -46,14 +46,14 @@ async def test_unload_entry(hass, mock_sensors, mock_api): assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert await hass.config_entries.async_unload(entries[0].entry_id) await hass.async_block_till_done() - assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 6 + assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 7 assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 1 assert len(hass.states.async_entity_ids(DOMAIN)) == 0 diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 81f70f6..aa7841a 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -9,6 +9,7 @@ FAKE_MINCHARGE_SENSOR = "sensor.fake_utility_co_minimum_charge" FAKE_CURRENT_RATE_SENSOR = "sensor.fake_utility_co_current_energy_rate" +FAKE_CURRENT_RATE_STRUCTURE_SENSOR = "sensor.fake_utility_co_current_rate_structure" pytestmark = pytest.mark.asyncio @@ -34,3 +35,7 @@ async def test_sensors(hass, mock_sensors, mock_api): assert state is not None assert state.state == "0.24477" assert state.attributes["all_rates"] == [0.24477, 0.007] + + state = hass.states.get(FAKE_CURRENT_RATE_STRUCTURE_SENSOR) + assert state is not None + assert state.state == "4"