add: receive more controller properties and save them

add: more tests
This commit is contained in:
Tobias Reisinger 2020-03-12 00:36:06 +01:00
parent 2a4e0e1075
commit 2b9abff7f1
3 changed files with 29 additions and 12 deletions

View file

@ -106,16 +106,10 @@ void controllers::post_discover(const HttpRequestPtr &req, std::function<void(co
uuid_t discovered_id; uuid_t discovered_id;
int id_size = sizeof(uuid_t); int id_size = sizeof(uuid_t);
memcpy(&discovered_id, binn_map_blob(answer_payload, DISCOVERY_MAPPING_ID, &id_size), id_size); memcpy(&discovered_id, binn_map_blob(answer_payload, DISCOVERY_MAPPING_ID, &id_size), id_size);
//strncpy(&id, binn_map_blob(answer_payload, DISCOVERY_MAPPING_ID, &uuid_size), uuid_size);
char uuid_str[38]; char *discovered_name = binn_map_str(answer_payload, DISCOVERY_MAPPING_NAME);
uuid_unparse(discovered_id, uuid_str); uint32_t discovered_command_port = binn_map_uint32(answer_payload, DISCOVERY_MAPPING_COMMAND_PORT);
LOG_DEBUG << uuid_str; uint8_t discovered_relay_count = binn_map_uint8(answer_payload, DISCOVERY_MAPPING_RELAY_COUNT);
continue;
free(answer_payload);
Json::Value client_info;
bool found_discovered_in_list = false; bool found_discovered_in_list = false;
@ -143,13 +137,14 @@ void controllers::post_discover(const HttpRequestPtr &req, std::function<void(co
controller_dbo discovered_controller{}; controller_dbo discovered_controller{};
strcpy(discovered_controller.ip, inet_ntoa(addr.sin_addr)); strcpy(discovered_controller.ip, inet_ntoa(addr.sin_addr));
memcpy(discovered_controller.id, discovered_id, sizeof(uuid_t)); memcpy(discovered_controller.id, discovered_id, sizeof(uuid_t));
strcpy(discovered_controller.name, client_info["name"].asCString()); strcpy(discovered_controller.name, discovered_name);
discovered_controller.relay_count = client_info["relay_count"].asInt(); discovered_controller.relay_count = discovered_relay_count;
discovered_controller.port = client_info["port"].asInt(); discovered_controller.port = discovered_command_port;
discovered_controller.active = true; discovered_controller.active = true;
discovered_controller.insert(); discovered_controller.insert();
} }
free(answer_payload);
discover_answer_buf[0] = config::discover_code_accept; discover_answer_buf[0] = config::discover_code_accept;
send(client_fd, discover_answer_buf, sizeof(uint8_t), 0); send(client_fd, discover_answer_buf, sizeof(uint8_t), 0);

View file

@ -12,6 +12,7 @@ create table controllers
ip VARCHAR(16), ip VARCHAR(16),
port INTEGER, port INTEGER,
relay_count INTEGER, relay_count INTEGER,
tag varchar(64),
active BOOLEAN not null active BOOLEAN not null
); );

View file

@ -43,3 +43,24 @@ stages:
url: "http://localhost:5000/api/v1/schedules/on" url: "http://localhost:5000/api/v1/schedules/on"
response: response:
status_code: 200 status_code: 200
body:
name: "on"
periods:
- start: "00:00"
end: "23:59"
- name: overwrite protected on schedule
request:
method: PUT
url: "http://localhost:5000/api/v1/schedules/on"
json:
name: "turned_on"
periods:
- start: '00:10'
end: '00:20'
response:
status_code: 200
body:
name: "{tavern.request_vars.json.name}"
periods:
- start: "00:00"
end: "23:59"