Skip to content
Open
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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ import asyncio

ACCOUNTID = "<ACCOUNT ID>" # get your account ID (6 digits) from the Account page in the Adax WiFi app
PASSWORD = "<PASSWORD>" # create a service password under "Remote Api" in the app
withenergy = True

async def main():
async with aiohttp.ClientSession() as session:
heater= Adax(ACCOUNTID, PASSWORD, session)
heater= Adax(ACCOUNTID, PASSWORD, session, withenergy)
for home in await heater.get_homes():
print(home)
for room in await heater.get_rooms():
print(room)
for device in await heater.get_devices():
print(device)
energy = await heater.get_energy()
for room_id in energy:
print(room_id)
print(energy[room_id])

asyncio.run(main())

Expand Down
27 changes: 25 additions & 2 deletions adax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
class Adax:
"""Adax data handler."""

def __init__(self, account_id, password, websession):
def __init__(self, account_id, password, websession, withenergy=False):
"""Init Adax data handler."""
self._account_id = account_id
self._password = password
self.withenergy = withenergy
self.websession = websession
self._access_token = None
self._homes = []
self._rooms = []
self._devices = []
self._energy = {}
self._timeout = 10

Expand All @@ -31,11 +34,26 @@ def __init__(self, account_id, password, websession):
self._write_task = None
self._pending_writes = {"rooms": []}

async def get_homes(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to not do self.update() in all these functions. Should be possible to get self._homes without forcing an update.
(Should not had self.update() in get_rooms either)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't wanted to such refactor. Imho, the cleanest would be to have functions which are 1-on-1 with the API endpoints.

"""Get Adax homes."""
await self.update()
return self._homes

async def get_rooms(self):
"""Get Adax rooms."""
await self.update()
return self._rooms

async def get_devices(self):
"""Get Adax devices."""
await self.update()
return self._devices

async def get_energy(self):
"""Get Adax energy."""
await self.update()
return self._energy

async def update(self):
"""Update data."""
if (
Expand Down Expand Up @@ -104,13 +122,18 @@ async def _write_set_room_target_temperature(self, json_data):

async def fetch_rooms_info(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add an include_energy parameter and then remove self.withenergy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current structure that would mean to pass it down from get_room and update

"""Get rooms info."""
response = await self._request(API_URL + "/rest/v1/content/", retry=1)
withenergy_query = ""
if self.withenergy:
withenergy_query = "?withEnergy=1"
response = await self._request(f"{API_URL}/rest/v1/content/{withenergy_query}", retry=1)
if response is None:
return
json_data = await response.json()
if json_data is None:
return
self._homes = json_data["homes"]
self._rooms = json_data["rooms"]
self._devices = json_data["devices"]
for room in self._rooms:
room["targetTemperature"] = room.get("targetTemperature", 0) / 100.0
room["temperature"] = room.get("temperature", 0) / 100.0
Expand Down