Skip to content

Commit

Permalink
Add Core response and Core state
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseRMorales committed Jul 2, 2024
1 parent 6ca0548 commit b247431
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ if __name__ == "__main__":

True if the server is healthy

- `get_core_state() -> dict`

Retrieve the core state

- `get_devices() -> list[DeviceResponse]`

Retrieve a list of devices
Expand All @@ -51,3 +55,27 @@ Retrieve the device consumption by name
- `get_surplus() -> float:`

Retrieve the surplus value

- `set_surplus_margin(margin: float) -> float:`

Set the surplus margin

- `set_grid_margin(margin: float) -> float:`

Set the grid margin

- `set_idle_power(idle_power: float) -> float:`

Set the idle power

- `set_device_max_consumption(device_name: str, max_consumption: float) -> float:`

Set the max consumption for a device

- `set_device_expected_consumption(device_name: str, expected_consumption: float) -> float:`

Set the expected consumption for a device

- `set_device_cooldown(device_name: str, cooldown: int) -> int:`

Set the cooldown for a device
13 changes: 11 additions & 2 deletions pyosmanager/pyosmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import aiohttp
import backoff

from pyosmanager.responses import DeviceResponse
from pyosmanager.responses import CoreResponse, DeviceResponse

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,7 +72,7 @@ async def __post_data(self, endpoint, data):
"""
try:
async with self.session.post(
f"{self.base_url}/{endpoint}", json=data
f"{self.base_url}/api/{endpoint}", json=data
) as response:
response.raise_for_status()
data = await response.json()
Expand All @@ -94,6 +94,15 @@ async def is_healthy(self) -> bool:
except APIError:
return False

async def get_core_state(self) -> dict:
"""
Get the core state of the system.
:return: Core state of the system
"""
core = await self.__get_data("core")
return CoreResponse(**core)

async def get_devices(self) -> list[DeviceResponse]:
"""
Get a list of all devices.
Expand Down
13 changes: 13 additions & 0 deletions pyosmanager/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ class DeviceResponse:
powered: bool
cooldown: int | None
enabled: bool


@dataclass
class CoreResponse:
"""
This class is used to represent the response of the API
when querying for the core.
"""

surplus: float
surplus_margin: float
grid_margin: float
idle_power: float
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name="pyosmanager",
packages=["pyosmanager"],
version="0.2.1",
version="0.2.2",
license="MIT",
description="Python client for Open Surplus Manager",
long_description=long_description,
Expand Down

0 comments on commit b247431

Please sign in to comment.