From 6c87dd9a430a66a9be98efdb5a38d91f33181d8b Mon Sep 17 00:00:00 2001 From: JosyBan Date: Thu, 7 Mar 2024 13:47:13 +0000 Subject: [PATCH 1/3] Changes to add an unlock call fixes CJNE/ha-myenergi#493 --- .gitignore | 2 ++ README.md | 1 + custom_components/myenergi/entity.py | 6 ++++++ custom_components/myenergi/select.py | 5 +++++ custom_components/myenergi/services.yaml | 8 ++++++++ tests/conftest.py | 7 +++++++ tests/test_services.py | 20 ++++++++++++++++++++ 7 files changed, 49 insertions(+) diff --git a/.gitignore b/.gitignore index f52dff2..7d0ca17 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ pythonenv* venv .venv .direnv +.vscode/settings.json +.devcontainer/configuration.yaml diff --git a/README.md b/README.md index 037a410..42847e6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/custom_components/myenergi/entity.py b/custom_components/myenergi/entity.py index c85e9e8..62dbd34 100644 --- a/custom_components/myenergi/entity.py +++ b/custom_components/myenergi/entity.py @@ -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): diff --git a/custom_components/myenergi/select.py b/custom_components/myenergi/select.py index 5264955..f6c2065 100644 --- a/custom_components/myenergi/select.py +++ b/custom_components/myenergi/select.py @@ -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( diff --git a/custom_components/myenergi/services.yaml b/custom_components/myenergi/services.yaml index cbe63d4..0287e40 100644 --- a/custom_components/myenergi/services.yaml +++ b/custom_components/myenergi/services.yaml @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 20f4d5f..e49740a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 diff --git a/tests/test_services.py b/tests/test_services.py index d9b64c1..0d6671f 100644 --- a/tests/test_services.py +++ b/tests/test_services.py @@ -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 \ No newline at end of file From 5bec04d4c222a9c754eb7442ebda9bf0cff629c2 Mon Sep 17 00:00:00 2001 From: JosyBan Date: Thu, 7 Mar 2024 14:01:05 +0000 Subject: [PATCH 2/3] Removed .gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7d0ca17..0ffedc7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,4 @@ pythonenv* venv .venv .direnv -.vscode/settings.json -.devcontainer/configuration.yaml + From 1329c9b08ff5361ca9de0876d6dc18669052ef9d Mon Sep 17 00:00:00 2001 From: JosyBan Date: Thu, 7 Mar 2024 17:08:36 +0000 Subject: [PATCH 3/3] undoing change to gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0ffedc7..f52dff2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,3 @@ pythonenv* venv .venv .direnv -