Skip to content

Commit

Permalink
feat: add max_current sensor (#385)
Browse files Browse the repository at this point in the history
* feat: add `max_current` sensor

* formatting

* formatting again
  • Loading branch information
firstof9 authored Oct 11, 2024
1 parent ae4d7cb commit 11b1732
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
10 changes: 9 additions & 1 deletion custom_components/openevse/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@
device_class=SensorDeviceClass.ENERGY,
entity_registry_enabled_default=False,
),
"max_current": SensorEntityDescription(
key="max_current",
name="Max Current",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
),
}

SWITCH_TYPES: Final[dict[str, OpenEVSESwitchEntityDescription]] = {
Expand Down Expand Up @@ -388,7 +396,7 @@
# entity_category=EntityCategory.CONFIG,
# ),
"max_current_soft": OpenEVSESelectEntityDescription(
name="Max Current",
name="Charge Rate",
key="current_capacity",
default_options=None,
command="set_current",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openevse/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/firstof9/openevse/issues",
"loggers": ["openevsehttp"],
"requirements": ["python-openevse-http==0.1.61"],
"requirements": ["python-openevse-http==0.1.62"],
"version": "0.0.0-dev",
"zeroconf": ["_openevse._tcp.local."]
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-openevse-http==0.1.61
python-openevse-http==0.1.62
5 changes: 3 additions & 2 deletions tests/fixtures/status.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"evse_connected": 1,
"amp": 32.2,
"voltage": 240,
"pilot": 48,
"pilot": 40,
"wh": 64582,
"temp": 503,
"temp1": false,
Expand Down Expand Up @@ -49,5 +49,6 @@
"shaper_cur": 21,
"vehicle_soc": 75,
"vehicle_range": 468,
"vehicle_eta": 18000
"vehicle_eta": 18000,
"max_current": 48
}
14 changes: 7 additions & 7 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def test_setup_entry(hass, test_charger, mock_ws_start):
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 20
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand All @@ -51,7 +51,7 @@ async def test_setup_entry_bad_serial(hass, test_charger_bad_serial, mock_ws_sta
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 20
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand All @@ -71,7 +71,7 @@ async def test_setup_and_unload_entry(hass, test_charger):
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 20
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand Down Expand Up @@ -102,7 +102,7 @@ async def test_setup_entry_state_change(hass, test_charger, mock_ws_start, caplo
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 22
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand Down Expand Up @@ -132,7 +132,7 @@ async def test_setup_entry_state_change_timeout(
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 22
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand Down Expand Up @@ -162,7 +162,7 @@ async def test_setup_entry_state_change_2(hass, test_charger, mock_ws_start, cap
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 22
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 23
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand Down Expand Up @@ -197,7 +197,7 @@ async def test_setup_entry_state_change_2_bad_post(
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 22
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 23
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def test_sensors(hass, test_charger, mock_ws_start):
await hass.async_block_till_done()

assert len(hass.states.async_entity_ids(BINARY_SENSOR_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 20
assert len(hass.states.async_entity_ids(SENSOR_DOMAIN)) == 21
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 4
assert len(hass.states.async_entity_ids(SELECT_DOMAIN)) == 2
entries = hass.config_entries.async_entries(DOMAIN)
Expand All @@ -48,3 +48,6 @@ async def test_sensors(hass, test_charger, mock_ws_start):
state = hass.states.get("sensor.openevse_total_usage")
assert state
assert state.state == "64.582"
state = hass.states.get("sensor.openevse_max_current")
assert state
assert state.state == "48"
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ python =
3.11: py311
3.12: py312, lint, mypy

[pytest]
asyncio_default_fixture_loop_scope=function

[testenv]
commands =
pytest --asyncio-mode=auto --timeout=30 --cov=custom_components/openevse --cov-report=xml {posargs}
Expand Down

0 comments on commit 11b1732

Please sign in to comment.