-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Major overhaul to incorporate gateway version 3 API. Version can be automatically detected or manually specified. - UserData class is deprecated and replaced with Hub. - ShadePosition class now replaces the raw json management of shades in support of cross generational management. - Schedules / Automations are now supported by the API - New get_*objecttype* methods available to returned structured data objects for consistent management
- Loading branch information
Showing
30 changed files
with
2,238 additions
and
726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Aio PowerView api version.""" | ||
|
||
__version__ = "2.0.4" | ||
__version__ = "3.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Scenes class managing all scene data.""" | ||
|
||
import logging | ||
|
||
from aiopvapi.helpers.aiorequest import AioRequest | ||
from aiopvapi.helpers.api_base import ApiEntryPoint | ||
from aiopvapi.helpers.constants import ( | ||
ATTR_ID, | ||
ATTR_SCHEDULED_EVENT_DATA, | ||
) | ||
from aiopvapi.resources.automation import Automation | ||
|
||
from aiopvapi.resources.model import PowerviewData | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class Automations(ApiEntryPoint): | ||
"""Powerview Automations""" | ||
|
||
def __init__(self, request: AioRequest) -> None: | ||
self.api_endpoint = "scheduledevents" | ||
if request.api_version >= 3: | ||
self.api_endpoint = "automations" | ||
super().__init__(request, self.api_endpoint) | ||
|
||
def _resource_factory(self, raw): | ||
return Automation(raw, self.request) | ||
|
||
def _loop_raw(self, raw): | ||
if self.api_version < 3: | ||
raw = raw[ATTR_SCHEDULED_EVENT_DATA] | ||
|
||
for _raw in raw: | ||
yield _raw | ||
|
||
def _get_to_actual_data(self, raw): | ||
if self.api_version >= 3: | ||
return raw | ||
return raw.get("scene") | ||
|
||
async def get_automations(self, fetch_scene_data: bool = True) -> PowerviewData: | ||
"""Get a list of automations. | ||
:returns PowerviewData object | ||
:raises PvApiError when an error occurs. | ||
""" | ||
resources = await self.get_resources() | ||
if self.api_version < 3: | ||
resources = resources[ATTR_SCHEDULED_EVENT_DATA] | ||
|
||
processed = {entry[ATTR_ID]: Automation(entry, self.request) for entry in resources} | ||
|
||
if fetch_scene_data is True: | ||
for automation in processed.values(): | ||
await automation.fetch_associated_scene_data() | ||
|
||
_LOGGER.debug("Raw automation data: %s", resources) | ||
return PowerviewData(raw=resources, processed=processed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.