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

493 unlock #494

Merged
merged 3 commits into from
Mar 11, 2024
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 @@ -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
Loading