finish rename ligths as outlets

This commit is contained in:
jbnadal
2018-05-07 11:43:07 +02:00
parent 7d8b653d08
commit 10bfa7ac93
6 changed files with 47 additions and 42 deletions

View File

@@ -13,28 +13,28 @@
{ {
"capabilities": [ "capabilities": [
{ {
"name": "lights", "name": "outlets",
"speach_name": "lumière" "speech_name": "lumière"
}, },
{ {
"name": "shutters", "name": "shutters",
"speach_name": "volet" "speech_name": "volet"
}, },
{ {
"name": "sprinklers", "name": "sprinklers",
"speach_name": "station" "speech_name": "station"
} }
] ]
} }
``` ```
## domo.lights ## domo.outlets
### create ### create
``` ```
./usr/bin/ubus call domo.lights create ./usr/bin/ubus call domo.outlets create "{\"name\":\"test\", \"sender\": 12797322, \"switch\": 4}"
``` ```
TODO TODO
@@ -42,38 +42,38 @@ TODO
### list ### list
``` ```
./usr/bin/ubus call domo.lights list ./usr/bin/ubus call domo.outlets list
``` ```
```json ```json
{ {
"lights": [ "outlets": [
{ {
"id": 1, "id": 1,
"name": "Bureau JB", "name": "Bureau JB",
"speach_name": "bureau", "speech_name": "bureau",
"zone": "", "zone": "",
"state": true, "state": true,
"sender": 12797322, "sender": 12797322,
"interruptor": 0 "switch": 0
}, },
{ {
"id": 2, "id": 2,
"name": "Salon", "name": "Salon",
"speach_name": "salon", "speech_name": "salon",
"zone": "", "zone": "",
"state": false, "state": false,
"sender": 12797322, "sender": 12797322,
"interruptor": 1 "switch": 1
}, },
{ {
"id": 3, "id": 3,
"name": "Sapin", "name": "Sapin",
"speach_name": "sapin", "speech_name": "sapin",
"zone": "", "zone": "",
"state": false, "state": false,
"sender": 12797322, "sender": 12797322,
"interruptor": 2 "switch": 2
} }
] ]
} }
@@ -82,25 +82,25 @@ TODO
### read ### read
``` ```
./usr/bin/ubus call domo.lights read "{\"id\":2}" ./usr/bin/ubus call domo.outlets read "{\"id\":2}"
``` ```
```json ```json
{ {
"id": 2, "id": 2,
"name": "Salon", "name": "Salon",
"speach_name": "salon", "speech_name": "salon",
"state": false, "state": false,
"zone": "", "zone": "",
"sender": 12797322, "sender": 12797322,
"interruptor": 1 "switch": 1
} }
``` ```
### update ### update
``` ```
./usr/bin/ubus call domo.lights update ./usr/bin/ubus call domo.outlets update
``` ```
TODO TODO
@@ -108,7 +108,7 @@ TODO
### delete ### delete
``` ```
./usr/bin/ubus call domo.lights delete ./usr/bin/ubus call domo.outlets delete
``` ```
TODO TODO

View File

@@ -36,7 +36,7 @@
* *
* @brief Constructor of the Device Collection. * @brief Constructor of the Device Collection.
*/ */
DeviceCollection::DeviceCollection(void) DeviceCollection::DeviceCollection(void) : m_max_id(0)
{ {
} }
@@ -67,6 +67,12 @@ Device *DeviceCollection::operator[](int a_pos)
int DeviceCollection::add(Device *a_device) int DeviceCollection::add(Device *a_device)
{ {
m_devices.push_back(std::unique_ptr<Device>(a_device)); m_devices.push_back(std::unique_ptr<Device>(a_device));
if (a_device->get_id() > m_max_id)
{
m_max_id = a_device->get_id();
}
return 0; return 0;
} }

View File

@@ -53,6 +53,7 @@ class DeviceCollection
private: private:
std::vector <std::unique_ptr<Device>> m_devices; std::vector <std::unique_ptr<Device>> m_devices;
uint16_t m_max_id;
}; };
#endif /* _DEVICE_COLLECTION_H */ #endif /* _DEVICE_COLLECTION_H */

View File

@@ -76,7 +76,7 @@ int DevicesManager::load(void)
if (json_object_object_get_ex(the_root_node, kOutletEntry, &the_value_node)) if (json_object_object_get_ex(the_root_node, kOutletEntry, &the_value_node))
{ {
load_lights(the_value_node); load_outlets(the_value_node);
} }
if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node)) if (json_object_object_get_ex(the_root_node, kShutterEntry, &the_value_node))
@@ -136,7 +136,7 @@ std::string DevicesManager::get(const std::string &a_capability)
if (a_capability == kOutletEntry) if (a_capability == kOutletEntry)
{ {
json_object_object_add(the_output_node, kOutletEntry, m_lights.to_json()); json_object_object_add(the_output_node, kOutletEntry, m_outlets.to_json());
} }
else if (a_capability == kShutterEntry) else if (a_capability == kShutterEntry)
{ {
@@ -166,10 +166,10 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
if (a_capability == kOutletEntry) if (a_capability == kOutletEntry)
{ {
the_pos = m_lights.find(an_id); the_pos = m_outlets.find(an_id);
if (the_pos != -1) if (the_pos != -1)
{ {
the_output = json_object_to_json_string(m_lights[the_pos]->to_json()); the_output = json_object_to_json_string(m_outlets[the_pos]->to_json());
} }
} }
@@ -241,32 +241,32 @@ int DevicesManager::set_state(const std::string &a_capability, int an_id, bool a
*/ */
int DevicesManager::create(const std::string &a_capability, struct json_object *a_node) int DevicesManager::create(const std::string &a_capability, struct json_object *a_node)
{ {
return 0;
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_lights * @fn load_outlets
* *
* @brief Load Lights Object From a Json Node. * @brief Load outlets Object From a Json Node.
*/ */
int DevicesManager::load_lights(struct json_object *a_node) int DevicesManager::load_outlets(struct json_object *a_node)
{ {
fprintf(stderr, "DevicesManager::load_lights\n"); fprintf(stderr, "DevicesManager::load_outlets\n");
// Get Lights // Get Outlets
if (json_object_get_type(a_node) == json_type_array) if (json_object_get_type(a_node) == json_type_array)
{ {
int the_len; int the_len;
struct json_object *the_light_node; struct json_object *the_outlet_node;
the_len = json_object_array_length(a_node); the_len = json_object_array_length(a_node);
for (int i = 0; i < the_len; i++) for (int i = 0; i < the_len; i++)
{ {
OutletDio* the_outlet = new OutletDio; OutletDio* the_outlet = new OutletDio;
the_light_node = json_object_array_get_idx(a_node, i); the_outlet_node = json_object_array_get_idx(a_node, i);
the_outlet->from_json(the_light_node); the_outlet->from_json(the_outlet_node);
m_lights.add(the_outlet); m_outlets.add(the_outlet);
} }
} }
@@ -274,9 +274,9 @@ int DevicesManager::load_lights(struct json_object *a_node)
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_lights * @fn load_shutters
* *
* @brief Load Lights Object From a Json Node. * @brief Load Shutters Object From a Json Node.
*/ */
int DevicesManager::load_shutters(struct json_object *a_node) int DevicesManager::load_shutters(struct json_object *a_node)
{ {
@@ -304,9 +304,9 @@ int DevicesManager::load_shutters(struct json_object *a_node)
} }
/*! ---------------------------------------------------------------------------- /*! ----------------------------------------------------------------------------
* @fn load_lights * @fn load_sprinklers
* *
* @brief Load Lights Object From a Json Node. * @brief Load Sprinklers Object From a Json Node.
*/ */
int DevicesManager::load_sprinklers(struct json_object *a_node) int DevicesManager::load_sprinklers(struct json_object *a_node)
{ {

View File

@@ -60,14 +60,14 @@ class DevicesManager
int create(const std::string &a_capability, struct json_object *a_node); int create(const std::string &a_capability, struct json_object *a_node);
private: private:
int load_lights(struct json_object *a_node); int load_outlets(struct json_object *a_node);
int load_shutters(struct json_object *a_node); int load_shutters(struct json_object *a_node);
int load_sprinklers(struct json_object *a_node); int load_sprinklers(struct json_object *a_node);
private: private:
std::string m_file_path; std::string m_file_path;
DeviceCollection m_lights; DeviceCollection m_outlets;
DeviceCollection m_shutters; DeviceCollection m_shutters;
DeviceCollection m_sprinklers; DeviceCollection m_sprinklers;
}; };

View File

@@ -81,8 +81,6 @@ OutletsController::~OutletsController(void)
*/ */
int OutletsController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg) int OutletsController::create(struct ubus_context *, struct ubus_request_data *, struct blob_attr *a_msg)
{ {
int the_result = 0;
struct blob_buf the_buf = {0};
char *the_string; char *the_string;
struct json_object *the_root_node; struct json_object *the_root_node;
printf("%s\n", __PRETTY_FUNCTION__); printf("%s\n", __PRETTY_FUNCTION__);