Add OpenEVSE station status binary sensor (#187076)

This commit is contained in:
Chris
2026-10-18 10:05:53 +02:00
committed by GitHub
parent 1b740dcd4b
commit d4bca35972
5 changed files with 88 additions and 0 deletions
@@ -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,
),
)
@@ -9,6 +9,9 @@
},
"shaper_active": {
"default": "mdi:tune-variant"
},
"station_status": {
"default": "mdi:ev-station"
}
},
"select": {
@@ -68,6 +68,9 @@
"shaper_active": {
"name": "Shaper active"
},
"station_status": {
"name": "Station status"
},
"using_ethernet": {
"name": "Ethernet connected"
},
@@ -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': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'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': <ANY>,
'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({
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'openevse_mock_config Station status',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.openevse_mock_config_station_status',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_entities[binary_sensor.openevse_mock_config_vehicle_connected-entry]
EntityRegistryEntrySnapshot({
'aliases': list([
@@ -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