mirror of https://github.com/home-assistant/core
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:
parent
d397217b5b
commit
bef5fde832
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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: [
|
||||
{
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"data": {
|
||||
"type": "ChargingStart",
|
||||
"id": "guid",
|
||||
"attributes": { "action": "stop" }
|
||||
}
|
||||
}
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue