Update README.md, fix MQTT auth, fix battery status reporting
This commit is contained in:
parent
736808931a
commit
59d21b3fe4
3 changed files with 27 additions and 8 deletions
|
@ -7,7 +7,7 @@
|
|||
- [x] Command buttons
|
||||
- [x] Notifications
|
||||
- [x] Actions
|
||||
- [x] System information reporting (CPU usage, battery status, …)
|
||||
- [x] System information reporting (CPU usage, RAM usage, battery status)
|
||||
- [ ] Media control (MPRIS)
|
||||
- [ ] PipeWire control
|
||||
- [ ] File watcher
|
||||
|
@ -51,6 +51,9 @@ display_name = "My PC"
|
|||
host = "127.0.0.1" # You probably need to change this
|
||||
port = 1883
|
||||
|
||||
# You can remove the following line if your MQTT broker allows unauthenticated access
|
||||
credentials = { user = "user", password = "password" }
|
||||
|
||||
[modules.buttons]
|
||||
enabled = true
|
||||
|
||||
|
|
|
@ -43,8 +43,10 @@ pub async fn init(context: &mut InitializationContext) -> Result<()> {
|
|||
sub_id: "ram_usage",
|
||||
display_name: "RAM Usage",
|
||||
icon: "mdi:memory",
|
||||
suggested_precision: 0,
|
||||
suggested_precision: Some(0),
|
||||
unit: Some("%"),
|
||||
force_update: true,
|
||||
device_class: "None"
|
||||
},
|
||||
context,
|
||||
config.ram_usage,
|
||||
|
@ -63,8 +65,10 @@ pub async fn init(context: &mut InitializationContext) -> Result<()> {
|
|||
sub_id: "cpu_usage",
|
||||
display_name: "CPU Usage",
|
||||
icon: "mdi:memory",
|
||||
suggested_precision: 0,
|
||||
suggested_precision: Some(0),
|
||||
unit: Some("%"),
|
||||
force_update: true,
|
||||
device_class: "None"
|
||||
},
|
||||
context,
|
||||
config.cpu_usage,
|
||||
|
@ -106,8 +110,10 @@ pub async fn init(context: &mut InitializationContext) -> Result<()> {
|
|||
sub_id: "battery_level",
|
||||
display_name: "Battery Level",
|
||||
icon: "mdi:battery",
|
||||
suggested_precision: 0,
|
||||
suggested_precision: Some(0),
|
||||
unit: Some("%"),
|
||||
force_update: true,
|
||||
device_class: "battery"
|
||||
},
|
||||
context,
|
||||
config.battery,
|
||||
|
@ -120,8 +126,10 @@ pub async fn init(context: &mut InitializationContext) -> Result<()> {
|
|||
sub_id: "battery_state",
|
||||
display_name: "Battery State",
|
||||
icon: "mdi:battery",
|
||||
suggested_precision: 0,
|
||||
suggested_precision: None,
|
||||
unit: None,
|
||||
force_update: false,
|
||||
device_class: "enum"
|
||||
},
|
||||
context,
|
||||
config.battery,
|
||||
|
@ -140,8 +148,10 @@ struct InfoEntityOptions<'a> {
|
|||
sub_id: &'a str,
|
||||
display_name: &'a str,
|
||||
icon: &'a str,
|
||||
suggested_precision: u64,
|
||||
suggested_precision: Option<u64>,
|
||||
unit: Option<&'a str>,
|
||||
force_update: bool,
|
||||
device_class: &'a str
|
||||
}
|
||||
|
||||
async fn init_info_value(
|
||||
|
@ -167,10 +177,10 @@ async fn init_info_value(
|
|||
let mut object = json::object! {
|
||||
"availability_topic": context.full.mqtt.availability_topic.clone(),
|
||||
"device": context.full.mqtt.discovery_device_object.clone(),
|
||||
"force_update": true,
|
||||
"device_class": options.device_class,
|
||||
"force_update": options.force_update,
|
||||
"icon": options.icon,
|
||||
"name": options.display_name,
|
||||
"suggested_display_precision": options.suggested_precision,
|
||||
"state_class": "measurement",
|
||||
"state_topic": state_topic.as_str(),
|
||||
"object_id": entity_id.as_str(),
|
||||
|
@ -181,6 +191,10 @@ async fn init_info_value(
|
|||
object.insert("unit_of_measurement", unit).unwrap();
|
||||
}
|
||||
|
||||
if let Some(suggested_precision) = options.suggested_precision {
|
||||
object.insert("suggested_display_precision", suggested_precision).unwrap();
|
||||
}
|
||||
|
||||
object
|
||||
}),
|
||||
)
|
||||
|
|
|
@ -28,6 +28,8 @@ pub async fn create_client(config: &config::Config, machine_id: &str, availabili
|
|||
usize::MAX,
|
||||
);
|
||||
|
||||
config.mqtt.credentials.as_ref().map(|c| options.set_credentials(c.user.clone(), c.password.clone()));
|
||||
|
||||
let (mqtt_client, event_loop) = MqttClient::new(options, 30);
|
||||
Ok((mqtt_client, event_loop))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue