Skip to content

Commit

Permalink
use same syntax as Pronote to use Pronote cards
Browse files Browse the repository at this point in the history
use same syntax as Pronote to use Pronote cards
use snake_case
add comment to class, methods, etc.
fix homeworks
  • Loading branch information
Giga77 committed Mar 22, 2024
1 parent 51241c3 commit b254c20
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 204 deletions.
53 changes: 37 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
# Ecole directe integration for Home Assistant
# Integration Ecole directe pour Home Assistant

![Version](https://img.shields.io/github/v/release/hacf-fr/hass-ecoledirecte?label=version)
![Version](https://img.shields.io/github/v/release/hacf-fr/hass-ecoledirecte?label=version) [![HACS: Custom](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)

### Manual install
- [Installation](#Installation)
- [Installation via l'interface utilisateur via HACS](#Installation-via-l'interface-utilisateur-via-HACS)
- [Installation manuelle](<#Installation-manuelle>)
- [Configuration](#Configuration)
- [Utilisation](#Utilisation)

Copy the `ecole_directe` folder from latest release to the `custom_components` folder in your `config` folder.
Restart Home Assistant

## Installation


### Installation via l'interface utilisateur via HACS

1. Depuis [HACS](https://hacs.xyz/) (Home Assistant Community Store), sélectionner `Intégrations`. Puis ouvrez le menu en haut à droite et utiliser l'option `Dépôts personnalisés` pour ajouter le dépôt de l'intégration.

2. Ajoutez l'adresse <https://github.com/hacf-fr/hass-ecoledirecte> avec pour catégorie `Intégration`, et faire `AJOUTER`. Le dépôt apparaît dans la liste.

3. La carte de ce `nouveau dépôt` va s'afficher, cliquez sur celle-ci puis `Télécharger` en bas à droite.

4. Laisser le choix de la dernière version et utiliser l'option `Télécharger`.

5. Il faut ensuite redémarrer Home Assistant.


### Installation manuelle
Copier le répertoire ecole_directe de la dernière release dans le répertoire custom_components de votre répertoire config. Redémarrer Home Assistant

## Configuration

Click on the following button:
Cliquer sur ce boutton:
[![Open your Home Assistant instance and start setting up a new integration of a specific brand.](https://my.home-assistant.io/badges/brand.svg)](https://my.home-assistant.io/redirect/brand/?brand=ecole_directe)

Or go to :
Settings > Devices & Sevices > Integrations > Add Integration, and search for "Ecole Directe"

Use your username and password :
Ou aller dans :
Paramètres > Appareils et services > Intégrations > Ajouter une intégration, et chercher "Ecole Directe"

Utiliser votre identifiant et mot de passe password :
![Ecole directe config flow](doc/config_flow_username_password.png)

## Usage
## Utilisation

This integration provides several sensors, always prefixed with `ecole_directe_FIRSTNAME_LASTNAME` (where `FIRSTNAME` and `LASTNAME` are replaced).
Cette intégration fournit plusieurs entités, toujours prefixées avec `ecole_directe_PRENOM_NOM` (`PRENOM` et `NOM` sont remplacé).


| Sensor | Description |
|--------|-------------|
| `sensor.ecole_directe_FIRSTNAME_LASTNAME` | basic informations about your child |
| `[...]_homework` | homework |
| `[...]_evaluations` | evaluations |
| `sensor.ecole_directe_PRENOM_NOM` | informations basique de l'enfant |
| `[...]_homework` | devoirs |
| `[...]_grades` | notes |

Les entités sont mises à jour toutes les 30 minutes.

The sensors are updated every 30 minutes.
9 changes: 4 additions & 5 deletions custom_components/ecole_directe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

from __future__ import annotations

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
import logging

from datetime import timedelta

import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady

from .coordinator import EDDataUpdateCoordinator

from .const import DEFAULT_REFRESH_INTERVAL, DOMAIN, PLATFORMS

_LOGGER = logging.getLogger(__name__)
Expand Down
4 changes: 3 additions & 1 deletion custom_components/ecole_directe/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.exceptions import HomeAssistantError
from homeassistant.core import callback

from .ecoleDirecte_helper import (
from .ecole_directe_helper import (
get_ecoledirecte_session,
)

Expand Down Expand Up @@ -83,6 +83,8 @@ class InvalidAuth(HomeAssistantError):


class OptionsFlowHandler(config_entries.OptionsFlow):
"""Configuration of integration options"""

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ecole_directe/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

# default values for options
DEFAULT_REFRESH_INTERVAL = 30
NOTES_TO_DISPLAY = 15
GRADES_TO_DISPLAY = 15
HOMEWORK_DESC_MAX_LENGTH = 125
72 changes: 51 additions & 21 deletions custom_components/ecole_directe/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import TimestampDataUpdateCoordinator

from .ecoleDirecte_helper import get_ecoledirecte_session, getDevoirs, getNotes
from .ecole_directe_helper import (
get_ecoledirecte_session,
get_homeworks,
get_grades,
get_homeworks_by_date,
)

from .const import (
DEFAULT_REFRESH_INTERVAL,
Expand Down Expand Up @@ -52,45 +57,70 @@ async def _async_update_data(self) -> dict[Platform, dict[str, Any]]:
self.data = {}
self.data["session"] = session

currentYear = datetime.datetime.now().year
if (currentYear % 2) == 0:
yearData = f"{str(currentYear-1)}-{str(currentYear)}"
current_year = datetime.datetime.now().year
if (current_year % 2) == 0:
year_data = f"{str(current_year-1)}-{str(current_year)}"
else:
yearData = f"{str(currentYear)}-{str(currentYear + 1)}"
year_data = f"{str(current_year)}-{str(current_year + 1)}"

# if (session.typeCompte == '1'): # famille
# if session._account_type == "1": # famille
# if "MESSAGERIE" in session.modules:
# try:
# self.data['messages'] = await self.hass.async_add_executor_job(getMessages, session, None, yearData)
# self.data["messages"] = await self.hass.async_add_executor_job(
# get_messages, session, None, year_data
# )
# except Exception as ex:
# self.data['messages'] = None
# _LOGGER.warning("Error getting messages for family from ecole directe: %s", ex)
# self.data["messages"] = None
# _LOGGER.warning(
# "Error getting messages for family from ecole directe: %s", ex
# )

for eleve in session.eleves:
if "CAHIER_DE_TEXTES" in eleve.modules:
try:
self.data[
"devoirs" + eleve.get_fullnameLower()
] = await self.hass.async_add_executor_job(
getDevoirs, session, eleve
homeworks_json = await self.hass.async_add_executor_job(
get_homeworks, session, eleve
)
for key in homeworks_json.keys():
homeworks_by_date_json = await self.hass.async_add_executor_job(
get_homeworks_by_date, session, eleve, key
)
_LOGGER.debug(
"homeworks_by_date_json:%s", homeworks_by_date_json
)
for matiere in homeworks_by_date_json["matieres"]:
for homework in homeworks_json[key]:
if matiere["id"] == homework["idDevoir"]:
homework["nbJourMaxRenduDevoir"] = matiere[
"nbJourMaxRenduDevoir"
]
homework["contenu"] = matiere["aFaire"]["contenu"]

_LOGGER.debug("homeworks_json:%s", homeworks_json)
self.data[f"homeworks{eleve.get_fullname_lower()}"] = homeworks_json
except Exception as ex:
_LOGGER.warning("Error getting devoirs from ecole directe: %s", ex)
self.data["devoirs" + eleve.get_fullnameLower()] = {}
_LOGGER.warning(
"Error getting homeworks from ecole directe: %s", ex
)
self.data[f"homeworks{eleve.get_fullname_lower()}"] = {}
if "NOTES" in eleve.modules:
try:
self.data[
"notes" + eleve.get_fullnameLower()
f"grades{eleve.get_fullname_lower()}"
] = await self.hass.async_add_executor_job(
getNotes, session, eleve, yearData
get_grades, session, eleve, year_data
)
except Exception as ex:
_LOGGER.warning("Error getting notes from ecole directe: %s", ex)
self.data["notes" + eleve.get_fullnameLower()] = {}
_LOGGER.warning("Error getting grades from ecole directe: %s", ex)
self.data[f"grades{eleve.get_fullname_lower()}"] = {}
# if "MESSAGERIE" in eleve.modules:
# try:
# self.data['messages'+ eleve.eleve_id] = await self.hass.async_add_executor_job(getMessages, session, eleve, yearData)
# self.data[
# "messages" + eleve.eleve_id
# ] = await self.hass.async_add_executor_job(
# get_messages, session, eleve, year_data
# )
# except Exception as ex:
# _LOGGER.warning("Error getting notes from ecole directe: %s", ex)
# _LOGGER.warning("Error getting messages from ecole directe: %s", ex)

return self.data
Loading

0 comments on commit b254c20

Please sign in to comment.