Skip to content

Commit

Permalink
Merge branch 'dependabot/pip/flake8-simplify-0.17.1' of https://githu…
Browse files Browse the repository at this point in the history
…b.com/klaasnicolaas/python-pem into dependabot/pip/flake8-simplify-0.17.1
  • Loading branch information
klaasnicolaas committed Feb 18, 2022
2 parents 3eda844 + 4af6469 commit 7da891b
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
language: system
types: [python]
entry: poetry run bandit
files: ^net2grid/
files: ^gridnet/
require_serial: true
- id: black
name: ☕️ Format using black
Expand Down
54 changes: 29 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ A python package with which you can read the data from a [NET2GRID][net2grid] de
## Installation

```bash
pip install net2grid
pip install gridnet
```

## Usage

```py
import asyncio

from net2grid import Net2Grid
from gridnet import GridNet

async def main():
"""Show example on getting data from your NET2GRID device."""
async with Net2Grid(
"""Show example on getting data from your device."""
async with GridNet(
host="example.com",
) as client:
device = await client.device()
Expand Down Expand Up @@ -121,6 +121,10 @@ To run just the Python tests:
poetry run pytest
```

## Trademark Legal Notices

All product names, trademarks and registered trademarks in this repository, are property of their respective owners, and are used by the author for identification purposes only. The use of these names, trademarks and brands, do not imply endorsement or affiliation.

## License

MIT License
Expand Down Expand Up @@ -152,27 +156,27 @@ SOFTWARE.
[pre-commit]: https://pre-commit.com

<!-- MARKDOWN LINKS & IMAGES -->
[build-shield]: https://github.com/klaasnicolaas/python-net2grid/actions/workflows/tests.yaml/badge.svg
[build-url]: https://github.com/klaasnicolaas/python-net2grid/actions/workflows/tests.yaml
[code-quality-shield]: https://img.shields.io/lgtm/grade/python/g/klaasnicolaas/python-net2grid.svg?logo=lgtm&logoWidth=18
[code-quality]: https://lgtm.com/projects/g/klaasnicolaas/python-net2grid/context:python
[commits-shield]: https://img.shields.io/github/commit-activity/y/klaasnicolaas/python-net2grid.svg
[commits-url]: https://github.com/klaasnicolaas/python-net2grid/commits/main
[codecov-shield]: https://codecov.io/gh/klaasnicolaas/python-net2grid/branch/main/graph/badge.svg?token=CXCSJBsRPE
[codecov-url]: https://codecov.io/gh/klaasnicolaas/python-net2grid
[forks-shield]: https://img.shields.io/github/forks/klaasnicolaas/python-net2grid.svg
[forks-url]: https://github.com/klaasnicolaas/python-net2grid/network/members
[issues-shield]: https://img.shields.io/github/issues/klaasnicolaas/python-net2grid.svg
[issues-url]: https://github.com/klaasnicolaas/python-net2grid/issues
[license-shield]: https://img.shields.io/github/license/klaasnicolaas/python-net2grid.svg
[last-commit-shield]: https://img.shields.io/github/last-commit/klaasnicolaas/python-net2grid.svg
[build-shield]: https://github.com/klaasnicolaas/python-gridnet/actions/workflows/tests.yaml/badge.svg
[build-url]: https://github.com/klaasnicolaas/python-gridnet/actions/workflows/tests.yaml
[code-quality-shield]: https://img.shields.io/lgtm/grade/python/g/klaasnicolaas/python-gridnet.svg?logo=lgtm&logoWidth=18
[code-quality]: https://lgtm.com/projects/g/klaasnicolaas/python-gridnet/context:python
[commits-shield]: https://img.shields.io/github/commit-activity/y/klaasnicolaas/python-gridnet.svg
[commits-url]: https://github.com/klaasnicolaas/python-gridnet/commits/main
[codecov-shield]: https://codecov.io/gh/klaasnicolaas/python-gridnet/branch/main/graph/badge.svg?token=CXCSJBsRPE
[codecov-url]: https://codecov.io/gh/klaasnicolaas/python-gridnet
[forks-shield]: https://img.shields.io/github/forks/klaasnicolaas/python-gridnet.svg
[forks-url]: https://github.com/klaasnicolaas/python-gridnet/network/members
[issues-shield]: https://img.shields.io/github/issues/klaasnicolaas/python-gridnet.svg
[issues-url]: https://github.com/klaasnicolaas/python-gridnet/issues
[license-shield]: https://img.shields.io/github/license/klaasnicolaas/python-gridnet.svg
[last-commit-shield]: https://img.shields.io/github/last-commit/klaasnicolaas/python-gridnet.svg
[maintenance-shield]: https://img.shields.io/maintenance/yes/2022.svg
[maintainability-shield]: https://api.codeclimate.com/v1/badges/0b3297077cbc525a837e/maintainability
[maintainability-url]: https://codeclimate.com/github/klaasnicolaas/python-net2grid/maintainability
[maintainability-url]: https://codeclimate.com/github/klaasnicolaas/python-gridnet/maintainability
[project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg
[pypi]: https://pypi.org/project/net2grid/
[python-versions-shield]: https://img.shields.io/pypi/pyversions/net2grid
[releases-shield]: https://img.shields.io/github/release/klaasnicolaas/python-net2grid.svg
[releases]: https://github.com/klaasnicolaas/python-net2grid/releases
[stars-shield]: https://img.shields.io/github/stars/klaasnicolaas/python-net2grid.svg
[stars-url]: https://github.com/klaasnicolaas/python-net2grid/stargazers
[pypi]: https://pypi.org/project/gridnet/
[python-versions-shield]: https://img.shields.io/pypi/pyversions/gridnet
[releases-shield]: https://img.shields.io/github/release/klaasnicolaas/python-gridnet.svg
[releases]: https://github.com/klaasnicolaas/python-gridnet/releases
[stars-shield]: https://img.shields.io/github/stars/klaasnicolaas/python-gridnet.svg
[stars-url]: https://github.com/klaasnicolaas/python-gridnet/stargazers
13 changes: 13 additions & 0 deletions gridnet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Asynchronous Python client for a NED2GRID device."""

from .exceptions import GridNetConnectionError, GridNetError
from .gridnet import GridNet
from .models import Device, SmartBridge

__all__ = [
"Device",
"GridNet",
"GridNetError",
"GridNetConnectionError",
"SmartBridge",
]
9 changes: 9 additions & 0 deletions gridnet/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Exceptions for GridNet."""


class GridNetError(Exception):
"""Generic GridNet exception."""


class GridNetConnectionError(GridNetError):
"""GridNet connection exception."""
34 changes: 17 additions & 17 deletions net2grid/net2grid.py → gridnet/gridnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from aiohttp.hdrs import METH_GET
from yarl import URL

from .exceptions import Net2GridConnectionError
from .exceptions import GridNetConnectionError
from .models import Device, SmartBridge


@dataclass
class Net2Grid:
"""Main class for handling connections with the NET2GRID devices."""
class GridNet:
"""Main class for handling connections with the devices."""

host: str
request_timeout: int = 10
Expand All @@ -34,26 +34,26 @@ async def request(
method: str = METH_GET,
data: dict | None = None,
) -> dict[str, Any]:
"""Handle a request to a NET2GRID device.
"""Handle a request to the device.
Args:
uri: Request URI, without '/', for example, 'status'
method: HTTP Method to use.
data: Dictionary of data to send to the NET2GRID API.
data: Dictionary of data to send to the API.
Returns:
A Python dictionary (text) with the response from
a NET2GRID device.
a device.
Raises:
Net2GridConnectionError: An error occurred while
communicating with the NET2GRID device.
GridNetConnectionError: An error occurred while
communicating with the device.
"""
version = metadata.version(__package__)
url = URL.build(scheme="http", host=self.host, path="/").join(URL(uri))

headers = {
"User-Agent": f"PythonNet2Grid/{version}",
"User-Agent": f"PythonGridNet/{version}",
"Accept": "application/json, text/plain, */*",
}

Expand All @@ -71,22 +71,22 @@ async def request(
)
response.raise_for_status()
except asyncio.TimeoutError as exception:
raise Net2GridConnectionError(
"Timeout occurred while connecting to the NET2GRID device"
raise GridNetConnectionError(
"Timeout occurred while connecting to the device"
) from exception
except (
ClientError,
ClientResponseError,
socket.gaierror,
) as exception:
raise Net2GridConnectionError(
"Error occurred while communicating with the NET2GRID device"
raise GridNetConnectionError(
"Error occurred while communicating with the device"
) from exception

return await response.text()

async def device(self) -> Device:
"""Get the latest values from a NET2GRID device.
"""Get the latest values from a the device.
Returns:
A Device data object from the API.
Expand All @@ -96,7 +96,7 @@ async def device(self) -> Device:
return Device.from_dict(data)

async def smartbridge(self) -> SmartBridge:
"""Get the latest values from a NET2GRID device.
"""Get the latest values from a the device.
Returns:
A SmartBridge data object from the API.
Expand All @@ -110,11 +110,11 @@ async def close(self) -> None:
if self.session and self._close_session:
await self.session.close()

async def __aenter__(self) -> Net2Grid:
async def __aenter__(self) -> GridNet:
"""Async enter.
Returns:
The NET2GRID object.
The GridNet object.
"""
return self

Expand Down
14 changes: 7 additions & 7 deletions net2grid/models.py → gridnet/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Models for NET2GRID."""
"""Models for GridNet."""
from __future__ import annotations

from dataclasses import dataclass
Expand All @@ -7,18 +7,18 @@

@dataclass
class SmartBridge:
"""Object representing an SmartBridge response from a NET2GRID device."""
"""Object representing an SmartBridge response from the device."""

power_flow: int
energy_consumption_total: float
energy_production_total: float

@staticmethod
def from_dict(data: dict[str, Any]) -> SmartBridge:
"""Return SmartBridge object from the NET2GRID API response.
"""Return SmartBridge object from the API response.
Args:
data: The data from the NET2GRID API.
data: Response data from the API.
Returns:
A SmartBridge object.
Expand Down Expand Up @@ -46,7 +46,7 @@ def convert(value):

@dataclass
class Device:
"""Object representing an Device response from NET2GRID device."""
"""Object representing an Device response from the device."""

n2g_id: str
model: str
Expand All @@ -57,10 +57,10 @@ class Device:

@staticmethod
def from_dict(data: dict[str, Any]) -> Device:
"""Return Device object from the NET2GRID API response.
"""Return Device object from the API response.
Args:
data: The data from the NET2GRID API.
data: Response data from the API.
Returns:
A Device object.
Expand Down
File renamed without changes.
13 changes: 0 additions & 13 deletions net2grid/__init__.py

This file was deleted.

9 changes: 0 additions & 9 deletions net2grid/exceptions.py

This file was deleted.

22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[tool.poetry]
name = "net2grid"
name = "gridnet"
version = "0.0.0"
description = "Asynchronous Python client for the NET2GRID devices"
description = "Asynchronous Python client for a NET2GRID devices"
authors = ["Klaas Schoute <[email protected]>"]
maintainers = ["Klaas Schoute <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/klaasnicolaas/python-net2grid"
repository = "https://github.com/klaasnicolaas/python-net2grid"
documentation = "https://github.com/klaasnicolaas/python-net2grid"
homepage = "https://github.com/klaasnicolaas/python-gridnet"
repository = "https://github.com/klaasnicolaas/python-gridnet"
documentation = "https://github.com/klaasnicolaas/python-gridnet"
keywords = ["net2grid", "energy", "device", "power", "async", "client"]
classifiers = [
"Framework :: AsyncIO",
Expand All @@ -21,7 +21,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
packages = [
{ include = "net2grid" },
{ include = "gridnet" },
]

[tool.poetry.dependencies]
Expand Down Expand Up @@ -59,22 +59,22 @@ codespell = "^2.1.0"
bandit = "^1.7.2"

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/klaasnicolaas/python-net2grid/issues"
Changelog = "https://github.com/klaasnicolaas/python-net2grid/releases"
"Bug Tracker" = "https://github.com/klaasnicolaas/python-gridnet/issues"
Changelog = "https://github.com/klaasnicolaas/python-gridnet/releases"

[tool.black]
target-version = ['py39']

[tool.coverage.paths]
source = ["net2grid"]
source = ["gridnet"]

[tool.coverage.report]
show_missing = true
exclude_lines = ["pragma: no cover", "if TYPE_CHECKING:"]

[tool.coverage.run]
branch = true
source = ["net2grid"]
source = ["gridnet"]

[tool.isort]
profile = "black"
Expand Down Expand Up @@ -116,7 +116,7 @@ addopts = "--cov"

[tool.vulture]
min_confidence = 80
paths = ["net2grid"]
paths = ["gridnet"]
verbose = true

[build-system]
Expand Down
12 changes: 6 additions & 6 deletions test_output.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# pylint: disable=W0621
"""Asynchronous Python client for the NET2GRID API."""
"""Asynchronous Python client for a NET2GRID device."""

import asyncio

from net2grid import Device, Net2Grid, SmartBridge
from gridnet import Device, GridNet, SmartBridge


async def main():
"""Test."""
async with Net2Grid(
async with GridNet(
host="example.com",
) as net2grid:
smartbridge: SmartBridge = await net2grid.smartbridge()
device: Device = await net2grid.device()
) as gridnet:
smartbridge: SmartBridge = await gridnet.smartbridge()
device: Device = await gridnet.device()
print(smartbridge)
print()
print(f"Power flow: {smartbridge.power_flow}")
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Asynchronous Python client for the NET2GRID device."""
"""Asynchronous Python client for NET2GRID devices."""
import os


Expand Down
Loading

0 comments on commit 7da891b

Please sign in to comment.