aboutsummaryrefslogtreecommitdiff
path: root/src/entity_button.rs
diff options
context:
space:
mode:
authordiogo464 <[email protected]>2025-12-05 12:17:01 +0000
committerdiogo464 <[email protected]>2025-12-05 12:17:01 +0000
commit0c86da392af50c7588b087c3f72602e8368af65e (patch)
tree894cd2f353298b83a56cde06eafd7b1e366aa6b3 /src/entity_button.rs
parent1d2ee64d0ec917a2c2b66f8d58e1f37dd174a89d (diff)
reworked entity creation
Diffstat (limited to 'src/entity_button.rs')
-rw-r--r--src/entity_button.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/entity_button.rs b/src/entity_button.rs
new file mode 100644
index 0000000..baa89a4
--- /dev/null
+++ b/src/entity_button.rs
@@ -0,0 +1,41 @@
1use crate::{Entity, EntityCommonConfig, EntityConfig, constants};
2
3#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
4pub enum ButtonClass {
5 #[default]
6 Generic,
7 Identify,
8 Restart,
9 Update,
10}
11
12#[derive(Debug, Default)]
13pub struct ButtonConfig {
14 pub common: EntityCommonConfig,
15 pub class: ButtonClass,
16}
17
18impl ButtonConfig {
19 pub(crate) fn populate(&self, config: &mut EntityConfig) {
20 self.common.populate(config);
21 config.domain = constants::HA_DOMAIN_BUTTON;
22 config.device_class = match self.class {
23 ButtonClass::Generic => None,
24 ButtonClass::Identify => Some(constants::HA_DEVICE_CLASS_BUTTON_IDENTIFY),
25 ButtonClass::Restart => Some(constants::HA_DEVICE_CLASS_BUTTON_RESTART),
26 ButtonClass::Update => Some(constants::HA_DEVICE_CLASS_BUTTON_UPDATE),
27 };
28 }
29}
30
31pub struct Button<'a>(Entity<'a>);
32
33impl<'a> Button<'a> {
34 pub(crate) fn new(entity: Entity<'a>) -> Self {
35 Self(entity)
36 }
37
38 pub async fn pressed(&mut self) {
39 self.0.wait_command().await;
40 }
41}