Merge branch 'feature/subtype' into 'master'

RainMaker core: Add a new field "subtype" for devices and add an API to get param value

See merge request app-frameworks/esp-rainmaker!238
This commit is contained in:
Piyush Shah
2021-06-02 07:26:09 +00:00
5 changed files with 60 additions and 0 deletions

View File

@@ -533,6 +533,19 @@ esp_err_t esp_rmaker_node_remove_device(const esp_rmaker_node_t *node, const esp
*/
esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, const char *attr_name, const char *val);
/** Add a Device subtype
*
* This can be something like esp.subtype.rgb-light for a device of type esp.device.lightbulb.
* This would primarily be used by the phone apps to render different icons for the same device type.
*
* @param[in] device Device handle.
* @param[in] subtype String describing the sub type.
*
* @return ESP_OK if the subtype was added successfully.
* @return error in case of failure.
*/
esp_err_t esp_rmaker_device_add_subtype(const esp_rmaker_device_t *device, const char *subtype);
/** Get device name from handle
*
* @param[in] device Device handle.
@@ -729,6 +742,19 @@ char *esp_rmaker_param_get_name(const esp_rmaker_param_t *param);
*/
char *esp_rmaker_param_get_type(const esp_rmaker_param_t *param);
/** Get parameter value
*
* This gives the parameter value that is stored in the RainMaker core.
*
* @note This does not call any explicit functions to read value from hardware/driver.
*
* @param[in] param Parameter handle
*
* @return Pointer to parameter value on success.
* @return NULL in case of failure.
*/
esp_rmaker_param_val_t *esp_rmaker_param_get_val(esp_rmaker_param_t *param);
/** Report the node details to the cloud
*
* This API reports node details i.e. the node configuration and values of all the parameters to the ESP RainMaker cloud.

View File

@@ -42,6 +42,9 @@ esp_err_t esp_rmaker_device_delete(const esp_rmaker_device_t *device)
esp_rmaker_param_delete((esp_rmaker_param_t *)param);
param = next_param;
}
if (_device->subtype) {
free(_device->subtype);
}
if (_device->name) {
free(_device->name);
}
@@ -204,6 +207,24 @@ esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, con
return ESP_OK;
}
/* Add a device subtype */
esp_err_t esp_rmaker_device_add_subtype(const esp_rmaker_device_t *device, const char *subtype)
{
if (!device || !subtype) {
ESP_LOGE(TAG, "Device handle or subtype cannot be NULL.");
return ESP_ERR_INVALID_ARG;
}
_esp_rmaker_device_t *_device = (_esp_rmaker_device_t *)device;
if (_device->subtype) {
free(_device->subtype);
}
if ((_device->subtype = strdup(subtype)) != NULL ){
return ESP_OK;
} else {
return ESP_ERR_NO_MEM;
}
}
esp_err_t esp_rmaker_device_assign_primary_param(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param)
{
if (!device || !param) {

View File

@@ -63,6 +63,7 @@ typedef struct esp_rmaker_attr esp_rmaker_attr_t;
struct esp_rmaker_device {
char *name;
char *type;
char *subtype;
esp_rmaker_device_write_cb_t write_cb;
esp_rmaker_device_read_cb_t read_cb;
void *priv_data;

View File

@@ -184,6 +184,9 @@ static esp_err_t esp_rmaker_report_devices_or_services(json_gen_str_t *jptr, cha
if (device->type) {
json_gen_obj_set_string(jptr, "type", device->type);
}
if (device->subtype) {
json_gen_obj_set_string(jptr, "subtype", device->subtype);
}
if (device->attributes) {
json_gen_push_array(jptr, "attributes");
esp_rmaker_attr_t *attr = device->attributes;

View File

@@ -438,6 +438,15 @@ esp_err_t esp_rmaker_param_store_value(_esp_rmaker_param_t *param)
return err;
}
esp_rmaker_param_val_t *esp_rmaker_param_get_val(esp_rmaker_param_t *param)
{
if (!param) {
ESP_LOGE(TAG, "Param handle cannot be NULL.");
return NULL;
}
return &((_esp_rmaker_param_t *)param)->val;
}
esp_err_t esp_rmaker_param_delete(const esp_rmaker_param_t *param)
{
_esp_rmaker_param_t *_param = (_esp_rmaker_param_t *)param;