Skip to content

Commit

Permalink
fix: make attributes optional
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
MrMarble committed Jun 30, 2024
1 parent 9a058b2 commit 145277f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions datadis/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class ConsumptionData(TypedDict):
time: str
consumptionKWh: float
obtainMethod: str
surplusEnergyKWh: float


class MaxPower(TypedDict):
cups: str
date: str
time: str
maxPower: float
period: str


T = TypeVar("T", Supplie, ConsumptionData, ContractDetail, MaxPower)
Expand All @@ -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

0 comments on commit 145277f

Please sign in to comment.