Skip to content

Commit

Permalink
Merge pull request #494 from JosyBan/493-unlock
Browse files Browse the repository at this point in the history
493 unlock
  • Loading branch information
CJNE authored Mar 11, 2024
2 parents 9260fa2 + 1329c9b commit 6b705dc
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 @@ -46,6 +46,7 @@ It will create HA devices depending on what you have installed:
- 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
- Service to unlock the Zappi

- 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 @@ -70,6 +70,12 @@ async def stop_boost(self) -> None:
await self.device.stop_boost()
self.schedule_update_ha_state()

async def unlock(self) -> None:
_LOGGER.debug("unlock called")
"""Unlock"""
await self.device.unlock()
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 @@ -60,6 +60,11 @@ async def async_setup_entry(hass, entry, async_add_devices):
{},
"stop_boost",
)
platform.async_register_entity_service(
"myenergi_unlock",
{},
"unlock",
)
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 @@ -71,3 +71,11 @@ myenergi_stop_boost:
model: Zappi
entity:
domain: select
myenergi_unlock:
name: Unlock
description: Unlock
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 @@ -145,3 +145,10 @@ def mock_zappi_stop_boost():
"""Return a mocked Zappi object."""
with patch("pymyenergi.client.Zappi.stop_boost") as stop_boost:
yield stop_boost


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


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

await setup_mock_myenergi_config_entry(hass)

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

0 comments on commit 6b705dc

Please sign in to comment.