Skip to content

Commit

Permalink
Rename charge_schedule helpers (#1306)
Browse files Browse the repository at this point in the history
* Update HVAC schedule

* Fix E501 Line too long

* Changes made by Ruff

* Update unit tests

* Restated old method names and marked them as deprecated

* Rollback hvac_schedule

* Rollback tests

* Rollback tests

---------

Co-authored-by: Kristof Van Hertum <[email protected]>
Co-authored-by: vhkristof <>
  • Loading branch information
epenet and vhkristof authored Aug 29, 2024
1 parent 734806a commit 9847aac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 28 additions & 2 deletions src/renault_api/kamereon/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from typing import Any
from warnings import warn

from . import models

Expand All @@ -17,8 +18,22 @@
]


def update_schedule(schedule: models.ChargeSchedule, settings: dict[str, Any]) -> None:
"""Update schedule."""
def update_schedule(
schedule: models.ChargeSchedule, settings: dict[str, Any]
) -> None: # pragma: no cover
"""Update charge schedule."""
warn(
"This method is deprecated, please use update_charge_schedule.",
DeprecationWarning,
stacklevel=2,
)
update_charge_schedule(schedule, settings)


def update_charge_schedule(
schedule: models.ChargeSchedule, settings: dict[str, Any]
) -> None:
"""Update charge schedule."""
if "activated" in settings:
schedule.activated = settings["activated"]
for day in DAYS_OF_WEEK:
Expand All @@ -40,6 +55,17 @@ def update_schedule(schedule: models.ChargeSchedule, settings: dict[str, Any]) -

def create_schedule(
settings: dict[str, Any],
) -> models.ChargeSchedule: # pragma: no cover
warn(
"This method is deprecated, please use create_charge_schedule.",
DeprecationWarning,
stacklevel=2,
)
return create_charge_schedule(settings)


def create_charge_schedule(
settings: dict[str, Any],
) -> models.ChargeSchedule: # pragma: no cover
"""Update schedule."""
raise NotImplementedError
Expand Down
4 changes: 2 additions & 2 deletions src/renault_api/kamereon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ def update(self, args: Dict[str, Any]) -> None:
self.schedules = []
for schedule in self.schedules:
if schedule.id == args["id"]: # pragma: no branch
helpers.update_schedule(schedule, args)
helpers.update_charge_schedule(schedule, args)
return
self.schedules.append(helpers.create_schedule(args)) # pragma: no cover
self.schedules.append(helpers.create_charge_schedule(args)) # pragma: no cover


@dataclass
Expand Down

0 comments on commit 9847aac

Please sign in to comment.