Skip to content

Commit

Permalink
Fix bug moyenne generale
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Jan 15, 2025
1 parent 153009c commit c4f43b0
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions custom_components/ecole_directe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ async def async_setup_entry(
if DEBUG_ON or "NOTES" in eleve.modules:
sensors.append(EDGradesSensor(coordinator, eleve))
sensors.append(EDEvaluationsSensor(coordinator, eleve))
disciplines = coordinator.data[f"{eleve.get_fullname_lower()}_disciplines"]
disciplines = coordinator.data[f"{
eleve.get_fullname_lower()}_disciplines"]
for discipline in disciplines:
sensors.append(EDDisciplineSensor(coordinator, eleve,discipline["name"],discipline["moyenne"]))
moyenne = coordinator.data[f"{eleve.get_fullname_lower()}_moyenne_generale"]
sensors.append(EDMoyenneSensor(coordinator, eleve,moyenne["moyenneGenerale"]))
sensors.append(EDDisciplineSensor(
coordinator, eleve, discipline["name"], discipline["moyenne"]))
if f"{eleve.get_fullname_lower()}_moyenne_generale" in coordinator.data:
sensors.append(EDMoyenneSensor(coordinator, eleve, coordinator.data[f"{
eleve.get_fullname_lower()}_moyenne_generale"]))

if DEBUG_ON or "VIE_SCOLAIRE" in eleve.modules:
sensors.append(EDAbsencesSensor(coordinator, eleve))
Expand Down Expand Up @@ -157,7 +160,8 @@ class EDChildSensor(EDGenericSensor):
def __init__(self, coordinator: EDDataUpdateCoordinator, eleve: EDEleve) -> None:
"""Initialize the ED sensor."""
super().__init__(coordinator, "", eleve, "len")
self._attr_unique_id = f"ed_{eleve.get_fullname_lower()}_{eleve.eleve_id}]"
self._attr_unique_id = f"ed_{eleve.get_fullname_lower()}_{
eleve.eleve_id}]"
self._account_type = self.coordinator.data["session"]._account_type

@property
Expand Down Expand Up @@ -214,7 +218,8 @@ def extra_state_attributes(self):
in self.coordinator.data
):
homeworks = self.coordinator.data[
f"{self._child_info.get_fullname_lower()}_homework{self._suffix}"
f"{self._child_info.get_fullname_lower()}_homework{
self._suffix}"
]
for homework in homeworks:
if not homework["done"]:
Expand All @@ -231,7 +236,8 @@ def extra_state_attributes(self):

if is_too_big(attributes):
attributes = []
_LOGGER.warning("[%s] attributes are too big! %s", self._name, attributes)
_LOGGER.warning("[%s] attributes are too big! %s",
self._name, attributes)

return {
"updated_at": self.coordinator.last_update_success_time,
Expand Down Expand Up @@ -262,6 +268,7 @@ def extra_state_attributes(self):
"grades": attributes,
}


class EDDisciplineSensor(EDGenericSensor):
"""Representation of a ED sensor."""

Expand All @@ -280,9 +287,10 @@ def extra_state_attributes(self):
"moyenneClasse": discipline["moyenneClasse"],
"moyenneMin": discipline["moyenneMin"],
"moyenneMax": discipline["moyenneMax"],
"appreciations":discipline["appreciations"]
"appreciations": discipline["appreciations"]
}


class EDLessonsSensor(EDGenericSensor):
"""Representation of a ED sensor."""

Expand Down Expand Up @@ -341,7 +349,8 @@ def extra_state_attributes(self):
):
self._lunch_break_end_at = lesson["start"]
if is_too_big(attributes):
_LOGGER.warning("[%s] attributes are too big! %s", self._name, attributes)
_LOGGER.warning("[%s] attributes are too big! %s",
self._name, attributes)
attributes = []
result = {
"updated_at": self.coordinator.last_update_success_time,
Expand All @@ -357,6 +366,7 @@ def extra_state_attributes(self):

return result


class EDMoyenneSensor(EDGenericSensor):
"""Representation of a ED sensor."""

Expand All @@ -379,6 +389,7 @@ def extra_state_attributes(self):
"dateCalcul": moyenne["dateCalcul"],
}


class EDEvaluationsSensor(EDGenericSensor):
"""Representation of a ED sensor."""

Expand Down

0 comments on commit c4f43b0

Please sign in to comment.