pub struct HassClient { /* private fields */ }
Expand description
HassClient is a library that is meant to simplify the conversation with HomeAssistant Web Socket Server it provides a number of convenient functions that creates the requests and read the messages from server
Implementations§
Source§impl HassClient
impl HassClient
pub async fn new(url: &str) -> HassResult<Self>
Sourcepub async fn auth_with_longlivedtoken(&mut self, token: &str) -> HassResult<()>
pub async fn auth_with_longlivedtoken(&mut self, token: &str) -> HassResult<()>
authenticate the session using a long-lived access token
When a client connects to the server, the server sends out auth_required. The first message from the client should be an auth message. You can authorize with an access token. If the client supplies valid authentication, the authentication phase will complete by the server sending the auth_ok message. If the data is incorrect, the server will reply with auth_invalid message and disconnect the session.
Sourcepub async fn ping(&mut self) -> HassResult<()>
pub async fn ping(&mut self) -> HassResult<()>
The API supports receiving a ping from the client and returning a pong. This serves as a heartbeat to ensure the connection is still alive.
Sourcepub async fn get_config(&mut self) -> HassResult<HassConfig>
pub async fn get_config(&mut self) -> HassResult<HassConfig>
This will get the current config of the Home Assistant.
The server will respond with a result message containing the config.
Sourcepub async fn get_states(&mut self) -> HassResult<Vec<HassEntity>>
pub async fn get_states(&mut self) -> HassResult<Vec<HassEntity>>
This will get all the current states from Home Assistant.
The server will respond with a result message containing the states.
Sourcepub async fn get_services(&mut self) -> HassResult<HassServices>
pub async fn get_services(&mut self) -> HassResult<HassServices>
This will get all the services from Home Assistant.
The server will respond with a result message containing the services.
Sourcepub async fn get_panels(&mut self) -> HassResult<HassPanels>
pub async fn get_panels(&mut self) -> HassResult<HassPanels>
This will get all the registered panels from Home Assistant.
The server will respond with a result message containing the current registered panels.
Sourcepub async fn call_service(
&mut self,
domain: String,
service: String,
service_data: Option<Value>,
) -> HassResult<()>
pub async fn call_service( &mut self, domain: String, service: String, service_data: Option<Value>, ) -> HassResult<()>
This will call a service in Home Assistant. Right now there is no return value. The client can listen to state_changed events if it is interested in changed entities as a result of a service call.
The server will indicate with a message indicating that the service is done executing.
https://developers.home-assistant.io/docs/api/websocket#calling-a-service
additional info : https://developers.home-assistant.io/docs/api/rest ==> Post /api/services/<domain>/<service>
Sourcepub async fn subscribe_event(
&mut self,
event_name: &str,
) -> HassResult<Receiver<WSEvent>>
pub async fn subscribe_event( &mut self, event_name: &str, ) -> HassResult<Receiver<WSEvent>>
The command subscribe_event will subscribe your client to the event bus.
Returns a channel that will receive the subscription messages.