| Crates.io | hive-client |
| lib.rs | hive-client |
| version | 0.0.5 |
| created_at | 2025-04-17 00:14:35.175537+00 |
| updated_at | 2025-09-06 19:08:58.482452+00 |
| description | A Rust client for interfacing with Hive smart home systems. |
| homepage | https://ryanmaber.com |
| repository | https://github.com/ryanmab/hive-client |
| max_upload_size | |
| id | 1637080 |
| size | 200,781 |
The Hive Client crate provides a client for interfacing with Hive smart home systems.
[dependencies]
hive-client = "0.0.5"
More in-depth examples can be found in documentation comments on the Client methods.
use hive_client::authentication::{TrustedDevice, User};
let client = hive_client::Client::new("Home Automation");
let trusted_device = Some(TrustedDevice::new(
"device_password",
"device_group_key",
"device_key"
));
let attempt = client.login(User::new("example@example.com", "example"), trusted_device).await;
if let Ok(_) = attempt {
// Login was successful
let mut actions = client.get_actions()
.await
.expect("Quick action should be retrieved");
if let Some(mut first_action) = actions.first_mut() {
let was_activated = first_action.activate()
.await
.expect("Quick action should be activated");
}
}
use hive_client::authentication::{TrustedDevice, User};
use hive_client::products::{Product, ProductData, State, States};
let client = hive_client::Client::new("Home Automation");
let trusted_device = Some(TrustedDevice::new(
"device_password",
"device_group_key",
"device_key"
));
let attempt = client.login(User::new("example@example.com", "example"), trusted_device).await;
if let Ok(_) = attempt {
// Login was successful
let products = client.get_products()
.await
.expect("Products should be retrieved");
if let Some(mut heating) = products.into_iter().find(|Product { data, .. }| matches!(data, ProductData::Heating { .. })) {
let was_set = heating.set_state(States(vec!(State::TargetTemperature(18.0))))
.await
.expect("Product state should be set");
}
}
use hive_client::authentication::{TrustedDevice, User};
use hive_client::products::{Product, ProductData, State, States};
let client = hive_client::Client::new("Home Automation");
let trusted_device = Some(TrustedDevice::new(
"device_password",
"device_group_key",
"device_key"
));
let attempt = client.login(User::new("example@example.com", "example"), trusted_device).await;
if let Ok(_) = attempt {
// Login was successful
let postcode = "SW1A 1AA";
let weather = client.get_weather(postcode)
.await
.expect("Weather should be retrieved");
// Example: It is currently 18.0C with clear skies at Buckingham Palace
println!("It is currently {} with {} at Buckingham Palace", weather.data.temperature, weather.data.description);
}
There are tons of features which could be added to the crate. If you'd like to contribute, please feel free to open an issue or a pull request.
Examples of features which could be added:
Many of the tests require that an AWS Cognito User Pool, configured with SRP authentication and device tracking, be available to act as a mock server.
The setup of a suitable User Pool is fully automated with Terraform (see the infrastructure folder).
In order to setup the test environment, Terraform needs to be installed and AWS credentials need to be configured locally.
Once this is done, running apply should setup the Terraform backend, and the user pool and app client in the correct state:
# Setup state backend
cd infrastructure/state && terraform init && terraform apply
# Setup user pool
cd infrastructure/tests && terraform init --backend-config="./local.config" && terraform apply
After the user pool is set up, multiple environment variables need to be set in a .env file.
The .env file can be created by using .env.example as a template:
cp .env.example .env
The tests can be run with:
cargo test
The test environment can be torn down at any point with:
cd infrastructure/tests && terraform destroy