diff --git a/tibber/types/subscription_price_connection.py b/tibber/types/subscription_price_connection.py index e69de29..5e9570e 100644 --- a/tibber/types/subscription_price_connection.py +++ b/tibber/types/subscription_price_connection.py @@ -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", [])] diff --git a/tibber/types/subscription_price_connection_page_info.py b/tibber/types/subscription_price_connection_page_info.py index 8ec91cf..6ccefb6 100644 --- a/tibber/types/subscription_price_connection_page_info.py +++ b/tibber/types/subscription_price_connection_page_info.py @@ -3,6 +3,9 @@ """A class representing the SubscriptionPriceConnectionPageInfo type from the GraphQL Tibber API.""" from typing import TYPE_CHECKING +if TYPE_CHECKING: + from tibber.account import Account + class SubscriptionPriceConnectionPageInfo: def __init__(self, data: dict, tibber_client: "Account"): diff --git a/tibber/types/subscription_price_edge.py b/tibber/types/subscription_price_edge.py index a583e87..36e9fff 100644 --- a/tibber/types/subscription_price_edge.py +++ b/tibber/types/subscription_price_edge.py @@ -5,6 +5,9 @@ from tibber.types.price import Price +if TYPE_CHECKING: + from tibber.account import Account + class SubscriptionPriceEdge: def __init__(self, data: dict, tibber_client: "Account"):