-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
325 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,94 @@ | ||
"""Data update coordinator for the Ecole Directe integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
import datetime | ||
import logging | ||
from datetime import timedelta | ||
from typing import Any | ||
|
||
import logging | ||
from .ecoleDirecte_helper import * | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.update_coordinator import TimestampDataUpdateCoordinator | ||
|
||
from .ecoleDirecte_helper import get_ecoledirecte_session, getHomework, getNotes | ||
|
||
from .const import ( | ||
DEFAULT_REFRESH_INTERVAL, | ||
) | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class EDDataUpdateCoordinator(TimestampDataUpdateCoordinator): | ||
"""Data update coordinator for the Ecole Directe integration.""" | ||
|
||
config_entry: ConfigEntry | ||
|
||
def __init__( | ||
self, hass: HomeAssistant, entry: ConfigEntry | ||
) -> None: | ||
def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None: | ||
"""Initialize the coordinator.""" | ||
super().__init__( | ||
hass=hass, | ||
logger=_LOGGER, | ||
name=entry.title, | ||
update_interval=timedelta(minutes=entry.options.get("refresh_interval", DEFAULT_REFRESH_INTERVAL)), | ||
update_interval=timedelta( | ||
minutes=entry.options.get("refresh_interval", DEFAULT_REFRESH_INTERVAL) | ||
), | ||
) | ||
self.config_entry = entry | ||
|
||
async def _async_update_data(self) -> dict[Platform, dict[str, Any]]: | ||
"""Get the latest data from Ecole Directe and updates the state.""" | ||
|
||
data = self.config_entry.data | ||
self.data = { | ||
"account_type": data['account_type'], | ||
} | ||
|
||
session = await self.hass.async_add_executor_job(get_ecoledirecte_session, data) | ||
|
||
if session is None: | ||
_LOGGER.error('Unable to init ecole directe client') | ||
_LOGGER.error("Unable to init ecole directe client") | ||
return None | ||
|
||
self.data['session'] = session | ||
self.data = {} | ||
self.data["session"] = session | ||
|
||
currentYear = datetime.datetime.now().year | ||
if (currentYear % 2) == 0: | ||
yearData = f"{str(currentYear-1)}-{str(currentYear)}" | ||
else: | ||
yearData = f"{str(currentYear)}-{str(currentYear + 1)}" | ||
|
||
if (data['account_type'] == 'famille'): | ||
try: | ||
self.data['messages'] = await self.hass.async_add_executor_job(getMessages, session, None, None) | ||
except Exception as ex: | ||
self.data['messages'] = None | ||
_LOGGER.warning("Error getting messages for family from ecole directe: %s", ex) | ||
# if (session.typeCompte == '1'): # famille | ||
# if "MESSAGERIE" in session.modules: | ||
# try: | ||
# self.data['messages'] = await self.hass.async_add_executor_job(getMessages, session, None, yearData) | ||
# except Exception as 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['homework'+ eleve.eleve_id] = await self.hass.async_add_executor_job(getHomework, session, eleve) | ||
self.data[ | ||
"homework" + eleve.get_fullnameLower() | ||
] = await self.hass.async_add_executor_job( | ||
getHomework, session, eleve | ||
) | ||
except Exception as ex: | ||
_LOGGER.warning("Error getting homework from ecole directe: %s", ex) | ||
if "NOTES" in eleve.modules: | ||
try: | ||
self.data['notes'+ eleve.eleve_id] = await self.hass.async_add_executor_job(getNotes, session, eleve) | ||
except Exception as ex: | ||
_LOGGER.warning("Error getting notes from ecole directe: %s", ex) | ||
if "MESSAGERIE" in eleve.modules: | ||
try: | ||
self.data['notes'+ eleve.eleve_id] = await self.hass.async_add_executor_job(getMessages, session, eleve, None) | ||
self.data[ | ||
"notes" + eleve.get_fullnameLower() | ||
] = await self.hass.async_add_executor_job( | ||
getNotes, session, eleve, yearData | ||
) | ||
except Exception as ex: | ||
_LOGGER.warning("Error getting notes from ecole directe: %s", ex) | ||
# if "MESSAGERIE" in eleve.modules: | ||
# try: | ||
# self.data['messages'+ eleve.eleve_id] = await self.hass.async_add_executor_job(getMessages, session, eleve, yearData) | ||
# except Exception as ex: | ||
# _LOGGER.warning("Error getting notes from ecole directe: %s", ex) | ||
|
||
return self.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Data Formatter for the Ecole Directe integration.""" | ||
|
||
import logging | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def format_homework(homework) -> dict: | ||
return None # TODO | ||
|
||
|
||
def format_note(note) -> dict: | ||
return None # TODO |
Oops, something went wrong.