pub struct Client { /* private fields */ }
Implementations§
Source§impl Client
An aynchronous client for Sonoff mini R3 API
impl Client
An aynchronous client for Sonoff mini R3 API
For more details look at the official docs: https://sonoff.tech/sonoff-diy-developer-documentation-minir3-http-api/
Sourcepub fn new<H: Into<String>>(host: H, port: u16) -> Self
pub fn new<H: Into<String>>(host: H, port: u16) -> Self
Constructs a new Client
with given host and port
§Example
let client = Client::new("192.168.1.75", 8081);
Sourcepub async fn fetch_info(&self) -> Result<Info>
pub async fn fetch_info(&self) -> Result<Info>
Fetch device info.
In current implementation it always uses /zeroconf/info
API and returns limited info. For
more details take a look at Info
struct.
§Example
let got = client.fetch_info().await;
assert!(got.is_ok());
assert_eq!(
got.unwrap(),
Info {
switch: SwitchPosition::Off,
startup: StartupPosition::Off
}
)
Sourcepub async fn set_startup_position(
&self,
position: StartupPosition,
) -> Result<()>
pub async fn set_startup_position( &self, position: StartupPosition, ) -> Result<()>
Set startup position for device.
It uses /zeroconf/startups
API and always sets given position only for outlet 0.
Other outlets will be set to off
on every call, because API doesn’t allow to specify
state for one outlet only.
§Example
let got = client.set_startup_position(StartupPosition::Stay).await;
assert!(got.is_ok());
Sourcepub async fn set_switch_position(&self, position: SwitchPosition) -> Result<()>
pub async fn set_switch_position(&self, position: SwitchPosition) -> Result<()>
Set switch position.
Is uses /zeroconf/switches
API and always sets given position for outlet 0 only. This API
allows to ignore state of another outlets, so they will be ignored.
§Example
let got = client.set_switch_position(SwitchPosition::On).await;
assert!(got.is_err());
assert_eq!(
got.unwrap_err().downcast::<Error>().unwrap(),
Error::WrongParameters
)