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

Add new libbi status codes #40

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions pymyenergi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from pymyenergi.eddi import BOOST_TARGETS
from pymyenergi.eddi import EDDI_MODES
from pymyenergi.exceptions import WrongCredentials
from pymyenergi.zappi import CHARGE_MODES
from pymyenergi.libbi import LIBBI_MODES
from pymyenergi.zappi import CHARGE_MODES

from . import EDDI
from . import HARVI
from . import ZAPPI
from . import LIBBI
from . import ZAPPI

logging.basicConfig()
logging.root.setLevel(logging.WARNING)
Expand Down
2 changes: 1 addition & 1 deletion pymyenergi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from . import EDDI
from . import FREQUENCY_GRID
from . import HARVI
from . import LIBBI
from . import HOUR
from . import LIBBI
from . import VOLTAGE_GRID
from . import ZAPPI
from .eddi import Eddi
Expand Down
13 changes: 7 additions & 6 deletions pymyenergi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Text

import httpx

from pycognito import Cognito

from .exceptions import MyenergiException
Expand All @@ -19,6 +18,7 @@
_USER_POOL_ID = 'eu-west-2_E57cCJB20'
_CLIENT_ID = '2fup0dhufn5vurmprjkj599041'


class Connection:
"""Connection to myenergi API."""

Expand All @@ -36,7 +36,7 @@ def __init__(
self.app_email = app_email
self.auth = httpx.DigestAuth(self.username, self.password)
self.headers = {"User-Agent": "Wget/1.14 (linux-gnu)"}
if self.app_email and app_password:
if self.app_email and self.app_password:
self.oauth = Cognito(_USER_POOL_ID, _CLIENT_ID, username=self.app_email)
self.oauth.authenticate(password=self.app_password)
self.oauth_headers = {"Authorization": f"Bearer {self.oauth.access_token}"}
Expand All @@ -57,10 +57,11 @@ def _checkMyenergiServerURL(self, responseHeader):
raise WrongCredentials()

async def discoverLocations(self):
locs = await self.get("/api/Location", oauth=True)
# check if guest location - use the first location by default
if locs["content"][0]["isGuestLocation"] == True:
self.invitation_id = locs["content"][0]["invitationData"]["invitationId"]
if self.app_email and self.app_password:
locs = await self.get("/api/Location", oauth=True)
# check if guest location - use the first location by default
if locs["content"][0]["isGuestLocation"] == True:
self.invitation_id = locs["content"][0]["invitationData"]["invitationId"]

def checkAndUpdateToken(self):
# check if we have oauth credentials
Expand Down
10 changes: 2 additions & 8 deletions pymyenergi/libbi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import logging

from pymyenergi.connection import Connection

from . import LIBBI
from .base_device import BaseDevice

_LOGGER = logging.getLogger(__name__)

STATES = {
0: "Off",
1: "On",
Expand All @@ -27,9 +23,11 @@
151: "FW Upgrade (ARM)",
156: "FW Upgrade (DSP)",
172: "BMS Charge Temperature Low",
176: "BMS Updating",
234: "Calibration Charge",
251: "FW Upgrade (DSP)",
252: "FW Upgrade (ARM)",
253: "BMS Upgrading"
}

LIBBI_MODES = ["Stopped", "Normal", "Export"]
Expand Down Expand Up @@ -83,10 +81,6 @@ def local_mode(self):
"""Get current known status"""
return self._data.get("lmo", 1)

@property
def prefix(self):
return "E"

@property
def ct_keys(self):
"""Return CT key names that are not none"""
Expand Down
1 change: 1 addition & 0 deletions pymyenergi/zappi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}
SINGLE_PHASE = "SINGLE_PHASE"


class Zappi(BaseDevice):
"""Zappi Client for myenergi API."""

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/libbi.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"fwv": "3702S5.041",
"newAppAvailable": "False",
"newBootloaderAvailable": "False"
}
}
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from pymyenergi.client import MyenergiClient
from pymyenergi.eddi import Eddi
from pymyenergi.harvi import Harvi
from pymyenergi.zappi import Zappi
from pymyenergi.libbi import Libbi
from pymyenergi.zappi import Zappi

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down
Loading