Skip to content

Commit

Permalink
Improved support for weekly schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
Ola Lidholm committed Sep 9, 2023
1 parent 95694d3 commit b2c9bdc
Showing 1 changed file with 53 additions and 14 deletions.
67 changes: 53 additions & 14 deletions pyeasee/charger.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,20 +370,52 @@ async def get_weekly_charge_plan(self) -> ChargerWeeklySchedule:
# TODO: document types
async def set_weekly_charge_plan(self, day, chargeStartTime, chargeStopTime, enabled=True):
"""Set and post charger weekly charge plan setting to cloud"""
json = {
"isEnabled": enabled,
"days": [
{
"dayOfWeek": day,
"ranges": [
{
"startTime": str(chargeStartTime),
"stopTime": str(chargeStopTime),
}
],
}
],
}

try:
plan = await self.easee.get(f"/api/chargers/{self.id}/weekly_charge_plan")
plan = await plan.json()
_LOGGER.debug(plan)
except (NotFoundException):
_LOGGER.debug("No scheduled charge plan")
plan = None
except (ServerFailureException):
return None

if plan is None:
json = {
"isEnabled": enabled,
"days": [
{
"dayOfWeek": day,
"ranges": [
{
"startTime": str(chargeStartTime),
"stopTime": str(chargeStopTime),
}
],
}
],
}
else:
json = plan
days = json["days"]
newdays = []
for oldday in days:
if oldday["dayOfWeek"] == day:
newday = {
"dayOfWeek": day,
"ranges": [
{
"startTime": str(chargeStartTime),
"stopTime": str(chargeStopTime),
}
],
}
newdays.append(newday)
else:
newdays.append(oldday)
json["days"] = newdays

try:
return await self.easee.post(f"/api/chargers/{self.id}/weekly_charge_plan", json=json)
except (ServerFailureException):
Expand Down Expand Up @@ -444,6 +476,13 @@ async def delete_basic_charge_plan(self):
except (ServerFailureException):
return None

async def delete_weekly_charge_plan(self):
"""Delete charger basic charge plan setting from cloud"""
try:
return await self.easee.delete(f"/api/chargers/{self.id}/weekly_charge_plan")
except (ServerFailureException):
return None

async def override_schedule(self):
"""Override scheduled charging and start charging"""
try:
Expand Down

0 comments on commit b2c9bdc

Please sign in to comment.