Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop boost service #443

Merged
merged 1 commit into from
Dec 2, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ It will create HA devices depending on what you have installed:
- Minumum green level number input; how much power must be sourced from green sources (local generation) to do diversion charging
- Service to start boost (provide boost amount in kWh as parameter)
- Service to start smart boost (provide boost amount in kWh and desired finished time as paramters)
- Service to stop boost

- Eddi

Expand Down
6 changes: 6 additions & 0 deletions custom_components/myenergi/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ async def start_smart_boost(self, amount: float, when: str) -> None:
await self.device.start_smart_boost(amount, when)
self.schedule_update_ha_state()

async def stop_boost(self) -> None:
_LOGGER.debug("Stop boost called")
"""Stop boost"""
await self.device.stop_boost()
self.schedule_update_ha_state()


class MyenergiHub(CoordinatorEntity):
def __init__(self, coordinator, config_entry, meta):
Expand Down
5 changes: 5 additions & 0 deletions custom_components/myenergi/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
SMART_BOOST_SCHEMA,
"start_smart_boost",
)
platform.async_register_entity_service(
"myenergi_stop_boost",
{},
"stop_boost",
)
devices.append(ZappiChargeModeSelect(coordinator, device, entry))
elif device.kind == "eddi":
platform.async_register_entity_service(
Expand Down
8 changes: 8 additions & 0 deletions custom_components/myenergi/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ myenergi_smart_boost:
required: true
selector:
time:
myenergi_stop_boost:
name: Stop boost
description: Stop boost
target:
device:
model: Zappi
entity:
domain: select
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,10 @@ def mock_eddi_device():
"""Return a mocked eddi object."""
with patch("pymyenergi.client.Eddi.set_priority") as device:
yield device


@pytest.fixture
def mock_zappi_stop_boost():
"""Return a mocked Zappi object."""
with patch("pymyenergi.client.Zappi.stop_boost") as stop_boost:
yield stop_boost
20 changes: 20 additions & 0 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,23 @@ async def test_eddi_boost(
await hass.async_block_till_done()
assert mock_eddi_manual_boost.call_count == 1
mock_eddi_manual_boost.assert_called_with("Heater 1", 44.0)


async def test_stop_boost(
hass: HomeAssistant, mock_zappi_stop_boost: MagicMock
) -> None:
"""Verify device information includes expected details."""

await setup_mock_myenergi_config_entry(hass)

await hass.services.async_call(
"myenergi",
"myenergi_stop_boost",
{
ATTR_ENTITY_ID: TEST_ZAPPI_SELECT_CHARGE_MODE,
},
blocking=False,
)
assert mock_zappi_stop_boost.call_count == 0
await hass.async_block_till_done()
assert mock_zappi_stop_boost.call_count == 1