Skip to content
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
2 changes: 1 addition & 1 deletion openevsehttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async def _process_request_with_session(
try:
message = json.loads(message)
except ValueError:
_LOGGER.warning("Non JSON response: %s", message)
_LOGGER.debug("Non JSON response: %s", message)

if resp.status == 400:
if isinstance(message, dict) and "msg" in message:
Expand Down
8 changes: 6 additions & 2 deletions openevsehttp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ async def set_divert_mode(self, mode: str = "fast") -> None:
_LOGGER.error("Problem issuing command: %s", response)
raise UnknownError

self._status["divertmode"] = new_mode

async def set_shaper(self, enable: bool = True) -> None:
"""Set shaper mode."""
if not self._version_check("4.0.0"):
Expand All @@ -500,16 +502,18 @@ async def set_shaper(self, enable: bool = True) -> None:

url = f"{self.url}shaper"
mode = 1 if enable else 0
data = {"mode": mode}
data = {"shaper": mode}

_LOGGER.debug("Setting shaper to %s", mode)
response = await self.process_request(url=url, method="post", data=data)
response = await self.process_request(url=url, method="post", rapi=data)
response = self._normalize_response(response)
msg = response.get("msg") if isinstance(response, Mapping) else None
if msg not in ["OK", "done", "no change", "Current Shaper state changed"]:
_LOGGER.error("Problem issuing command: %s", response)
raise UnknownError

self._status["shaper"] = mode

async def toggle_shaper(self) -> None:
"""Toggle shaper mode."""
shaper_active = self._status.get("shaper")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

PROJECT_DIR = Path(__file__).parent.resolve()
README_FILE = PROJECT_DIR / "README.md"
VERSION = "0.3.2"
VERSION = "0.3.3"

setup(
name="python_openevse_http",
Expand Down
27 changes: 27 additions & 0 deletions tests/test_shaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ async def test_set_shaper_fail(test_charger, mock_aioclient, caplog):
await test_charger.set_shaper(True)


async def test_set_shaper_non_json(test_charger, mock_aioclient, caplog):
"""Test set_shaper with a non-JSON response."""
await test_charger.update()
test_charger._status["shaper"] = 0

mock_aioclient.post(
TEST_URL_SHAPER,
status=200,
body="Current Shaper state changed",
)
with caplog.at_level(logging.DEBUG):
await test_charger.set_shaper(True)
assert "Setting shaper to 1" in caplog.text
assert test_charger.shaper_active == 1

test_charger._status["shaper"] = 1
mock_aioclient.post(
TEST_URL_SHAPER,
status=200,
body="Current Shaper state changed",
)
with caplog.at_level(logging.DEBUG):
await test_charger.set_shaper(False)
assert "Setting shaper to 0" in caplog.text
assert test_charger.shaper_active == 0


async def test_toggle_shaper(test_charger, mock_aioclient, caplog):
"""Test toggle_shaper command."""
await test_charger.update()
Expand Down
Loading