Skip to content

Commit

Permalink
feat: Expose new rate structure property (#81)
Browse files Browse the repository at this point in the history
* Expose new rate structure property

* Add tests
  • Loading branch information
stabbylambda authored Nov 1, 2024
1 parent a48ca2b commit 606ed0d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions custom_components/openei/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openei/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 2 additions & 2 deletions requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,4 +9,4 @@ flake8
mypy
pydocstyle
isort
pylint
pylint
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions tests/test_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"

0 comments on commit 606ed0d

Please sign in to comment.