Add stop charge button to renault integration (#88003)

* Added service to start/stop charge

* Remove comment

* Fixed service

* removed service for start/stop charge

* Remove version

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Format

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Revert change

* Fix lint

* Add tests

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
rodriguestiago0 2023-02-28 09:28:44 +00:00 committed by GitHub
parent d397217b5b
commit bef5fde832
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 0 deletions

View File

@ -71,4 +71,11 @@ BUTTON_TYPES: tuple[RenaultButtonEntityDescription, ...] = (
name="Start charge",
requires_electricity=True,
),
RenaultButtonEntityDescription(
async_press=lambda x: x.vehicle.set_charge_stop(),
key="stop_charge",
icon="mdi:ev-station",
name="Stop charge",
requires_electricity=True,
),
)

View File

@ -151,6 +151,11 @@ class RenaultVehicleProxy:
"""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."""

View File

@ -114,6 +114,12 @@ MOCK_VEHICLES = {
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: [
@ -336,6 +342,12 @@ MOCK_VEHICLES = {
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: [
{
@ -565,6 +577,12 @@ MOCK_VEHICLES = {
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: [
{

View File

@ -0,0 +1,7 @@
{
"data": {
"type": "ChargingStart",
"id": "guid",
"attributes": { "action": "stop" }
}
}

View File

@ -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(