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

Run precommit on sources #37

Merged
merged 2 commits into from
Jun 3, 2024
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 .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ Currently supported features:
- Enable/Disable charging from the grid
- Set charge target (in Wh)

CLI examples:

## CLI examples:

```bash
myenergi libbi show
Expand Down
8 changes: 4 additions & 4 deletions pymyenergi/base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def fetch_history_data(
"ivi1": 0,
"bdp1": 0,
"bcp1": 0,
"pvp1": 0
"pvp1": 0,
}
if resolution == MINUTE:
url = f"/cgi-jday-{self.prefix}{self._serialno}-{date_from.year}-{date_from.month}-{date_from.day}-{date_from.hour}-0-{how_long}"
Expand Down Expand Up @@ -169,11 +169,11 @@ async def fetch_history_data(
"grid_export": round(energy_wh["exp"] / 1000, 2),
"battery_charge": round(energy_wh["bcp1"] / 1000, 2),
"battery_discharge": round(energy_wh["bdp1"] / 1000, 2),
"inverter_export": round(energy_wh["ive1"] /1000, 2),
"inverter_import": round(energy_wh["ivi1"] /1000, 2),
"inverter_export": round(energy_wh["ive1"] / 1000, 2),
"inverter_import": round(energy_wh["ivi1"] / 1000, 2),
"device_boosted": device_boosted,
"device_green": device_green,
"device_total": device_boosted + device_green
"device_total": device_boosted + device_green,
}
if resolution == MINUTE:
return_data["pv_total"] = round(energy_wh["pvp1"] / 1000, 2)
Expand Down
10 changes: 6 additions & 4 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 All @@ -28,11 +28,13 @@
async def main(args):
username = args.username or input("Please enter your hub serial number: ")
password = args.password or getpass(prompt="Password (apikey): ")
app_email = args.app_email or input("App email (enter to skip; only needed for libbi): ")
app_email = args.app_email or input(
"App email (enter to skip; only needed for libbi): "
)
if app_email:
app_password = args.app_password or getpass(prompt="App password: ")
else:
app_password = ''
app_password = ""
conn = Connection(username, password, app_password, app_email)
if app_email and app_password:
await conn.discoverLocations()
Expand Down
19 changes: 13 additions & 6 deletions 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 Expand Up @@ -83,7 +83,9 @@ def _calculate_history_totals(self):
if zappi_or_eddi_or_libbi is not None:
for key in energy_keys:
if self._history_totals[key] == 0:
self._history_totals[key] = zappi_or_eddi_or_libbi.history_data.get(key, 0)
self._history_totals[key] = zappi_or_eddi_or_libbi.history_data.get(
key, 0
)
self._history_totals["green"] = self._history_totals.get(
"green", 0
) + zappi_or_eddi_or_libbi.history_data.get("device_green", 0)
Expand Down Expand Up @@ -133,7 +135,10 @@ def _calculate_totals(self):
self._totals[VOLTAGE_GRID] = zappi_or_eddi_or_libbi.supply_voltage
if self._totals.get(CT_GRID, 0) == 0 and zappi_or_eddi_or_libbi is not None:
self._totals[CT_GRID] = zappi_or_eddi_or_libbi.power_grid
if self._totals.get(CT_GENERATION, 0) == 0 and zappi_or_eddi_or_libbi is not None:
if (
self._totals.get(CT_GENERATION, 0) == 0
and zappi_or_eddi_or_libbi is not None
):
self._totals[CT_GENERATION] = zappi_or_eddi_or_libbi.power_generated

def get_power_totals(self):
Expand Down Expand Up @@ -214,8 +219,8 @@ async def refresh(self):
for grp in self._data:
keys = list(grp.keys())
key = keys[0]
if(len(keys) > 1 and keys[1] == 'fwv'):
self._firmware_version = grp['fwv']
if len(keys) > 1 and keys[1] == "fwv":
self._firmware_version = grp["fwv"]
if key not in DEVICE_TYPES:
if key == "fwv":
self._firmware_version = grp[key]
Expand All @@ -225,7 +230,9 @@ async def refresh(self):
devices = grp[key]
for device_data in devices:
serial = device_data.get("sno")
self._update_available = device_data.get('newBootloaderAvailable', False)
self._update_available = device_data.get(
"newBootloaderAvailable", False
)
existing_device = self.devices.get(serial, None)
if existing_device is None:
existing_device = device_factory(
Expand Down
19 changes: 12 additions & 7 deletions pymyenergi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@
from typing import Text

import httpx

from pycognito import Cognito

from .exceptions import MyenergiException
from .exceptions import TimeoutException
from .exceptions import WrongCredentials

_LOGGER = logging.getLogger(__name__)
_USER_POOL_ID = 'eu-west-2_E57cCJB20'
_CLIENT_ID = '2fup0dhufn5vurmprjkj599041'
_USER_POOL_ID = "eu-west-2_E57cCJB20"
_CLIENT_ID = "2fup0dhufn5vurmprjkj599041"


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

def __init__(
self, username: Text = None, password: Text = None, app_password: Text = None, app_email: Text = None, timeout: int = 20
self,
username: Text = None,
password: Text = None,
app_password: Text = None,
app_email: Text = None,
timeout: int = 20,
) -> None:
"""Initialize connection object."""
self.timeout = timeout
Expand All @@ -41,7 +46,7 @@ def __init__(
self.oauth.authenticate(password=self.app_password)
self.oauth_headers = {"Authorization": f"Bearer {self.oauth.access_token}"}
self.do_query_asn = True
self.invitation_id = ''
self.invitation_id = ""
_LOGGER.debug("New connection created")

def _checkMyenergiServerURL(self, responseHeader):
Expand Down Expand Up @@ -79,8 +84,8 @@ async def send(self, method, url, json=None, oauth=False):
) as httpclient:
theUrl = self.oauth_base_url + url
# if we have an invitiation id, we need to add that to the query
if (self.invitation_id != ""):
if ("?" in theUrl):
if self.invitation_id != "":
if "?" in theUrl:
theUrl = theUrl + "&invitationId=" + self.invitation_id
else:
theUrl = theUrl + "?invitationId=" + self.invitation_id
Expand Down
2 changes: 1 addition & 1 deletion pymyenergi/eddi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def ct_keys(self):

@property
def hsk(self):
""" Heatsink temperature """
"""Heatsink temperature"""
val = self._data.get("hsk", None)
if val is not None:
val = val / 10
Expand Down
1 change: 1 addition & 0 deletions pymyenergi/zappi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"auto" : 2,
}


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

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
author="Johan Isaksson",
author_email="johan@generatorhallen.se",
description="Python library and CLI for communicating with myenergi API.",
long_description=open("README.md", 'r').read(),
long_description_content_type='text/markdown',
long_description=open("README.md", "r").read(),
long_description_content_type="text/markdown",
package_data={"pymyenergi": ["VERSION"]},
include_package_data=True,
url="https://github.com/cjne/pymyenergi",
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"
}
}
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -69,4 +69,4 @@ async def test_get_libbi_devices(client_fetch_data_fixture):
client = MyenergiClient(conn)
devices = await client.get_devices("libbi")
assert len(devices) == 1
assert isinstance(devices[0], Libbi)
assert isinstance(devices[0], Libbi)
Loading