Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send status to mattermost #17

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
110 changes: 110 additions & 0 deletions software/raspberrypi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions software/raspberrypi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[workspace]
resolver = "2"
members = [
"backend",
"hardware",
]
members = ["backend", "hardware"]

[profile.release]
lto = true
Expand Down
9 changes: 8 additions & 1 deletion software/raspberrypi/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ shadow-rs = "0.38"

[dev-dependencies]
pretty_assertions = "1"
tokio = { version = "1", features = ["rt", "macros"] }
fake = "3"
secrecy = "0.10"
wiremock = "0.6"

[dependencies]
hardware = { path = "../hardware" }
Expand All @@ -29,6 +33,7 @@ tracing-oslog = "0.2"
tracing-journald = "0.3"
directories-next = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
anyhow = "1"
thiserror = "2"
rust-embed = "8"
Expand All @@ -42,7 +47,9 @@ poem = { version = "3", features = [
] }
reqwest = { version = "0.12", default-features = false, features = [
"rustls-tls",
"json",
] }
reqwest-retry = "0.7"
reqwest-middleware = "0.4"
reqwest-middleware = { version = "0.4", features = ["json"] }
reqwest-tracing = "0.5"
secrecy = { version = "0.10", features = ["serde"] }
52 changes: 52 additions & 0 deletions software/raspberrypi/backend/python/mattermost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python

import sys

from mattermostdriver import Driver


def main(*args):
print(args)

url = args[0][0]
login_id = args[0][1]
api_token = args[0][2]
scheme = args[0][3]
port = args[0][4]
state = args[0][5]

driver = Driver(
{
"url": url,
"login_id": login_id,
"token": api_token,
"scheme": scheme,
"port": int(port),
}
)
driver.login()

team = driver.teams.get_team_by_name("section77")
channel = driver.channels.get_channel_by_name(team["id"], "clubstatus")

message = ""
name = ""
if state == "true":
message = "Die Section77 ist offen"
name = "Status: Offen"
elif state == "false":
message = "Die Section77 ist geschlossen"
name = "Status: Geschlossen"

# send message
_post = driver.posts.create_post({"channel_id": channel["id"], "message": message})
# update room name
driver.channels.patch_channel(
channel["id"], {"id": channel["id"], "display_name": name}
)

driver.logout()


if __name__ == "__main__":
main(sys.argv[1:])
13 changes: 4 additions & 9 deletions software/raspberrypi/backend/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use anyhow::Result;
use config::{Config, ConfigError, Environment, File};
use directories_next::ProjectDirs;
use secrecy::SecretString;
use serde::Deserialize;

use hardware::{doorswitch, lock, lockswitch};

use crate::{mattermost::configuration::MatterMost, spaceapi::configuration::SpaceAPI};

pub type ConfigurationRef = &'static Configuration;

#[derive(Debug, Clone, Copy, Deserialize)]
Expand All @@ -14,20 +15,14 @@ pub struct Server {
pub port: u16,
}

#[derive(Debug, Clone, Deserialize)]
pub struct SpaceAPI {
pub enable: bool,
pub url: String,
pub username: String,
pub password: SecretString,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Configuration {
pub server: Server,

pub spaceapi: SpaceAPI,

pub mattermost: MatterMost,

// hardware
pub lockmotor: lock::Configuration,
pub lockswitch: lockswitch::Configuration,
Expand Down
2 changes: 2 additions & 0 deletions software/raspberrypi/backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
pub mod configuration;
mod handlers;
mod logic;
mod mattermost;
mod notifyer;
mod spaceapi;

use anyhow::Result;
use poem::{
Expand Down
Loading