-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
429 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
/.vscode | ||
/.embuild | ||
/target | ||
/Cargo.lock | ||
target/ | ||
|
||
/config.yml | ||
/ota.bin | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "hass-types" | ||
version = "0.1.0" | ||
authors = ["akosnad"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
heapless = { version = "0.8.0", features = ["serde"] } | ||
serde = { version = "1.0.215", default-features = false, features = ["derive", "alloc"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#![no_std] | ||
|
||
use alloc::{format, string::String}; | ||
use heapless::Vec; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
extern crate alloc; | ||
|
||
pub const DISCOVERY_PREFIX: &str = "homeassistant"; | ||
|
||
pub trait Discoverable { | ||
fn discovery_topic(&self) -> Topic; | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Deserialize, Serialize, Default)] | ||
pub enum AvailabilityMode { | ||
#[serde(rename = "all")] | ||
All, | ||
#[serde(rename = "any")] | ||
Any, | ||
#[default] | ||
#[serde(rename = "latest")] | ||
Latest, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Availability { | ||
pub payload_available: Option<String>, | ||
pub payload_not_available: Option<String>, | ||
pub topic: String, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Device { | ||
pub hw_version: Option<String>, | ||
pub sw_version: Option<String>, | ||
pub name: Option<String>, | ||
pub identifiers: Vec<String, 5>, | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct UniqueId(pub String); | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct Topic(pub String); | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize)] | ||
pub struct DeviceTracker { | ||
/// Only first availability is used by us, the rest are ignored. | ||
pub availability: Vec<Availability, 5>, | ||
pub availability_mode: Option<AvailabilityMode>, | ||
pub device: Option<Device>, | ||
pub unique_id: UniqueId, | ||
pub name: String, | ||
pub json_attributes_topic: Topic, | ||
} | ||
impl Discoverable for DeviceTracker { | ||
fn discovery_topic(&self) -> Topic { | ||
Topic(format!( | ||
"{}/device_tracker/{}/config", | ||
DISCOVERY_PREFIX, self.unique_id.0 | ||
)) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, Serialize)] | ||
pub struct DeviceTrackerAttributes { | ||
pub longitude: f64, | ||
pub latitude: f64, | ||
pub gps_accuracy: Option<f64>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use alloc::vec; | ||
use embassy_sync::once_lock::OnceLock; | ||
use hass_types::*; | ||
|
||
static CONFIG: OnceLock<SystemConfig> = OnceLock::new(); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct SystemConfig { | ||
pub device_tracker: DeviceTracker, | ||
} | ||
impl SystemConfig { | ||
pub fn get() -> &'static Self { | ||
CONFIG.get_or_init(|| Self { | ||
device_tracker: include!(concat!(env!("OUT_DIR"), "/device_tracker_config.rs")), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.