From 2cb113df37ed45511d5d5b92348951c5e06ac449 Mon Sep 17 00:00:00 2001 From: Antoni-Czaplicki <56671347+Antoni-Czaplicki@users.noreply.github.com> Date: Thu, 11 Apr 2024 14:11:02 +0200 Subject: [PATCH] Update API version and fix message sensor for multiple students --- custom_components/vulcan/fetch_data.py | 37 +++++++++++++------------- custom_components/vulcan/manifest.json | 4 +-- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/custom_components/vulcan/fetch_data.py b/custom_components/vulcan/fetch_data.py index f89791c..de7dda7 100644 --- a/custom_components/vulcan/fetch_data.py +++ b/custom_components/vulcan/fetch_data.py @@ -296,24 +296,25 @@ async def get_latest_message(client): """ latest_message: dict[str, int | str] = {"timestamp": 0} - async for messagebox in await client.data.get_message_boxes(): - async for message in await client.data.get_messages(messagebox.global_key): - if message.sent_date.timestamp > latest_message["timestamp"]: - latest_message["id"] = message.id - latest_message["title"] = message.subject - latest_message["content"] = re.sub( - re.compile("<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});"), - "", - message.content, - ) - if message.sender is not None: - latest_message["sender"] = message.sender.name - else: - latest_message["sender"] = "Nieznany" - latest_message["date"] = ( - f"{message.sent_date.time.strftime('%H:%M')} {message.sent_date.date.strftime('%d.%m.%Y')}" - ) - latest_message["timestamp"] = message.sent_date.timestamp + async for message in await client.data.get_messages( + client.student.message_box.global_key + ): + if message.sent_date.timestamp > latest_message["timestamp"]: + latest_message["id"] = message.id + latest_message["title"] = message.subject + latest_message["content"] = re.sub( + re.compile("<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});"), + "", + message.content, + ) + if message.sender is not None: + latest_message["sender"] = message.sender.name + else: + latest_message["sender"] = "Nieznany" + latest_message["date"] = ( + f"{message.sent_date.time.strftime('%H:%M')} {message.sent_date.date.strftime('%d.%m.%Y')}" + ) + latest_message["timestamp"] = message.sent_date.timestamp if not latest_message: latest_message = { "id": 0, diff --git a/custom_components/vulcan/manifest.json b/custom_components/vulcan/manifest.json index c9a4229..03355ad 100644 --- a/custom_components/vulcan/manifest.json +++ b/custom_components/vulcan/manifest.json @@ -7,6 +7,6 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/Antoni-Czaplicki/vulcan-for-hassio/issues", "quality_scale": "silver", - "requirements": ["vulcan-api==2.3.2"], - "version": "0.16.0" + "requirements": ["vulcan-api==2.4.0"], + "version": "0.16.1" }