From d4bca35972607d32bb223edc46d3343cc0257856 Mon Sep 17 00:00:00 2001 From: Chris <1105672+firstof9@users.noreply.github.com> Date: Sun, 18 Oct 2026 01:05:53 -0700 Subject: [PATCH] Add OpenEVSE station status binary sensor (#187076) --- .../components/openevse/binary_sensor.py | 5 ++ homeassistant/components/openevse/icons.json | 3 ++ .../components/openevse/strings.json | 3 ++ .../snapshots/test_binary_sensor.ambr | 50 +++++++++++++++++++ .../components/openevse/test_binary_sensor.py | 27 ++++++++++ 5 files changed, 88 insertions(+) diff --git a/homeassistant/components/openevse/binary_sensor.py b/homeassistant/components/openevse/binary_sensor.py index 9e3d6818bd3d..e430a4880249 100644 --- a/homeassistant/components/openevse/binary_sensor.py +++ b/homeassistant/components/openevse/binary_sensor.py @@ -66,6 +66,11 @@ BINARY_SENSOR_TYPES: tuple[OpenEVSEBinarySensorDescription, ...] = ( entity_registry_enabled_default=False, value_fn=lambda ev: ev.mqtt_connected, ), + OpenEVSEBinarySensorDescription( + key="station_status", + translation_key="station_status", + value_fn=lambda ev: ev.status == "active" if ev.status is not None else None, + ), ) diff --git a/homeassistant/components/openevse/icons.json b/homeassistant/components/openevse/icons.json index 13ce512f6d3c..877fb2892a3b 100644 --- a/homeassistant/components/openevse/icons.json +++ b/homeassistant/components/openevse/icons.json @@ -9,6 +9,9 @@ }, "shaper_active": { "default": "mdi:tune-variant" + }, + "station_status": { + "default": "mdi:ev-station" } }, "select": { diff --git a/homeassistant/components/openevse/strings.json b/homeassistant/components/openevse/strings.json index e9f4d3914e82..97dc4b266028 100644 --- a/homeassistant/components/openevse/strings.json +++ b/homeassistant/components/openevse/strings.json @@ -68,6 +68,9 @@ "shaper_active": { "name": "Shaper active" }, + "station_status": { + "name": "Station status" + }, "using_ethernet": { "name": "Ethernet connected" }, diff --git a/tests/components/openevse/snapshots/test_binary_sensor.ambr b/tests/components/openevse/snapshots/test_binary_sensor.ambr index e1cb25730648..d4e1c792d73e 100644 --- a/tests/components/openevse/snapshots/test_binary_sensor.ambr +++ b/tests/components/openevse/snapshots/test_binary_sensor.ambr @@ -250,6 +250,56 @@ 'state': 'off', }) # --- +# name: test_entities[binary_sensor.openevse_mock_config_station_status-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.openevse_mock_config_station_status', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Station status', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Station status', + 'platform': 'openevse', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'station_status', + 'unique_id': 'deadbeeffeed-station_status', + 'unit_of_measurement': None, + }) +# --- +# name: test_entities[binary_sensor.openevse_mock_config_station_status-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'openevse_mock_config Station status', + }), + 'context': , + 'entity_id': 'binary_sensor.openevse_mock_config_station_status', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'off', + }) +# --- # name: test_entities[binary_sensor.openevse_mock_config_vehicle_connected-entry] EntityRegistryEntrySnapshot({ 'aliases': list([ diff --git a/tests/components/openevse/test_binary_sensor.py b/tests/components/openevse/test_binary_sensor.py index 941e0b0e38fd..cba78709e616 100644 --- a/tests/components/openevse/test_binary_sensor.py +++ b/tests/components/openevse/test_binary_sensor.py @@ -117,3 +117,30 @@ async def test_binary_sensor_unavailable_on_coordinator_timeout( state = hass.states.get("binary_sensor.openevse_mock_config_vehicle_connected") assert state assert state.state == STATE_UNAVAILABLE + + +@pytest.mark.parametrize( + ("raw_status", "expected_state"), + [ + pytest.param("active", "on", id="active"), + pytest.param("disabled", "off", id="disabled"), + pytest.param(None, STATE_UNKNOWN, id="none"), + ], +) +async def test_station_status_binary_sensor( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_charger: MagicMock, + raw_status: str | None, + expected_state: str, +) -> None: + """Test station status binary sensor states.""" + mock_charger.status = raw_status + + with patch("homeassistant.components.openevse.PLATFORMS", [Platform.BINARY_SENSOR]): + mock_config_entry.add_to_hass(hass) + await hass.config_entries.async_setup(mock_config_entry.entry_id) + + state = hass.states.get("binary_sensor.openevse_mock_config_station_status") + assert state is not None + assert state.state == expected_state