From 34ff74c9a2ed06602d07de77498ee1fd6e9dce9d Mon Sep 17 00:00:00 2001 From: Klaas Schoute Date: Sun, 23 Jan 2022 01:49:59 +0100 Subject: [PATCH] Renname model to SmartBridge (#63) --- README.md | 6 +++--- net2grid/__init__.py | 4 ++-- net2grid/models.py | 12 ++++++------ net2grid/net2grid.py | 8 ++++---- test_output.py | 12 ++++++------ .../{smartmeter.json => smartbridge.json} | 0 tests/test_models.py | 18 +++++++++--------- tests/test_net2grid.py | 4 ++-- 8 files changed, 32 insertions(+), 32 deletions(-) rename tests/fixtures/{smartmeter.json => smartbridge.json} (100%) diff --git a/README.md b/README.md index f26da5e..2e4b7e5 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ async def main(): host="example.com", ) as client: device = await client.device() - smartmeter = await client.smartmeter() + smartbridge = await client.smartbridge() print(device) - print(smartmeter) + print(smartbridge) if __name__ == "__main__": loop = asyncio.get_event_loop() @@ -69,7 +69,7 @@ You can read the following data with this package, the `power flow` entity can a - Hardware version - Manufacturer -### SmartMeter +### SmartBridge - Power Flow (W) - Energy Consumption (kWh) diff --git a/net2grid/__init__.py b/net2grid/__init__.py index 84478c3..576f7a9 100644 --- a/net2grid/__init__.py +++ b/net2grid/__init__.py @@ -1,7 +1,7 @@ """Asynchronous Python client for a NED2GRID device.""" from .exceptions import Net2GridConnectionError, Net2GridError -from .models import Device, SmartMeter +from .models import Device, SmartBridge from .net2grid import Net2Grid __all__ = [ @@ -9,5 +9,5 @@ "Net2Grid", "Net2GridError", "Net2GridConnectionError", - "SmartMeter", + "SmartBridge", ] diff --git a/net2grid/models.py b/net2grid/models.py index 55faa1b..ad8c5a4 100644 --- a/net2grid/models.py +++ b/net2grid/models.py @@ -6,22 +6,22 @@ @dataclass -class SmartMeter: - """Object representing an SmartMeter response from a NET2GRID device.""" +class SmartBridge: + """Object representing an SmartBridge response from a NET2GRID device.""" power_flow: int energy_consumption_total: float energy_production_total: float @staticmethod - def from_dict(data: dict[str, Any]) -> SmartMeter: - """Return SmartMeter object from the NET2GRID API response. + def from_dict(data: dict[str, Any]) -> SmartBridge: + """Return SmartBridge object from the NET2GRID API response. Args: data: The data from the NET2GRID API. Returns: - A SmartMeter object. + A SmartBridge object. """ data = data["elec"] @@ -37,7 +37,7 @@ def convert(value): value = value / 1000 return round(value, 1) - return SmartMeter( + return SmartBridge( power_flow=data["power"]["now"].get("value"), energy_consumption_total=convert(data["import"]["now"].get("value")), energy_production_total=convert(data["export"]["now"].get("value")), diff --git a/net2grid/net2grid.py b/net2grid/net2grid.py index db838bf..b6bdbb6 100644 --- a/net2grid/net2grid.py +++ b/net2grid/net2grid.py @@ -14,7 +14,7 @@ from yarl import URL from .exceptions import Net2GridConnectionError -from .models import Device, SmartMeter +from .models import Device, SmartBridge @dataclass @@ -95,15 +95,15 @@ async def device(self) -> Device: data = json.loads(data) return Device.from_dict(data) - async def smartmeter(self) -> SmartMeter: + async def smartbridge(self) -> SmartBridge: """Get the latest values from a NET2GRID device. Returns: - A SmartMeter data object from the API. + A SmartBridge data object from the API. """ data = await self.request("meter/now") data = json.loads(data) - return SmartMeter.from_dict(data) + return SmartBridge.from_dict(data) async def close(self) -> None: """Close open client session.""" diff --git a/test_output.py b/test_output.py index 2916566..8562255 100644 --- a/test_output.py +++ b/test_output.py @@ -3,7 +3,7 @@ import asyncio -from net2grid import Device, Net2Grid, SmartMeter +from net2grid import Device, Net2Grid, SmartBridge async def main(): @@ -11,13 +11,13 @@ async def main(): async with Net2Grid( host="example.com", ) as net2grid: - smartmeter: SmartMeter = await net2grid.smartmeter() + smartbridge: SmartBridge = await net2grid.smartbridge() device: Device = await net2grid.device() - print(smartmeter) + print(smartbridge) print() - print(f"Power flow: {smartmeter.power_flow}") - print(f"Energy consumption: {smartmeter.energy_consumption_total}") - print(f"Energy production: {smartmeter.energy_production_total}") + print(f"Power flow: {smartbridge.power_flow}") + print(f"Energy consumption: {smartbridge.energy_consumption_total}") + print(f"Energy production: {smartbridge.energy_production_total}") print() print(device) print(f"ID: {device.n2g_id}") diff --git a/tests/fixtures/smartmeter.json b/tests/fixtures/smartbridge.json similarity index 100% rename from tests/fixtures/smartmeter.json rename to tests/fixtures/smartbridge.json diff --git a/tests/test_models.py b/tests/test_models.py index 4c13ee9..8c68107 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -2,7 +2,7 @@ import aiohttp import pytest -from net2grid import Device, Net2Grid, SmartMeter +from net2grid import Device, Net2Grid, SmartBridge from . import load_fixtures @@ -33,22 +33,22 @@ async def test_device(aresponses): @pytest.mark.asyncio -async def test_smartmeter(aresponses): - """Test request from a NET2GRID device - SmartMeter object.""" +async def test_smartbridge(aresponses): + """Test request from a NET2GRID device - SmartBridge object.""" aresponses.add( "example.com", "/meter/now", "GET", aresponses.Response( - text=load_fixtures("smartmeter.json"), + text=load_fixtures("smartbridge.json"), status=200, ), ) async with aiohttp.ClientSession() as session: client = Net2Grid(host="example.com", session=session) - smartmeter: SmartMeter = await client.smartmeter() - assert smartmeter - assert smartmeter.power_flow == 338 - assert smartmeter.energy_consumption_total == 17762.1 - assert smartmeter.energy_production_total == 21214.6 + smartbridge: SmartBridge = await client.smartbridge() + assert smartbridge + assert smartbridge.power_flow == 338 + assert smartbridge.energy_consumption_total == 17762.1 + assert smartbridge.energy_production_total == 21214.6 diff --git a/tests/test_net2grid.py b/tests/test_net2grid.py index d7e1f4b..d3c1c28 100644 --- a/tests/test_net2grid.py +++ b/tests/test_net2grid.py @@ -69,7 +69,7 @@ async def test_timeout(aresponses): async def response_handler(_): await asyncio.sleep(0.2) return aresponses.Response( - body="Goodmorning!", text=load_fixtures("smartmeter.json") + body="Goodmorning!", text=load_fixtures("smartbridge.json") ) aresponses.add("example.com", "/meter/now", "GET", response_handler) @@ -77,7 +77,7 @@ async def response_handler(_): async with aiohttp.ClientSession() as session: client = Net2Grid(host="example.com", session=session, request_timeout=0.1) with pytest.raises(Net2GridConnectionError): - assert await client.smartmeter() + assert await client.smartbridge() @pytest.mark.asyncio