Skip to content

Commit

Permalink
Update API version and fix message sensor for multiple students
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoni-Czaplicki committed Apr 11, 2024
1 parent ae01480 commit 2cb113d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
37 changes: 19 additions & 18 deletions custom_components/vulcan/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/vulcan/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 2cb113d

Please sign in to comment.