diff --git a/mytoyota/models/vehicle.py b/mytoyota/models/vehicle.py index 51885244..91a0413e 100644 --- a/mytoyota/models/vehicle.py +++ b/mytoyota/models/vehicle.py @@ -235,7 +235,7 @@ async def get_summary( from_date: date, to_date: date, summary_type: SummaryType = SummaryType.MONTHLY, - ) -> Optional[List[Summary]]: + ) -> List[Summary]: """Return a Daily, Weekly, Monthly or Yearly summary between the provided dates. All but Daily can return a partial time range. For example if the summary_type is weekly @@ -264,8 +264,8 @@ async def get_summary( resp = await self._api.get_trips_endpoint( self.vin, from_date, to_date, summary=True, limit=1, offset=0 ) - if resp.payload is None: - return None + if resp.payload is None or len(resp.payload.summary) == 0: + return [] # Convert to response if summary_type == SummaryType.DAILY: @@ -424,17 +424,22 @@ def _generate_yearly_summaries(self, summary, to_date: date) -> List[Summary]: build_summary = copy.copy(summary[0].summary) start_date = date(day=1, month=summary[0].month, year=summary[0].year) - for month, next_month in zip(summary, summary[1:] + [None]): - summary_month = date(day=1, month=month.month, year=month.year) - add_with_none(build_hdc, month.hdc) - build_summary += month.summary - - if next_month is None or next_month.year != month.year: - end_date = min(to_date, date(day=31, month=12, year=summary_month.year)) - ret.append(Summary(build_summary, self._metric, start_date, end_date, build_hdc)) - if next_month: - start_date = date(day=1, month=next_month.month, year=next_month.year) - build_hdc = copy.copy(next_month.hdc) - build_summary = copy.copy(next_month.summary) + if len(summary) == 1: + ret.append(Summary(build_summary, self._metric, start_date, to_date, build_hdc)) + else: + for month, next_month in zip(summary[1:], summary[2:] + [None]): + summary_month = date(day=1, month=month.month, year=month.year) + add_with_none(build_hdc, month.hdc) + build_summary += month.summary + + if next_month is None or next_month.year != month.year: + end_date = min(to_date, date(day=31, month=12, year=summary_month.year)) + ret.append( + Summary(build_summary, self._metric, start_date, end_date, build_hdc) + ) + if next_month: + start_date = date(day=1, month=next_month.month, year=next_month.year) + build_hdc = copy.copy(next_month.hdc) + build_summary = copy.copy(next_month.summary) return ret