From 145277f05ba22dd8f972f28a8c230cb0657e2d30 Mon Sep 17 00:00:00 2001 From: Alvaro Tinoco Date: Sun, 30 Jun 2024 22:38:00 +0200 Subject: [PATCH] fix: make attributes optional Closes #7 --- datadis/types.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/datadis/types.py b/datadis/types.py index da6a63e..bf2d14c 100644 --- a/datadis/types.py +++ b/datadis/types.py @@ -36,6 +36,7 @@ class ConsumptionData(TypedDict): time: str consumptionKWh: float obtainMethod: str + surplusEnergyKWh: float class MaxPower(TypedDict): @@ -43,6 +44,7 @@ class MaxPower(TypedDict): date: str time: str maxPower: float + period: str T = TypeVar("T", Supplie, ConsumptionData, ContractDetail, MaxPower) @@ -51,7 +53,6 @@ class MaxPower(TypedDict): def dict_to_typed(data: Mapping[str, Any], typed: Type[T]) -> T: result: T = typed.__call__() for key, _ in typed.__annotations__.items(): - if key not in data: - raise ValueError(f"Key: {key} is not available in data.") - result[key] = data[key] + if key in data: + result[key] = data[key] return result