Compare commits
No commits in common. "b4dedb3728fa5f67e3b78e6c1b0ffe44208f8b3f" and "888c44834ab0e2d6f7c3e880caf3c46ad8f8a6b8" have entirely different histories.
b4dedb3728
...
888c44834a
@ -5,7 +5,7 @@ Work in progress.
|
|||||||
## Features and Todo
|
## Features and Todo
|
||||||
|
|
||||||
- Authn/z
|
- Authn/z
|
||||||
- [x] Authentication and token retrieval
|
- [x] Token authentication
|
||||||
- [ ] Persistence of tokens
|
- [ ] Persistence of tokens
|
||||||
- Core functionality
|
- Core functionality
|
||||||
- [x] Enumerate sites and chargers
|
- [x] Enumerate sites and chargers
|
||||||
@ -13,12 +13,9 @@ Work in progress.
|
|||||||
- [x] Read charger status
|
- [x] Read charger status
|
||||||
- [ ] Control charging (start/pause/resume/stop)
|
- [ ] Control charging (start/pause/resume/stop)
|
||||||
- [ ] Control dynamic current limits
|
- [ ] Control dynamic current limits
|
||||||
- Event stream
|
- [ ] Websocket event stream
|
||||||
- [x] Websocket connection (raw SignalR messages)
|
|
||||||
- [ ] Event decoding
|
|
||||||
- Ergonomics
|
- Ergonomics
|
||||||
- [ ] Enums for protocol constants
|
- [ ] Enums for protocol constants
|
||||||
- [ ] Proper SignalR support with Tokio
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
23
src/api.rs
23
src/api.rs
@ -411,27 +411,4 @@ impl Charger {
|
|||||||
pub fn latest_session(&self, ctx: &mut Context) -> Result<Option<ChargingSession>, ApiError> {
|
pub fn latest_session(&self, ctx: &mut Context) -> Result<Option<ChargingSession>, ApiError> {
|
||||||
ctx.maybe_get(&format!("chargers/{}/sessions/latest", &self.id))
|
ctx.maybe_get(&format!("chargers/{}/sessions/latest", &self.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn command(&self, ctx: &mut Context, command: &str) -> Result<(), ApiError> {
|
|
||||||
ctx.post(&format!("chargers/{}/commands/{}", self.id, command), &())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start(&self, ctx: &mut Context) -> Result<(), ApiError> {
|
|
||||||
self.command(ctx, "start_charging")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn pause(&self, ctx: &mut Context) -> Result<(), ApiError> {
|
|
||||||
self.command(ctx, "pause_charging")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn resume(&self, ctx: &mut Context) -> Result<(), ApiError> {
|
|
||||||
self.command(ctx, "resume_charging")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn stop(&self, ctx: &mut Context) -> Result<(), ApiError> {
|
|
||||||
self.command(ctx, "stop_charging")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ pub enum RecvError {
|
|||||||
#[error("Bad message type")]
|
#[error("Bad message type")]
|
||||||
BadMessageType,
|
BadMessageType,
|
||||||
|
|
||||||
|
#[error("Not a SignalR message: {0:?}")]
|
||||||
|
NotSignalRMessage(String),
|
||||||
|
|
||||||
#[error("Invalid json: {0}")]
|
#[error("Invalid json: {0}")]
|
||||||
InvalidJson(#[from] serde_json::Error),
|
InvalidJson(#[from] serde_json::Error),
|
||||||
|
|
||||||
@ -38,9 +41,7 @@ pub enum RecvError {
|
|||||||
TungsteniteError(#[from] tungstenite::Error),
|
TungsteniteError(#[from] tungstenite::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Stream {
|
pub struct Stream { sock: WebSocket<MaybeTlsStream<TcpStream>> }
|
||||||
sock: WebSocket<MaybeTlsStream<TcpStream>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Stream {
|
impl Stream {
|
||||||
pub fn open(ctx: &mut Context) -> Result<Stream, NegotiateError> {
|
pub fn open(ctx: &mut Context) -> Result<Stream, NegotiateError> {
|
||||||
@ -87,15 +88,15 @@ impl Stream {
|
|||||||
self.sock.send(Message::Text(msg))
|
self.sock.send(Message::Text(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recv(&mut self) -> Result<Vec<serde_json::Value>, RecvError> {
|
pub fn recv(&mut self) -> Result<serde_json::Value, RecvError> {
|
||||||
let msg = self.sock.read()?;
|
let msg = self.sock.read()?;
|
||||||
let Message::Text(txt) = msg else { return Err(RecvError::BadMessageType) };
|
let Message::Text(txt) = msg else { return Err(RecvError::BadMessageType) };
|
||||||
|
let json: &str = match txt.strip_suffix("\x1E") {
|
||||||
let msgs = txt.split_terminator('\x1E')
|
None => return Err(RecvError::NotSignalRMessage(txt)),
|
||||||
.filter_map(|s| serde_json::from_str(s).ok())
|
Some(json) => json
|
||||||
.collect();
|
};
|
||||||
|
dbg!(&json);
|
||||||
Ok(msgs)
|
Ok(serde_json::from_str(json)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscribe(&mut self, id: &str) -> Result<(), tungstenite::Error> {
|
pub fn subscribe(&mut self, id: &str) -> Result<(), tungstenite::Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user