File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //! Tools for publishing a [Home Assistant button](https://www.home-assistant.io/integrations/button.mqtt/).
2+ use core:: ops:: Deref ;
3+
4+ use serde:: Serialize ;
5+
6+ use crate :: { homeassistant:: Component , Error , Topic } ;
7+
8+ /// The type of button.
9+ #[ derive( Serialize ) ]
10+ #[ serde( rename_all = "snake_case" ) ]
11+ #[ allow( missing_docs) ]
12+ pub enum ButtonClass {
13+ Identify ,
14+ Restart ,
15+ Update ,
16+ }
17+
18+ /// A button that can be pressed.
19+ #[ derive( Serialize ) ]
20+ pub struct Button {
21+ /// The type of button.
22+ pub device_class : Option < ButtonClass > ,
23+ }
24+
25+ impl Component for Button {
26+ type State = ( ) ;
27+
28+ fn platform ( ) -> & ' static str {
29+ "button"
30+ }
31+
32+ async fn publish_state < T : Deref < Target = str > > (
33+ & self ,
34+ _topic : & Topic < T > ,
35+ _state : Self :: State ,
36+ ) -> Result < ( ) , Error > {
37+ // Buttons don't have a state
38+ Err ( Error :: Invalid )
39+ }
40+ }
Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ use crate::{
5050} ;
5151
5252pub mod binary_sensor;
53+ pub mod button;
5354pub mod light;
5455pub mod sensor;
5556mod ser;
You can’t perform that action at this time.
0 commit comments