Skip to content

Commit

Permalink
Add stop boost service
Browse files Browse the repository at this point in the history
Closes CJNE#172
  • Loading branch information
RobFerrer committed Nov 4, 2023
1 parent 9a34460 commit 2667827
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
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

0 comments on commit 2667827

Please sign in to comment.