new_home_application/lib.rs
1//! # New Home Application
2//!
3//! This is the New Home Application framework used to create application for the New Home project.
4//! The New Home project aims to make a Smart Home (more or less) simple for people who are willing
5//! to tinker a bit around with electronics and software (Or knows someone who is).
6//!
7//! For a more detailed description on what this project exactly is, for who it is and how to setup
8//! a "New Home" follow the documentation in the [main project](https://gitlab.com/y_software/new-home-core)
9//!
10//! # Usage
11//!
12//! To implement a [Method](new_home_application::method::Method) it is recommended to use the
13//! new_home_application_macro crate.
14//!
15//! To get the whole application up and running you will have to build the application using the
16//! [ApplicationBuilder](new_home_application::app::ApplicationBuilder). This will help you configure
17//! the application and get it running. For a more detailed implementation on how to use the builder
18//! you can take a look into the examples/example-application.rs file.
19//!
20//! # Implementation
21//!
22//! In order to be fully complient with the New Home system and especially with the Core and UI, you
23//! will have to create implement some methods. These methods are:
24//!
25//! | Name | Scope | Description |
26//! |-----------------|-------|---------------------------------------------------------------------------------------------------------|
27//! | `get_script` | Core | Provides a JavaScript file. Has to be in the `message.script` key. |
28//! | `device_action` | UI | Provides the info on what should happen when clicking on the device button in the room/device overview. |
29//! | `config_root` | UI | Provides the info on what should happen when the application button is clicked. |
30//!
31//! # Examples
32//!
33//! An example on how to implement a method with the macro is in the new_home_application_macro crate.
34//!
35//! An example on how to implement the same structure is in the examples/example-method.rs
36//!
37//! The short version (without the main part) is also here:
38//!
39//! ```rust
40//! use serde_json::Value;
41//! use new_home_application::method::{MethodCallable, Method, MethodError};
42//! use new_home_application::communication::{MethodCall, MethodResult};
43//! use std::collections::HashMap;
44//!
45//! struct ExampleMethod {
46//! pub word: Value,
47//!
48//! pub uppercase: Value,
49//! }
50//!
51//! impl Method for ExampleMethod {
52//! fn name(&self) -> String {
53//! String::from(r#"example_method"#)
54//! }
55//!
56//! fn description(&self) -> String {
57//! String::from(r#"Can convert a word into uppercase"#)
58//! }
59//!
60//! fn help(&self) -> String {
61//! String::from(r#"Will convert the word to uppercase if uppercase flag is set"#)
62//! }
63//!
64//! fn set_arguments(
65//! &mut self,
66//! arguments: HashMap<String, Value>,
67//! ) -> Result<(), MethodError> {
68//! match arguments.get("word") {
69//! Some(value) => {
70//! self.word = value.clone();
71//! }
72//! _ => {
73//! return Err(MethodError::message(
74//! "Missing value for word",
75//! ));
76//! }
77//! }
78//! self.uppercase = arguments
79//! .get("uppercase")
80//! .unwrap_or(&serde_json::Value::from(false))
81//! .clone();
82//! Ok(())
83//! }
84//! }
85//!
86//! impl MethodCallable for ExampleMethod {
87//! fn call(&mut self, _: MethodCall) -> MethodResult {
88//! unimplemented!()
89//! }
90//! }
91//! ```
92//!
93//! This is the same example the derived (macro) one and by that I mean, that this is the
94//! `cargo expand` result.
95//!
96
97extern crate serde;
98#[macro_use]
99extern crate serde_json;
100
101pub mod app;
102pub mod communication;
103pub mod method;