Skip to content

Commit

Permalink
fix notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Giga77 committed Mar 17, 2024
1 parent e95385a commit ce31855
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
45 changes: 28 additions & 17 deletions custom_components/ecole_directe/ecoleDirecte_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def getResponse(session, url, payload):
payload = "data={}"

_LOGGER.debug("URL: [%s] - Payload: [%s]", url, payload)
response = requests.post(url, data=payload, headers=getHeaders(token), timeout=60)
response = requests.post(url, data=payload, headers=getHeaders(token), timeout=120)

if "application/json" in response.headers.get("Content-Type", ""):
respJson = response.json()
Expand Down Expand Up @@ -341,42 +341,54 @@ def get_ecoledirecte_session(data) -> ED_Session | None:
return None


def getMessages(session, eleve, anneeScolaire):
if eleve is None:
return getResponse(
session,
f"{APIURL}/familles/{session.id}/messages.awp?force=false&typeRecuperation=received&idClasseur=0&orderBy=date&order=desc&query=&onlyRead=&page=0&itemsPerPage=100&getAll=0&verbe=get&v={APIVERSION}",
encodeBody({"data": {"anneeMessages": anneeScolaire}}),
)
return getResponse(
session,
f"{APIURL}/eleves/{eleve.eleve_id}/messages.awp?force=false&typeRecuperation=received&idClasseur=0&orderBy=date&order=desc&query=&onlyRead=&page=0&itemsPerPage=100&getAll=0&verbe=get&v={APIVERSION}",
encodeBody({"data": {"anneeMessages": anneeScolaire}}),
)
# def getMessages(session, eleve, anneeScolaire):
# if eleve is None:
# return getResponse(
# session,
# f"{APIURL}/familles/{session.id}/messages.awp?force=false&typeRecuperation=received&idClasseur=0&orderBy=date&order=desc&query=&onlyRead=&page=0&itemsPerPage=100&getAll=0&verbe=get&v={APIVERSION}",
# encodeBody({"data": {"anneeMessages": anneeScolaire}}),
# )
# return getResponse(
# session,
# f"{APIURL}/eleves/{eleve.eleve_id}/messages.awp?force=false&typeRecuperation=received&idClasseur=0&orderBy=date&order=desc&query=&onlyRead=&page=0&itemsPerPage=100&getAll=0&verbe=get&v={APIVERSION}",
# encodeBody({"data": {"anneeMessages": anneeScolaire}}),
# )


def getDevoirsByDate(session, eleve, date):
return getResponse(
json = getResponse(
session,
f"{APIURL}/eleves/{eleve.eleve_id}/cahierdetexte/{date}.awp?verbe=get&v={APIVERSION}",
None,
)
if "data" in json:
return json["data"]
_LOGGER.warning("getDevoirsByDate: [%s]", json)
return None


def getDevoirs(session, eleve):
return getResponse(
json = getResponse(
session,
f"{APIURL}/eleves/{eleve.eleve_id}/cahierdetexte.awp?verbe=get&v={APIVERSION}",
None,
)
if "data" in json:
return json["data"]
_LOGGER.warning("getDevoirs: [%s]", json)
return None


def getNotes(session, eleve, anneeScolaire):
return getResponse(
json = getResponse(
session,
f"{APIURL}/eleves/{eleve.eleve_id}/notes.awp?verbe=get&v={APIVERSION}",
encodeBody({"data": {"anneeScolaire": anneeScolaire}}),
)
if "data" in json:
return json["data"]
_LOGGER.warning("getNotes: [%s]", json)
return None


def getHeaders(token):
Expand Down Expand Up @@ -405,5 +417,4 @@ def getHeaders(token):
def isLogin(session):
if session.token is not None and session.id is not None:
return True

return False
2 changes: 1 addition & 1 deletion custom_components/ecole_directe/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"documentation": "https://github.com/hacf-fr/hass-ecoledirecte",
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/hacf-fr/hass-ecoledirecte/issues",
"version": "0.0.1"
"version": "0.0.6"
}
19 changes: 13 additions & 6 deletions custom_components/ecole_directe/sensor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from homeassistant.core import HomeAssistant
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand All @@ -17,6 +19,8 @@
NOTES_TO_DISPLAY,
)

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
Expand Down Expand Up @@ -147,9 +151,11 @@ def extra_state_attributes(self):
attributes = []
todo_counter = 0
if f"devoirs{self._child_info.get_fullnameLower()}" in self.coordinator.data:
for date in self.coordinator.data[
json = self.coordinator.data[
f"devoirs{self._child_info.get_fullnameLower()}"
]:
]
_LOGGER.debug("EDDevoirsSensor attributes json: [%s]", json)
for date in json:
for devoirs in date:
for devoir_json in devoirs:
devoir = ED_Devoir(devoir_json, date)
Expand Down Expand Up @@ -182,10 +188,11 @@ def __init__(self, coordinator: EDDataUpdateCoordinator, eleve: ED_Eleve) -> Non
def extra_state_attributes(self):
"""Return the state attributes."""
attributes = []
notes = self.coordinator.data["notes" + self._child_info.get_fullnameLower()]
json = self.coordinator.data["notes" + self._child_info.get_fullnameLower()]
index_note = 0
if notes is not None:
for note in notes:
if json is not None and "notes" in json:
_LOGGER.debug("EDNotesSensor attributes json: [%s]", json)
for note in json["notes"]:
index_note += 1
if index_note == NOTES_TO_DISPLAY:
break
Expand All @@ -194,5 +201,5 @@ def extra_state_attributes(self):

return {
"updated_at": self.coordinator.last_update_success_time,
"evaluations": attributes,
"notes": attributes,
}

0 comments on commit ce31855

Please sign in to comment.