Struct HassClient

Source
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

Source

pub async fn new(url: &str) -> HassResult<Self>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V