Skip to content

Commit

Permalink
Small updates on python package (#37)
Browse files Browse the repository at this point in the history
* Move json load to request function

* Change async timeout

* Small project change
  • Loading branch information
klaasnicolaas authored Dec 15, 2021
1 parent f2a8c99 commit 4195b96
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
3 changes: 0 additions & 3 deletions pure_energie/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Models for Pure Energie Meter."""
from __future__ import annotations

import json
from dataclasses import dataclass
from typing import Any

Expand All @@ -24,7 +23,6 @@ def from_dict(data: dict[str, Any]) -> SmartMeter:
Returns:
A SmartMeter object.
"""
data = json.loads(data)
data = data["elec"]

def convert(value):
Expand Down Expand Up @@ -65,7 +63,6 @@ def from_dict(data: dict[str, Any]) -> Device:
Returns:
A Device object.
"""
data = json.loads(data)

return Device(
pem_id=data.get("id"),
Expand Down
9 changes: 6 additions & 3 deletions pure_energie/pure_energie.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
from __future__ import annotations

import asyncio
import json
from dataclasses import dataclass
from typing import Any, Mapping

import async_timeout
from aiohttp.client import ClientError, ClientResponseError, ClientSession
from async_timeout import timeout
from yarl import URL

from .exceptions import PureEnergieMeterConnectionError
Expand All @@ -28,7 +29,7 @@ def __init__(
session: Optional, shared, aiohttp client session.
"""
self._session = session
self._close_session = False
self._close_session: bool = False

self.host = host
self.request_timeout = request_timeout
Expand Down Expand Up @@ -64,7 +65,7 @@ async def request(
self._close_session = True

try:
with async_timeout.timeout(self.request_timeout):
async with timeout(self.request_timeout):
response = await self._session.request(
"GET",
url,
Expand All @@ -90,6 +91,7 @@ async def device(self) -> Device:
A Device data object from the Pure Energie device API.
"""
data = await self.request("info")
data = json.loads(data)
return Device.from_dict(data)

async def smartmeter(self) -> SmartMeter:
Expand All @@ -99,6 +101,7 @@ async def smartmeter(self) -> SmartMeter:
A SmartMeter data object from the Pure Energie device API.
"""
data = await self.request("meter/now")
data = json.loads(data)
return SmartMeter.from_dict(data)

async def close(self) -> None:
Expand Down
Empty file added pure_energie/py.typed
Empty file.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pure_energie"
version = "0.0.0"
description = "Asynchronous Python client for the Pure Energy devices"
description = "Asynchronous Python client for the Pure Energie Meter devices"
authors = ["Klaas Schoute <[email protected]>"]
maintainers = ["Klaas Schoute <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -63,7 +63,7 @@ bandit = "^1.7.1"
Changelog = "https://github.com/klaasnicolaas/python-pem/releases"

[tool.black]
target-version = ['py37']
target-version = ['py38']

[tool.coverage.paths]
source = ["pure_energie"]
Expand Down Expand Up @@ -120,5 +120,5 @@ paths = ["pure_energie"]
verbose = true

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["setuptools", "poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 4195b96

Please sign in to comment.