-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
"""A class representing the SubscriptionPriceConnection type from the GraphQL Tibber API.""" | ||
from typing import TYPE_CHECKING | ||
|
||
from tibber.types.price import Price | ||
from tibber.types.subscription_price_connection_page_info import \ | ||
SubscriptionPriceConnectionPageInfo | ||
from tibber.types.subscription_price_edge import SubscriptionPriceEdge | ||
|
||
if TYPE_CHECKING: | ||
from tibber.account import Account | ||
|
||
|
||
class SubscriptionPriceConnection: | ||
"""A class to get subscription price connection.""" | ||
|
||
def __init__(self, data: dict, tibber_client: "Account"): | ||
self.cache: dict = data or {} | ||
self.tibber_client: "Account" = tibber_client | ||
|
||
@property | ||
def edges(self) -> list[SubscriptionPriceEdge]: | ||
return [ | ||
SubscriptionPriceEdge(edge, self.tibber_client) | ||
for edge in self.cache.get("edges", []) | ||
] | ||
|
||
@property | ||
def pageInfo(self) -> SubscriptionPriceConnectionPageInfo: | ||
return SubscriptionPriceConnectionPageInfo( | ||
self.cache.get("pageInfo"), self.tibber_client | ||
) | ||
|
||
@property | ||
def nodes(self) -> list[Price]: | ||
"""List of Price objects from the executed range query.""" | ||
return [Price(node, self.tibber_client) for node in self.cache.get("nodes", [])] |
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