diff --git a/python_chargepoint/client.py b/python_chargepoint/client.py index 76a43c4..a805e6e 100644 --- a/python_chargepoint/client.py +++ b/python_chargepoint/client.py @@ -399,6 +399,31 @@ def set_amperage_limit(self, charger_id: int, amperage_limit: int, max_retry: in raise ChargePointCommunicationException( response=response, message="New amperage limit did not persist to charger after retries" ) + + @_require_login + def restart_home_charger(self, charger_id: int) -> None: + _LOGGER.debug("Sending restart command for panda: %s", charger_id) + restart = { + "user_id": self.user_id, + "restart_panda": {"device_id": charger_id, "mfhs": {}}, + } + response = self._session.post( + f"{self._global_config.endpoints.webservices}mobileapi/v5", json=restart + ) + + if response.status_code != codes.ok: + _LOGGER.error( + "Failed to restart charger! status_code=%s err=%s", + response.status_code, + response.text, + ) + raise ChargePointCommunicationException( + response=response, message="Failed to restart charger." + ) + + status = response.json() + _LOGGER.debug(status) + return @_require_login def get_charging_session(self, session_id: int) -> ChargingSession: diff --git a/tests/test_client.py b/tests/test_client.py index 5417717..9b58cf9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -393,6 +393,31 @@ def test_client_get_get_user_charging_status_failure(authenticated_client: Charg assert exc.value.response.status_code == 500 +@responses.activate +def test_client_restart_home_charger(authenticated_client: ChargePoint, home_charger_json: dict): + responses.add( + responses.POST, + f"{authenticated_client.global_config.endpoints.webservices}mobileapi/v5", + status=200, + json={"restart_panda": {}}, + ) + + status = authenticated_client.restart_home_charger(1234567890) + + assert status is None + +@responses.activate +def test_client_restart_home_charger_failure(authenticated_client: ChargePoint, home_charger_json: dict): + responses.add( + responses.POST, + f"{authenticated_client.global_config.endpoints.webservices}mobileapi/v5", + status=500, + ) + + with pytest.raises(ChargePointCommunicationException) as exc: + authenticated_client.restart_home_charger(1234567890) + + assert exc.value.response.status_code == 500 @responses.activate def test_start_session(