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

Update status codes and #28

Merged
merged 3 commits into from
Oct 28, 2020
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
25 changes: 18 additions & 7 deletions pyeasee/charger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

_LOGGER = logging.getLogger(__name__)


STATUS = {
1: "STANDBY",
2: "PAUSED",
0: "OFFLINE",
1: "DISCONNECTED",
2: "AWAITING_START",
3: "CHARGING",
4: "READY_TO_CHARGE",
5: "UNKNOWN",
6: "CAR_CONNECTED",
4: "COMPLETED",
5: "ERROR",
6: "READY_TO_CHARGE",
}

NODE_TYPE = {1: "Master", 2: "Extender"}
Expand All @@ -24,10 +26,19 @@
# Work-in-progress, must be taken with a pinch of salt, as per now just reverse engineering of observations until API properly documented
None: "No reason",
0: "No reason, charging or ready to charge",
1: "Charger paused",
2: "Charger paused",
3: "Charger paused",
4: "Charger paused",
5: "Charger paused",
6: "Charger paused",
9: "Error no current",
50: "Secondary unit not requesting current or no car connected",
51: "Charger paused",
52: "Charger paused",
53: "Charger disabled",
54: "Waiting for schedule",
54: "Waiting for schedule/auth",
55: "Pending auth"
}


Expand All @@ -37,7 +48,7 @@ class ChargerState(BaseDict):
def __init__(self, state: Dict[str, Any]):
data = {
**state,
"chargerOpMode": STATUS[state["chargerOpMode"]],
"status": STATUS[state["chargerOpMode"]],
"reasonForNoCurrent": f"({state['reasonForNoCurrent']}) {REASON_FOR_NO_CURRENT.get(state['reasonForNoCurrent'], 'Unknown')}",
}
super().__init__(data)
Expand Down
7 changes: 5 additions & 2 deletions pyeasee/easee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
Main client for the Eesee account.
"""
import asyncio
import aiohttp
import logging
from datetime import datetime, timedelta
from typing import Any, List

import aiohttp

from .charger import Charger
from .exceptions import (AuthorizationFailedException, NotFoundException,
ServerFailureException, TooManyRequestsException)
from .site import Site, SiteState
from .exceptions import AuthorizationFailedException, NotFoundException, TooManyRequestsException, ServerFailureException

__VERSION__ = "0.7.25"

Expand Down
3 changes: 2 additions & 1 deletion tests/test_charger.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ async def test_get_correct_status():
mock_easee = MockEasee(get_data=default_state)
charger = Charger({"id": "EH123456", "name": "Easee Home 12345"}, mock_easee)
state = await charger.get_state()
assert state["chargerOpMode"] == "CHARGING"
assert state["chargerOpMode"] == 3
assert state["status"] == "CHARGING"


@pytest.mark.asyncio
Expand Down
18 changes: 10 additions & 8 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
import json
import pytest
import asyncio
import json
import os

import aiohttp
import pytest
from aioresponses import aioresponses

from pyeasee import Easee, Charger
from pyeasee import Charger, Easee

BASE_URL = "https://api.easee.cloud"

Expand Down Expand Up @@ -43,7 +43,8 @@ async def test_get_chargers(aiosession, aioresponse):
aioresponse.get(f"{BASE_URL}/api/chargers/EH12345/state", payload=chargers_state_data)

state = await chargers[0].get_state()
assert state["chargerOpMode"] == "PAUSED"
assert state["chargerOpMode"] == 2
assert state["status"] == "AWAITING_START"
await easee.close()
await aiosession.close()

Expand Down Expand Up @@ -94,10 +95,11 @@ async def test_get_site_state(aiosession, aioresponse):
assert charger_config["localNodeType"] == "Master"

charger_state = site_state.get_charger_state("EH123497")
assert charger_state["chargerOpMode"] == "STANDBY"
assert charger_state["chargerOpMode"] == 1
assert charger_state["status"] == "DISCONNECTED"

charger_state = site_state.get_charger_state("NOTEXIST")
assert charger_state == None
assert charger_state is None

await easee.close()
await aiosession.close()