Skip to content

Commit

Permalink
fix sensor creation + decode64
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Mar 23, 2024
1 parent c69c3ff commit f80adc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions custom_components/ecole_directe/ecole_directe_formatter.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
"""Data Formatter for the Ecole Directe integration."""

import base64
import logging
from .const import HOMEWORK_DESC_MAX_LENGTH

_LOGGER = logging.getLogger(__name__)


def format_homework(homework):
"""format homework"""
try:
contenu = base64.b64decode(homework.contenu).decode("utf-8")
return {
"date": homework.pour_le,
"subject": homework.matiere,
"short_description": homework.contenu[0:HOMEWORK_DESC_MAX_LENGTH],
"description": homework.contenu,
"short_description": contenu[0:HOMEWORK_DESC_MAX_LENGTH],
"description": contenu,
"done": homework.effectue,
"background_color": None,
"files": None,
Expand All @@ -25,9 +30,10 @@ def format_homework(homework):
"interrogation": homework.interrogation,
"rendreEnLigne": homework.rendre_en_ligne,
"nbJourMaxRenduDevoir": homework.nb_jour_max_rendu_devoir,
"contenu": homework.contenu,
"contenu": contenu,
}
except Exception:
except Exception as ex:
_LOGGER.warning("Error: %s - format_homework: %s", ex, homework)
return {}


Expand Down Expand Up @@ -71,5 +77,6 @@ def format_grade(grade):
"maxClasse": grade.max_classe,
"elementsProgramme": grade.elements_programme,
}
except Exception:
except Exception as ex:
_LOGGER.warning("Error: %s - format_grade: %s", ex, grade)
return {}
4 changes: 2 additions & 2 deletions custom_components/ecole_directe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def __init__(self, coordinator: EDDataUpdateCoordinator, eleve: EDEleve) -> None
"""Initialize the ED sensor."""
super().__init__(
coordinator,
f"homeworks{self._child_info.get_fullname_lower()}",
f"homeworks{eleve.get_fullname_lower()}",
eleve,
"len",
)
Expand Down Expand Up @@ -202,7 +202,7 @@ class EDGradesSensor(EDGenericSensor):
def __init__(self, coordinator: EDDataUpdateCoordinator, eleve: EDEleve) -> None:
"""Initialize the ED sensor."""
super().__init__(
coordinator, f"grades{self._child_info.get_fullname_lower()}", eleve, "len"
coordinator, f"grades{eleve.get_fullname_lower()}", eleve, "len"
)

@property
Expand Down

0 comments on commit f80adc5

Please sign in to comment.