Browse Source

Read devices from a yaml file.

HashMap representation uses strings for index; u8 would be
better but somehow config-rs does not parse the Map correctly
(no error but shows empty map).
master
flabbergast 4 years ago
parent
commit
bc50d5f10f
  1. 27
      jee_config.yml
  2. 20
      src/main.rs

27
jee_config.yml

@ -0,0 +1,27 @@
devices:
"17":
id: 17
name: "bedroom/node/high/"
dev_type:
type: "TempHumBattV2"
"18":
id: 18
name: "garage/node/low/"
dev_type:
type: "TempBattV1"
"19":
id: 19
name: "kitchen/node/low/"
dev_type:
type: "TempBattV2"
"20":
id: 20
name: "conservatory/node/low/"
dev_type:
type: "TempHumLuxBattV1"
"21":
id: 21
name: "outside/node/front/"
dev_type:
type: "TempHumBattV1"

20
src/main.rs

@ -5,6 +5,7 @@
#[macro_use] extern crate error_chain;
#[macro_use] extern crate log;
extern crate loggerv;
extern crate config;
extern crate bus;
extern crate rand;
@ -112,22 +113,9 @@ quick_main!(|| -> Result<()> {
csv_enabled: matches.is_present("enable_csv"),
};
let mut node_list: HashMap<String,decode_jee::DeviceDesc> = HashMap::new();
node_list.insert("17".to_string(),
decode_jee::DeviceDesc { id: 17, name: "bedroom/node/high/".to_string(),
dev_type: decode_jee::DeviceType::TempHumBattV2 });
node_list.insert("18".to_string(),
decode_jee::DeviceDesc { id: 18, name: "garage/node/low/".to_string(),
dev_type: decode_jee::DeviceType::TempBattV1 });
node_list.insert("19".to_string(),
decode_jee::DeviceDesc { id: 19, name: "kitchen/node/low/".to_string(),
dev_type: decode_jee::DeviceType::TempBattV2 });
node_list.insert("20".to_string(),
decode_jee::DeviceDesc { id: 20, name: "conservatory/node/low/".to_string(),
dev_type: decode_jee::DeviceType::TempHumLuxBattV1 });
node_list.insert("21".to_string(),
decode_jee::DeviceDesc { id: 21, name: "outside/node/front/".to_string(),
dev_type: decode_jee::DeviceType::TempHumBattV1 });
let mut settings = config::Config::default();
settings.merge(config::File::with_name("jee_config.yml")).unwrap(); // TODO
let node_list = settings.get::<HashMap<String,decode_jee::DeviceDesc>>("devices").unwrap();
// initialise logger

Loading…
Cancel
Save