-
-
Notifications
You must be signed in to change notification settings - Fork 4
withenergy construction option, get_homes() get_devices() get_energy() methods #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -31,11 +34,26 @@ def __init__(self, account_id, password, websession): | |
| self._write_task = None | ||
| self._pending_writes = {"rooms": []} | ||
|
|
||
| async def get_homes(self): | ||
| """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 ( | ||
|
|
@@ -104,13 +122,18 @@ async def _write_set_room_target_temperature(self, json_data): | |
|
|
||
| async def fetch_rooms_info(self): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to add an
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.