|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +"""A class representing the SubscriptionPriceConnection type from the GraphQL Tibber API.""" |
| 4 | +from typing import TYPE_CHECKING |
| 5 | + |
| 6 | +from tibber.types.price import Price |
| 7 | +from tibber.types.subscription_price_connection_page_info import \ |
| 8 | + SubscriptionPriceConnectionPageInfo |
| 9 | +from tibber.types.subscription_price_edge import SubscriptionPriceEdge |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from tibber.account import Account |
| 13 | + |
| 14 | + |
| 15 | +class SubscriptionPriceConnection: |
| 16 | + """A class to get subscription price connection.""" |
| 17 | + |
| 18 | + def __init__(self, data: dict, tibber_client: "Account"): |
| 19 | + self.cache: dict = data or {} |
| 20 | + self.tibber_client: "Account" = tibber_client |
| 21 | + |
| 22 | + @property |
| 23 | + def edges(self) -> list[SubscriptionPriceEdge]: |
| 24 | + return [ |
| 25 | + SubscriptionPriceEdge(edge, self.tibber_client) |
| 26 | + for edge in self.cache.get("edges", []) |
| 27 | + ] |
| 28 | + |
| 29 | + @property |
| 30 | + def pageInfo(self) -> SubscriptionPriceConnectionPageInfo: |
| 31 | + return SubscriptionPriceConnectionPageInfo( |
| 32 | + self.cache.get("pageInfo"), self.tibber_client |
| 33 | + ) |
| 34 | + |
| 35 | + @property |
| 36 | + def nodes(self) -> list[Price]: |
| 37 | + """List of Price objects from the executed range query.""" |
| 38 | + return [Price(node, self.tibber_client) for node in self.cache.get("nodes", [])] |
0 commit comments