Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/renault/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ async def async_press(self) -> None:
name="Start charge",
requires_electricity=True,
),
RenaultButtonEntityDescription(
async_press=lambda x: x.vehicle.set_charge_stop(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested this feature?

Feedback on the renault-api library has been inconsistent, and the function doesn't appear to work on all vehicles (does it actually work on yours?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service worked on my Dacia Spring. I will test the button today.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested it and worked with my car.

Dacia spring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great can you please adjust tests accordingly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we split the renault and dacia integration? For example dacia spring don't allow schedule charge?

Is possible to have a base integration that is common to both and then specific for each brand?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same library so I think it's better to have a single integration.
Even some Renault vehicles don't support schedule charge...
It is better to adjust documentation for this

key="stop_charge",
icon="mdi:ev-station",
name="Stop charge",
requires_electricity=True,
),
)
5 changes: 5 additions & 0 deletions homeassistant/components/renault/renault_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ async def set_charge_start(self) -> models.KamereonVehicleChargingStartActionDat
"""Start vehicle charge."""
return await self._vehicle.set_charge_start()

@with_error_wrapping
async def set_charge_stop(self) -> models.KamereonVehicleChargingStartActionData:
"""Stop vehicle charge."""
return await self._vehicle.set_charge_stop()

@with_error_wrapping
async def set_ac_stop(self) -> models.KamereonVehicleHvacStartActionData:
"""Stop vehicle ac."""
Expand Down
18 changes: 18 additions & 0 deletions tests/components/renault/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_charge",
},
{
ATTR_ENTITY_ID: "button.reg_number_stop_charge",
ATTR_ICON: "mdi:ev-station",
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_stop_charge",
},
],
Platform.DEVICE_TRACKER: [],
Platform.SELECT: [
Expand Down Expand Up @@ -336,6 +342,12 @@
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_charge",
},
{
ATTR_ENTITY_ID: "button.reg_number_stop_charge",
ATTR_ICON: "mdi:ev-station",
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777999_stop_charge",
},
],
Platform.DEVICE_TRACKER: [
{
Expand Down Expand Up @@ -565,6 +577,12 @@
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_start_charge",
},
{
ATTR_ENTITY_ID: "button.reg_number_stop_charge",
ATTR_ICON: "mdi:ev-station",
ATTR_STATE: STATE_UNKNOWN,
ATTR_UNIQUE_ID: "vf1aaaaa555777123_stop_charge",
},
],
Platform.DEVICE_TRACKER: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"data": {
"type": "ChargingStart",
"id": "guid",
"attributes": { "action": "stop" }
}
}
28 changes: 28 additions & 0 deletions tests/components/renault/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ async def test_button_start_charge(
assert mock_action.mock_calls[0][1] == ()


@pytest.mark.usefixtures("fixtures_with_data")
@pytest.mark.parametrize("vehicle_type", ["zoe_40"], indirect=True)
async def test_button_stop_charge(
hass: HomeAssistant, config_entry: ConfigEntry
) -> None:
"""Test that button invokes renault_api with correct data."""
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()

data = {
ATTR_ENTITY_ID: "button.reg_number_stop_charge",
}

with patch(
"renault_api.renault_vehicle.RenaultVehicle.set_charge_stop",
return_value=(
schemas.KamereonVehicleChargingStartActionDataSchema.loads(
load_fixture("renault/action.set_charge_stop.json")
)
),
) as mock_action:
await hass.services.async_call(
BUTTON_DOMAIN, SERVICE_PRESS, service_data=data, blocking=True
)
assert len(mock_action.mock_calls) == 1
assert mock_action.mock_calls[0][1] == ()


@pytest.mark.usefixtures("fixtures_with_data")
@pytest.mark.parametrize("vehicle_type", ["zoe_40"], indirect=True)
async def test_button_start_air_conditioner(
Expand Down