Skip to content

Commit

Permalink
Add lunch break option
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Sep 20, 2024
1 parent 011d321 commit 7ded822
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions custom_components/ecole_directe/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .const import (
DEFAULT_ALLOW_NOTIFICATION,
DEFAULT_LUNCH_BREAK_TIME,
DOMAIN,
DEFAULT_REFRESH_INTERVAL,
FILENAME_QCM,
Expand Down Expand Up @@ -134,6 +135,12 @@ async def async_step_init(
"refresh_interval", DEFAULT_REFRESH_INTERVAL
),
): int,
vol.Optional(
"lunch_break_time",
default=self.config_entry.options.get(
"lunch_break_time", DEFAULT_LUNCH_BREAK_TIME
),
): str,
vol.Optional(
"decode_html",
default=self.config_entry.options.get("decode_html", False),
Expand Down
11 changes: 11 additions & 0 deletions custom_components/ecole_directe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from .const import (
DEBUG_ON,
DEFAULT_LUNCH_BREAK_TIME,
DEFAULT_REFRESH_INTERVAL,
EVENT_TYPE,
)
Expand Down Expand Up @@ -186,13 +187,23 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:

if DEBUG_ON or "EDT" in eleve.modules:
try:
break_time = self.config_entry.options.get(
"lunch_break_time", DEFAULT_LUNCH_BREAK_TIME
)
lunch_break_time = datetime.strptime(
break_time,
"%H:%M",
).time()
_LOGGER.warning("lunch_break_time: %s", lunch_break_time)

lessons = await self.hass.async_add_executor_job(
get_lessons,
session.token,
eleve,
current_week_begin.strftime("%Y-%m-%d"),
current_week_plus_21.strftime("%Y-%m-%d"),
self.hass.config.config_dir,
lunch_break_time,
)
self.data[f"{eleve.get_fullname_lower()}_timetable_today"] = list(
filter(
Expand Down
7 changes: 1 addition & 6 deletions custom_components/ecole_directe/ecole_directe_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def get_vie_scolaire_element(viescolaire) -> dict:
return {}


def get_lessons(token, eleve, date_debut, date_fin, config_path):
def get_lessons(token, eleve, date_debut, date_fin, config_path, lunch_break_time):
"""get lessons"""

if DEBUG_ON:
Expand All @@ -684,11 +684,6 @@ def get_lessons(token, eleve, date_debut, date_fin, config_path):
_LOGGER.warning("get_lessons: [%s]", json_resp)
return None

lunch_break_time = datetime.strptime(
DEFAULT_LUNCH_BREAK_TIME,
"%H:%M",
).time()

response = []
data = json_resp["data"]
for lesson_json in data:
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"description": "Customize the way the integration works",
"data": {
"refresh_interval": "Data refresh interval (in minutes)",
"lunch_break_time": "Lunch break time",
"decode_html": "Decode HTML for homeworks - Warning it will delete all HTML (style, links, iFrame, etc.)"
}
}
Expand Down
1 change: 1 addition & 0 deletions custom_components/ecole_directe/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"description": "Personnalisez le fonctionnement de l'intégration",
"data": {
"refresh_interval": "Intervale de mise à jour des données (en minutes)",
"lunch_break_time": "Heure de la pause déjeuner",
"decode_html": "Decode HTML pour les devoirs - Attention cela va supprimer tout le HTML (style, liens, iFrame, etc.)"
}
}
Expand Down

0 comments on commit 7ded822

Please sign in to comment.