finish rename ligths as outlets
This commit is contained in:
@@ -13,28 +13,28 @@
|
||||
{
|
||||
"capabilities": [
|
||||
{
|
||||
"name": "lights",
|
||||
"speach_name": "lumière"
|
||||
"name": "outlets",
|
||||
"speech_name": "lumière"
|
||||
},
|
||||
{
|
||||
"name": "shutters",
|
||||
"speach_name": "volet"
|
||||
"speech_name": "volet"
|
||||
},
|
||||
{
|
||||
"name": "sprinklers",
|
||||
"speach_name": "station"
|
||||
"speech_name": "station"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## domo.lights
|
||||
## domo.outlets
|
||||
|
||||
### create
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights create
|
||||
./usr/bin/ubus call domo.outlets create "{\"name\":\"test\", \"sender\": 12797322, \"switch\": 4}"
|
||||
```
|
||||
|
||||
TODO
|
||||
@@ -42,38 +42,38 @@ TODO
|
||||
### list
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights list
|
||||
./usr/bin/ubus call domo.outlets list
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"lights": [
|
||||
"outlets": [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Bureau JB",
|
||||
"speach_name": "bureau",
|
||||
"speech_name": "bureau",
|
||||
"zone": "",
|
||||
"state": true,
|
||||
"sender": 12797322,
|
||||
"interruptor": 0
|
||||
"switch": 0
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Salon",
|
||||
"speach_name": "salon",
|
||||
"speech_name": "salon",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 1
|
||||
"switch": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "Sapin",
|
||||
"speach_name": "sapin",
|
||||
"speech_name": "sapin",
|
||||
"zone": "",
|
||||
"state": false,
|
||||
"sender": 12797322,
|
||||
"interruptor": 2
|
||||
"switch": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -82,25 +82,25 @@ TODO
|
||||
### read
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights read "{\"id\":2}"
|
||||
./usr/bin/ubus call domo.outlets read "{\"id\":2}"
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Salon",
|
||||
"speach_name": "salon",
|
||||
"speech_name": "salon",
|
||||
"state": false,
|
||||
"zone": "",
|
||||
"sender": 12797322,
|
||||
"interruptor": 1
|
||||
"switch": 1
|
||||
}
|
||||
```
|
||||
|
||||
### update
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights update
|
||||
./usr/bin/ubus call domo.outlets update
|
||||
```
|
||||
|
||||
TODO
|
||||
@@ -108,7 +108,7 @@ TODO
|
||||
### delete
|
||||
|
||||
```
|
||||
./usr/bin/ubus call domo.lights delete
|
||||
./usr/bin/ubus call domo.outlets delete
|
||||
```
|
||||
|
||||
TODO
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ class DeviceCollection
|
||||
|
||||
private:
|
||||
std::vector <std::unique_ptr<Device>> m_devices;
|
||||
uint16_t m_max_id;
|
||||
};
|
||||
|
||||
#endif /* _DEVICE_COLLECTION_H */
|
||||
|
||||
@@ -76,7 +76,7 @@ int DevicesManager::load(void)
|
||||
|
||||
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))
|
||||
@@ -136,7 +136,7 @@ std::string DevicesManager::get(const std::string &a_capability)
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -166,10 +166,10 @@ std::string DevicesManager::get(const std::string &a_capability, uint32_t an_id)
|
||||
|
||||
if (a_capability == kOutletEntry)
|
||||
{
|
||||
the_pos = m_lights.find(an_id);
|
||||
the_pos = m_outlets.find(an_id);
|
||||
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)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
int the_len;
|
||||
struct json_object *the_light_node;
|
||||
struct json_object *the_outlet_node;
|
||||
|
||||
the_len = json_object_array_length(a_node);
|
||||
for (int i = 0; i < the_len; i++)
|
||||
{
|
||||
OutletDio* the_outlet = new OutletDio;
|
||||
the_light_node = json_object_array_get_idx(a_node, i);
|
||||
the_outlet->from_json(the_light_node);
|
||||
the_outlet_node = json_object_array_get_idx(a_node, i);
|
||||
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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -60,14 +60,14 @@ class DevicesManager
|
||||
int create(const std::string &a_capability, struct json_object *a_node);
|
||||
|
||||
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_sprinklers(struct json_object *a_node);
|
||||
|
||||
private:
|
||||
std::string m_file_path;
|
||||
|
||||
DeviceCollection m_lights;
|
||||
DeviceCollection m_outlets;
|
||||
DeviceCollection m_shutters;
|
||||
DeviceCollection m_sprinklers;
|
||||
};
|
||||
|
||||
@@ -81,8 +81,6 @@ OutletsController::~OutletsController(void)
|
||||
*/
|
||||
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;
|
||||
struct json_object *the_root_node;
|
||||
printf("%s\n", __PRETTY_FUNCTION__);
|
||||
|
||||
Reference in New Issue
Block a user